SHARE
TWEET
Untitled
a guest
Mar 13th, 2018
8
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- #include <glad/glad.h>
- #include "renderer.h"
- #include <GLFW/glfw3.h>
- #include <iostream>
- #include <memory>
- void framebuffer_resized(GLFWwindow *window, int width, int height);
- const char *vShader = "#version 300 es\n"
- "\n"
- "layout (location = 0) in vec2 inPosition;\n"
- "layout (location = 1) in vec2 inTextureCoordinates;\n"
- "\n"
- "uniform mat4 uModel;\n"
- "\n"
- "out vec2 textureCoordinates;\n"
- "\n"
- "void main()\n"
- "{\n"
- " gl_Position = uModel * vec4(inPosition, 0.0f, 1.0f);\n"
- " textureCoordinates = inTextureCoordinates;\n"
- "}\n";
- GLFWwindow *window = nullptr;
- std::unique_ptr<Renderer> renderer = nullptr;
- int main() {
- int screen_width = 800;
- int screen_height = 600;
- glfwInit();
- glfwWindowHint(GLFW_CONTEXT_CREATION_API, GLFW_EGL_CONTEXT_API);
- glfwWindowHint(GLFW_CLIENT_API, GLFW_OPENGL_ES_API);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 0);
- glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- window = glfwCreateWindow(screen_width, screen_height, "Illuminati", nullptr, nullptr);
- if (window == nullptr) {
- std::cout << "Failed to create GLFW window" << std::endl;
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- glfwSetFramebufferSizeCallback(window, framebuffer_resized);
- if (!gladLoadGLLoader((GLADloadproc)glfwGetProcAddress)) {
- std::cout << "Failed to initialize OpenGL context" << std::endl;
- return -1;
- }
- GLuint shader = glCreateShader(GL_VERTEX_SHADER);
- glShaderSource(shader, 1, &vShader, nullptr);
- glCompileShader(shader);
- renderer = std::make_unique<Renderer>(screen_width, screen_height);
- while (!glfwWindowShouldClose(window)) {
- if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS) {
- glfwSetWindowShouldClose(window, true);
- }
- renderer->DrawFrame();
- glfwSwapBuffers(window);
- glfwPollEvents();
- }
- glfwTerminate();
- return 0;
- }
- void framebuffer_resized(GLFWwindow *, int width, int height) {
- glViewport(0, 0, width, height);
- renderer->SetScreenSize(width, height);
- }
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.
