#include #define GLFW_INCLUDE_NONE #include #include #include #include // struct and function declaration // ---------------------------------------------------------------------------- void framebuffer_size_callback(GLFWwindow* window, int width, int height); void processInput(GLFWwindow* window); // ---------------------------------------------------------------------------- // END int main(void) { // GLFW settings init and which version of opengl we should use // and which subset of opengl profiles glfwInit(); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 4); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); // Window settings // create window int w_height = 1280; int w_width = 820; GLFWwindow* window = glfwCreateWindow(w_height, w_width, "Test", NULL, NULL); if (window == NULL) { printf("Failed to create GLFW window\n"); glfwTerminate(); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); return -1; } // init window glfwMakeContextCurrent(window); // init GLAD if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { printf("Failed to initialize GLAD\n"); return -1; } // opengl viewport framebuffer_size_callback(window, w_width, w_height); // ------------------------------------------------------------------------- // render loop // ------------------------------------------------------------------------- while (!glfwWindowShouldClose(window)) { // input processInput(window); // rendering commands here // ----------------------- glClearColor(0.2f, 0.3f, 0.3f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); // check and call events and swap the buffers glfwSwapBuffers(window); glfwPollEvents(); } glfwTerminate(); return 0; } // END render loop // ----------------------------------------------------------------------------- // Functions // ----------------------------------------------------------------------------- // glfw: whenever the window size changed (by OS or user resize) this callback function executes // --------------------------------------------------------------------------------------------- void framebuffer_size_callback(GLFWwindow* window, int width, int height) { glViewport(0, 0, width, height); } // process all input: query GLFW whether relevant keys are pressed/released this frame and react accordingly // --------------------------------------------------------------------------------------------------------- void processInput(GLFWwindow* window) { if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, 1); if (glfwGetKey(window, GLFW_KEY_Q) == GLFW_PRESS) glfwSetWindowShouldClose(window, 1); }