Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Include standard headers
- #include <stdio.h>
- #include <stdlib.h>
- // Include GLEW & GLFW
- #include <GL/glew.h>
- #include <GL/glfw.h>
- // DEViL
- #include <IL/il.h>
- #include <IL/ilut.h>
- #include "ShaderManager.h"
- int main( void )
- {
- // Initialise GLFW
- if( !glfwInit() )
- {
- fprintf( stderr, "Failed to initialize GLFW\n" );
- return -1;
- }
- glfwOpenWindowHint(GLFW_FSAA_SAMPLES, 4); // 4x antialiasing
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MAJOR, 3); // We want OpenGL 3.1
- glfwOpenWindowHint(GLFW_OPENGL_VERSION_MINOR, 3);
- glfwOpenWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); //We don't want the old OpenGL
- // Open a window and create its OpenGL context
- if( !glfwOpenWindow( 1024, 768, 0,0,0,0, 32,0, GLFW_WINDOW ) )
- {
- fprintf( stderr, "Failed to open GLFW window\n" );
- glfwTerminate();
- return -1;
- }
- // Initialize GLEW
- if (glewInit() != GLEW_OK) {
- fprintf(stderr, "Failed to initialize GLEW\n");
- return -1;
- }
- glfwSetWindowTitle( "GL Test" );
- // Ensure we can capture the escape key being pressed below
- glfwEnable( GLFW_STICKY_KEYS );
- // Clear Color
- glClearColor(1.0f, 1.0f, 0.0f, 1.0f);
- // An array of 3 vectors which represents 3 vertices
- static const GLfloat g_vertex_buffer_data[] = {
- -1.0f, -1.0f, 0.0f,
- 1.0f, -1.0f, 0.0f,
- -1.0f, 1.0f, 0.0f,
- };
- // This will identify our vertex buffer
- GLuint vertexbuffer;
- // Generate 1 buffer, put the resulting identifier in vertexbuffer
- glGenBuffers(1, &vertexbuffer);
- // The following commands will talk about our 'vertexbuffer' buffer
- glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
- // Give our vertices to OpenGL.
- glBufferData(GL_ARRAY_BUFFER, sizeof(g_vertex_buffer_data), g_vertex_buffer_data, GL_STATIC_DRAW);
- // Create and compile our GLSL program from the shaders
- ShaderManager* shaderManager = ShaderManager::getInstance();
- GLuint programID = shaderManager->setupShaders();
- do{
- glViewport(0,0,1024,768);
- // Clear the screen
- glClear( GL_COLOR_BUFFER_BIT );
- // Use our shader
- glUseProgram(programID);
- // 1rst attribute buffer : vertices
- glEnableVertexAttribArray(0);
- glBindBuffer(GL_ARRAY_BUFFER, vertexbuffer);
- glVertexAttribPointer(
- 0, // attribute 0. No particular reason for 0, but must match the layout in the shader.
- 3, // size
- GL_FLOAT, // type
- GL_FALSE, // normalized?
- 0, // stride
- (void*)0 // array buffer offset
- );
- // Draw the triangle !
- glDrawArrays(GL_TRIANGLES, 0, 3); // Starting from vertex 0; 3 vertices total -> 1 triangle
- glDisableVertexAttribArray(0);
- // Swap buffers
- glfwSwapBuffers();
- } // Check if the ESC key was pressed or the window was closed
- while( glfwGetKey( GLFW_KEY_ESC ) != GLFW_PRESS &&
- glfwGetWindowParam( GLFW_OPENED ) );
- }
Add Comment
Please, Sign In to add comment