Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <glad/glad.h>
- #include <GLFW/glfw3.h>
- #include "Macros.h"
- #include "Shader.h"
- #include "Model.h"
- const unsigned int screenWidth = 800;
- const unsigned int screenHeight = 600;
- const float modelData[] = {
- // positions // colors // uv coords
- -0.75f, -0.25f, 0.0f, 1.0f, 0.0f, 0.0f, // Bottom Left
- -0.75f, 0.25f, 0.0f, 0.0f, 1.0f, 0.0f, // Top Left
- -0.25f, 0.25f, 0.0f, 0.0f, 0.0f, 1.0f, // Top Right
- -0.25f, -0.25f, 0.0f, 0.5f, 0.5f, 0.5f, // Bottom Right
- };
- const unsigned int indices[] = {
- 0, 1, 2,
- 0, 2, 3
- };
- void framebuffer_size_callback(GLFWwindow* window, int width, int height);
- void processInput(GLFWwindow* window);
- int main(void)
- {
- /* Initialize the library */
- if (!glfwInit()) return -1;
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- // GLFW has nothing to do with OpenGL, glfw just handles os specific window initialization I think
- GLFWwindow* window = glfwCreateWindow(screenWidth, screenHeight, "LearnOpenGL", NULL, NULL);
- if (window == NULL)
- {
- LOG("Failed to create GLFW window");
- glfwTerminate();
- return -1;
- }
- // Then you tell GLFW you want to be executing operations on this window object incase you want to execute operations on a different one I'd assume.
- glfwMakeContextCurrent(window);
- // Then you set a function pointer for when the window object gets resized
- glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);
- // Then we load the mappings for the actual OpenGL function pointers because our computers don't know what... actually idk what exactly this does
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress))
- {
- LOG("Failed to initialize GLAD");
- return -1;
- }
- glViewport(0, 0, screenWidth, screenHeight);
- Shader mainShader("D:/Harry/My Stuff/Code/CPP/OpenGLDemo/OpenGLDemo/src/shaders/main.vsh", "D:/Harry/My Stuff/Code/CPP/OpenGLDemo/OpenGLDemo/src/shaders/main.fsh");
- Model model(modelData, indices);
- int nrAttributes;
- glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &nrAttributes);
- LOG("Maximum nr of vertex attributes supported: " << nrAttributes);
- LOG("RUNNING WHILE LOOP");
- while (!glfwWindowShouldClose(window))
- {
- processInput(window);
- glClearColor(0.2f, 0.6f, 0.3f, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT);
- mainShader.use();
- model.render();
- // Basically applies all these draws to the actual screen from the gpus pixel buffer ig
- glfwSwapBuffers(window);
- // Polls for IO events like mouse and keyboard and shit
- glfwPollEvents();
- }
- // Deallocate gpu data if you want this happens in the decnostructor of ~Model
- // Will deallocate GLFW shit
- glfwTerminate();
- return 0;
- }
- // 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, true);
- }
- // 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)
- {
- // make sure the viewport matches the new window dimensions; note that width and
- // height will be significantly larger than specified on retina displays.
- glViewport(0, 0, width, height);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement