basic template

This commit is contained in:
Afonso Clerigo Mendes de Sousa 2026-01-27 17:02:07 +00:00
parent a3d6407f02
commit 0736a73254
10 changed files with 75 additions and 24 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -61,6 +61,7 @@ file(GLOB_RECURSE PROJECT_HEADERS
${CMAKE_SOURCE_DIR}/source/*.h ${CMAKE_SOURCE_DIR}/source/*.h
) )
# Combine all sources # Combine all sources
set(ALL_SOURCES ${PROJECT_SOURCES} ${LIBRARY_SOURCES}) set(ALL_SOURCES ${PROJECT_SOURCES} ${LIBRARY_SOURCES})
@ -86,6 +87,23 @@ target_include_directories(${EXECUTABLE_NAME} PRIVATE
${CMAKE_SOURCE_DIR}/libraries ${CMAKE_SOURCE_DIR}/libraries
) )
# 1. Find the GLFW library in your lib folder
find_library(GLFW_LIB NAMES glfw glfw3 PATHS "${CMAKE_SOURCE_DIR}/libraries" NO_DEFAULT_PATH)
# 2. Link GLFW and the required Apple Frameworks
if(APPLE)
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
${GLFW_LIB}
"-framework Cocoa"
"-framework IOKit"
"-framework CoreVideo"
)
else()
# For Windows/Linux
target_link_libraries(${EXECUTABLE_NAME} PRIVATE ${GLFW_LIB})
endif()
# Compiler-specific flags # Compiler-specific flags
if(MSVC) if(MSVC)
target_compile_options(${EXECUTABLE_NAME} PRIVATE target_compile_options(${EXECUTABLE_NAME} PRIVATE

Binary file not shown.

View File

@ -1,10 +0,0 @@
[ 25%] Creating symlink to compile_commands.json in project root
[ 50%] Building C object CMakeFiles/test.dir/source/glad.c.o
[ 75%] Building CXX object CMakeFiles/test.dir/source/main.cpp.o
[ 75%] Built target symlink_compile_commands
/Users/AfonsoCMSosua/Developer/C++/algorithm_visualizer/source/glad.c:192:79: warning: implicit conversion changes signedness: 'int' to 'GLuint' (aka 'unsigned int') [-Wsign-conversion]
const char *gl_str_tmp = (const char*)glGetStringi(GL_EXTENSIONS, index);
~~~~~~~~~~~~ ^~~~~
1 warning generated.
[100%] Linking CXX executable bin/test
[100%] Built target test

View File

@ -1,9 +1,52 @@
#include <glad/glad.h> // Include GLAD before GLFW
#include <GLFW/glfw3.h>
#include <iostream> #include <iostream>
#include <glad/glad.h> // Callback to resize the viewport when the window is resized
#include <GLFW/glfw3.h> void framebuffer_size_callback(GLFWwindow *window, int width, int height) {
(void)window; // Unused parameter
int main() glViewport(0, 0, width, height);
{ }
return 0;
int main() {
// 1. Initialize GLFW
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
// 2. Create the Window
GLFWwindow *window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL);
if (window == NULL) {
std::cout << "Failed to create GLFW window" << std::endl;
glfwTerminate();
return -1;
}
glfwMakeContextCurrent(window);
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
// 3. Initialize GLAD (Load function pointers)
if (!gladLoadGLLoader(reinterpret_cast<GLADloadproc>(glfwGetProcAddress))){
std::cout << "Failed to initialize GLAD" << std::endl;
return -1;
}
// 4. The Render Loop
while (!glfwWindowShouldClose(window)) {
// Input
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
glfwSetWindowShouldClose(window, true);
// Rendering commands here
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); // Set clear color (Teal)
glClear(GL_COLOR_BUFFER_BIT); // Clear the screen
// Swap buffers and poll IO events
glfwSwapBuffers(window);
glfwPollEvents();
}
// 5. Clean up
glfwTerminate();
return 0;
} }

BIN
test

Binary file not shown.