basic template
This commit is contained in:
parent
a3d6407f02
commit
0736a73254
BIN
.cache/clangd/index/glad.c.C5E0D537357D99B1.idx
Normal file
BIN
.cache/clangd/index/glad.c.C5E0D537357D99B1.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/glad.h.D2576963611097C4.idx
Normal file
BIN
.cache/clangd/index/glad.h.D2576963611097C4.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/glfw3.h.8D809999404A419F.idx
Normal file
BIN
.cache/clangd/index/glfw3.h.8D809999404A419F.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/khrplatform.h.B05AC99ACA6BC483.idx
Normal file
BIN
.cache/clangd/index/khrplatform.h.B05AC99ACA6BC483.idx
Normal file
Binary file not shown.
BIN
.cache/clangd/index/main.cpp.21561E3F69D0E087.idx
Normal file
BIN
.cache/clangd/index/main.cpp.21561E3F69D0E087.idx
Normal file
Binary file not shown.
@ -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
|
||||||
|
|||||||
BIN
build/bin/test
BIN
build/bin/test
Binary file not shown.
@ -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
|
|
||||||
@ -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
|
||||||
|
glViewport(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user