Created
September 22, 2021 10:33
-
-
Save emadflash/074161eb3d308943f52c6228217e195f to your computer and use it in GitHub Desktop.
learnopengl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <glad/glad.h> | |
#include <GLFW/glfw3.h> | |
#include <stdio.h> | |
#include <stdbool.h> | |
/* | |
* An iteration of the render loop is more commonly called a frame. | |
*/ | |
void framebuffer_size_callback(GLFWwindow* window, int width, int height) { | |
glViewport(0, 0, width, height); | |
} | |
void process_input(GLFWwindow* window) { | |
/* | |
* If key is not pressed than GLFW_RELEASE instead of GLFW_PRESS will be set | |
* glfwSetWindowShouldClose interupts the while loop | |
*/ | |
if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) glfwSetWindowShouldClose(window, true); | |
} | |
int main() { | |
glfwInit(); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); | |
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); | |
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | |
GLFWwindow* window = glfwCreateWindow(800, 600, "LearnOpenGL", NULL, NULL); | |
if (window == NULL) { | |
printf("error: failed to create window\n"); | |
glfwTerminate(); | |
} | |
glfwMakeContextCurrent(window); | |
// GLAD things | |
if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) { | |
printf("Failed to initialize GLAD"); | |
return -1; | |
} | |
// View port | |
glViewport(0, 0, 800, 600); | |
// changing the view port based on window resizing | |
glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); | |
// render loop | |
while(!glfwWindowShouldClose(window)) { | |
// input | |
process_input(window); | |
// rendering commands | |
glClearColor(0.2f, 0.3f, 0.3f, 1.0f); // (state-setting) specify the color to clear the screen | |
glClear(GL_COLOR_BUFFER_BIT); // (state-using) clear and the entire color buffer will be filled with the color as configured by glClearColor. | |
// end | |
glfwSwapBuffers(window); // ??? | |
glfwPollEvents(); // checks if any events are triggered (like keyboard input or mouse movement events) | |
} | |
glfwTerminate(); // clean/delete all of GLFW's resources that were allocated | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment