SHARE
TWEET

Untitled

a guest Mar 13th, 2018 8 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <glad/glad.h>
  2.  
  3. #include "renderer.h"
  4.  
  5. #include <GLFW/glfw3.h>
  6. #include <iostream>
  7. #include <memory>
  8.  
  9. void framebuffer_resized(GLFWwindow *window, int width, int height);
  10. const char *vShader = "#version 300 es\n"
  11.         "\n"
  12.         "layout (location = 0) in vec2 inPosition;\n"
  13.         "layout (location = 1) in vec2 inTextureCoordinates;\n"
  14.         "\n"
  15.         "uniform mat4 uModel;\n"
  16.         "\n"
  17.         "out vec2 textureCoordinates;\n"
  18.         "\n"
  19.         "void main()\n"
  20.         "{\n"
  21.         "    gl_Position = uModel * vec4(inPosition, 0.0f, 1.0f);\n"
  22.         "    textureCoordinates = inTextureCoordinates;\n"
  23.         "}\n";
  24.  
  25. GLFWwindow *window = nullptr;
  26. std::unique_ptr<Renderer> renderer = nullptr;
  27.  
  28. int main() {
  29.     int screen_width = 800;
  30.     int screen_height = 600;
  31.  
  32.     glfwInit();
  33.     glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
  34.     glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
  35.     glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
  36.     glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
  37.     glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
  38.     glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
  39.  
  40.     window = glfwCreateWindow(screen_width, screen_height, "Illuminati", nullptr, nullptr);
  41.     if (window == nullptr) {
  42.         std::cout << "Failed to create GLFW window" << std::endl;
  43.         glfwTerminate();
  44.         return -1;
  45.     }
  46.     glfwMakeContextCurrent(window);
  47.     glfwSetFramebufferSizeCallback(window, framebuffer_resized);
  48.  
  49.     if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
  50.         std::cout << "Failed to initialize OpenGL context" << std::endl;
  51.         return -1;
  52.     }
  53.  
  54.     GLuint shader = glCreateShader(GL_VERTEX_SHADER);
  55.     glShaderSource(shader, 1, &vShader, nullptr);
  56.     glCompileShader(shader);
  57.  
  58.     renderer = std::make_unique<Renderer>(screen_width, screen_height);
  59.  
  60.     while (!glfwWindowShouldClose(window)) {
  61.  
  62.         if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
  63.             glfwSetWindowShouldClose(window, true);
  64.         }
  65.  
  66.         renderer->DrawFrame();
  67.  
  68.         glfwSwapBuffers(window);
  69.         glfwPollEvents();
  70.     }
  71.  
  72.     glfwTerminate();
  73.     return 0;
  74. }
  75.  
  76. void framebuffer_resized(GLFWwindow *, int width, int height) {
  77.     glViewport(0, 0, width, height);
  78.     renderer->SetScreenSize(width, height);
  79. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top