commit d7044f7352953a417d70f5a2a35223c63ed39d6f Author: Nathan Chapman Date: Mon Jun 30 11:34:10 2025 -0600 Initialize an OpenGL application: display a single color diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f38a87b --- /dev/null +++ b/.gitignore @@ -0,0 +1,22 @@ +# CMake build directories +build/ +cmake-build-*/ +out/ + +# CMake generated files +CMakeFiles/ +CMakeCache.txt +cmake_install.cmake +Makefile +*.vcxproj* +*.sln + +# IDE specific files +.idea/ +.vscode/ +*.user + +# Other temporary files +*.log +*.tmp +*.swp \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..b16cebd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.12) +project(OpenGLTest CXX) + +set(CMAKE_CXX_STANDARD 17) + +find_package(OpenGL REQUIRED) +find_package(GLEW REQUIRED) +find_package(glfw3 REQUIRED) + +add_executable(opengl_test src/main.cpp) + +target_link_libraries(opengl_test + OpenGL::GL + GLEW::GLEW + glfw +) \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..8c8440f --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,85 @@ +#include +#include +#include + +// Window dimensions +const GLint WIDTH = 800, HEIGHT = 600; + + +int main() { + // Initialize GLFW + glfwInitHint(GLFW_PLATFORM, GLFW_PLATFORM_WAYLAND); + + if (!glfwInit()) { + printf("GLFW initialization failed!"); + glfwTerminate(); + return 1; + } + + + // Setup GLFW window properties + // OpenGL version + // @Reminder Look into making it work on Wayland + glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); + glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6); + // Core profile means it will not be backwards compatible + glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); + glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); + + GLFWwindow *window = glfwCreateWindow(WIDTH, HEIGHT, "Test Window", NULL, NULL); + + if (!window) { + const char *desc; + int code = glfwGetError(&desc); + printf("GLFW window creation failed!"); + printf("GLFW error code: %d, description: %s\n", code, desc ? desc : "No description given"); + glfwTerminate(); + return 1; + } + + // Get Buffer size information + int buffer_width, buffer_height; + glfwGetFramebufferSize(window, &buffer_width, &buffer_height); + + // Set context for GLEW to use + glfwMakeContextCurrent(window); + + + glGetError(); + + // Allow modern extension features + glewExperimental = GL_TRUE; + + GLenum err = glewInit(); + if (err != GLEW_OK && err != GLEW_ERROR_NO_GLX_DISPLAY) { + printf("OpenGL version: %s\n", glGetString(GL_VERSION)); + fprintf(stderr, "Error: %s\n", glewGetErrorString(err)); + printf("glewInit() returned: %d\n", err); + glfwDestroyWindow(window); + glfwTerminate(); + return 1; + } + + // Setup viewport size + glViewport(0, 0, buffer_width, buffer_height); + + // Loop until window is closed + while (!glfwWindowShouldClose(window)) { + // Get and handle user input events + glfwPollEvents(); + + // Clear window + glClearColor(1.0f, 0.9f, 0.4f, 1.0f); + glClear(GL_COLOR_BUFFER_BIT); + + + // We usually have two buffers, the first is hidden and that's the one + // we draw to. The second is the one we display, so when we're done drawing + // we call this glfwSwapBuffers() to swap the buffers to show the one we've + // been drawing to so that it now shows. We then can start drawing on the + // other buffer. + glfwSwapBuffers(window); + } + + return 0; +} \ No newline at end of file