Guest User

Untitled

a guest
Jul 18th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 KB | None | 0 0
  1. // Include standard headers
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. // Include GLEW & GLFW
  6. #include <GL/glew.h>
  7. #include <GL/glfw.h>
  8.  
  9. // DEViL
  10. #include <IL/il.h>
  11. #include <IL/ilut.h>
  12.  
  13. #include "ShaderManager.h"
  14.  
  15. int main( void )
  16. {
  17.     // Initialise GLFW
  18.     if( !glfwInit() )
  19.     {
  20.         fprintf( stderr, "Failed to initialize GLFW\n" );
  21.         return -1;
  22.     }
  23.  
  24.     glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
  25.     glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
  26.     glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
  27.     glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
  28.  
  29.     // Open a window and create its OpenGL context
  30.     if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
  31.     {
  32.         fprintf( stderr, "Failed to open GLFW window\n" );
  33.         glfwTerminate();
  34.         return -1;
  35.     }
  36.  
  37.     // Initialize GLEW
  38.     if (glewInit() != GLEW_OK) {
  39.         fprintf(stderr, "Failed to initialize GLEW\n");
  40.         return -1;
  41.     }
  42.  
  43.     glfwSetWindowTitle( "GL Test" );
  44.  
  45.     // Ensure we can capture the escape key being pressed below
  46.     glfwEnable( GLFW_STICKY_KEYS );
  47.  
  48.     // Clear Color
  49.     glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
  50.    
  51.     // An array of 3 vectors which represents 3 vertices
  52.     static const GLfloat g_vertex_buffer_data[] = {
  53.        -1.0f, -1.0f, 0.0f,
  54.        1.0f, -1.0f, 0.0f,
  55.        -1.0f,  1.0f, 0.0f,
  56.     };
  57.  
  58.     // This will identify our vertex buffer
  59.     GLuint vertexbuffer;
  60.  
  61.     // Generate 1 buffer, put the resulting identifier in vertexbuffer
  62.     glGenBuffers(1, &vertexbuffer);
  63.  
  64.     // The following commands will talk about our 'vertexbuffer' buffer
  65.     glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  66.  
  67.     // Give our vertices to OpenGL.
  68.     glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
  69.  
  70.     // Create and compile our GLSL program from the shaders
  71.     ShaderManager* shaderManager = ShaderManager::getInstance();
  72.     GLuint programID = shaderManager->setupShaders();
  73.  
  74.     do{
  75.         glViewport(0,0,1024,768);
  76.    
  77.         // Clear the screen
  78.         glClear( GL_COLOR_BUFFER_BIT );
  79.  
  80.         // Use our shader
  81.         glUseProgram(programID);
  82.  
  83.         // 1rst attribute buffer : vertices
  84.         glEnableVertexAttribArray(0);
  85.         glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
  86.         glVertexAttribPointer(
  87.            0,                  // attribute 0. No particular reason for 0, but must match the layout in the shader.
  88.            3,                  // size
  89.            GL_FLOAT,           // type
  90.            GL_FALSE,           // normalized?
  91.            0,                  // stride
  92.            (void*)0            // array buffer offset
  93.         );
  94.  
  95.  
  96.         // Draw the triangle !
  97.         glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
  98.  
  99.         glDisableVertexAttribArray(0);
  100.  
  101.         // Swap buffers
  102.         glfwSwapBuffers();
  103.  
  104.     } // Check if the ESC key was pressed or the window was closed
  105.     while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
  106.     glfwGetWindowParam( GLFW_OPENED ) );
  107. }
Add Comment
Please, Sign In to add comment