Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <GL/glew.h>
- #include <GLFW/glfw3.h>
- #include <glm/glm.hpp>
- using namespace glm;
- #include "../common/shader.hpp"
- GLFWwindow* window;
- int main( void )
- {
- // Initialise GLFW
- if( !glfwInit() )
- {
- fprintf( stderr, "Failed to initialize GLFW\n" );
- getchar();
- return -1;
- }
- glfwWindowHint(GLFW_SAMPLES, 4);
- glfwWindowHint(GLFW_RESIZABLE,GL_FALSE);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
- glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
- glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); // To make MacOS happy; should not be needed
- glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
- // Open a window and create its OpenGL context
- window = glfwCreateWindow( 1024, 768, "Playground", nullptr, nullptr);
- if(window == nullptr){
- fprintf( stderr, "Failed to open GLFW window. If you have an Intel GPU, they are not 3.3 compatible. Try the 2.1 version of the tutorials.\n" );
- getchar();
- glfwTerminate();
- return -1;
- }
- glfwMakeContextCurrent(window);
- // Initialize GLEW
- // IMPORTANT: if this is not enable this might create SegmentationFault
- glewExperimental = true; // For core profile
- if (glewInit() != GLEW_OK) {
- fprintf(stderr, "Failed to initialize GLEW\n");
- getchar();
- glfwTerminate();
- return -1;
- }
- // Ensure we can capture the escape key being pressed below
- glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
- // Dark blue background
- glClearColor(0.0f, 0.0f, 0.4f, 0.0f);
- GLuint vao;
- glGenVertexArrays(1, &vao);
- glBindVertexArray(vao);
- GLuint programID = LoadShaders("shader.vert", "shader.frag");
- static const GLfloat vertices[] = {
- -1.0f, -1.0f, 0.0f,
- 1.0f, -1.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- };
- GLuint vbo;
- glGenBuffers(1, &vbo);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);
- do{
- glClear(GL_COLOR_BUFFER_BIT);
- glUseProgram(programID);
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vbo);
- glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, nullptr);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glDisableVertexAttribArray(0);
- // Swap buffers
- glfwSwapBuffers(window);
- glfwPollEvents();
- } // Check if the ESC key was pressed or the window was closed
- while( glfwGetKey(window, GLFW_KEY_ESCAPE ) != GLFW_PRESS &&
- glfwWindowShouldClose(window) == 0 );
- glDeleteBuffers(1, &vbo);
- glDeleteVertexArrays(1, &vao);
- glDeleteProgram(programID);
- // Close OpenGL window and terminate GLFW
- glfwTerminate();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement