Switch to full style
C++ openGL code examples
Post a reply

OpenGl simple example

Mon Mar 14, 2011 4:30 pm

OpenGl simple example
Code:
#include <cstdlib>
#include <GL/glut.h>
#include <GL/glut.h>

// Display callback ------------------------------------------------------------

void display()
{
    // clear the draw buffer .
    glClear(GL_COLOR_BUFFER_BIT);   // Erase everything

    // set the color to use in draw
    glColor3f(0.5, 0.5, 0.0);       
    
// create a polygon ( define the vertexs) 
    glBegin(GL_POLYGON); {           
        glVertex2f
(-0.5, -0.5);
        glVertex2f(-0.5,  0.5);
        glVertex2f( 0.5,  0.5);
        glVertex2f( 0.5, -0.5);
    } glEnd();

    // flush the drawing to screen . 
    glFlush(); 
}

// Keyboard callback function ( called on keyboard event handling )
void keyboard(unsigned char key, int x, int y)
{
    if (key == 'q' || key == 'Q')
        exit(EXIT_SUCCESS);
}

// Main execution  function 
int main(int argc, char *argv[])
{
    glutInit(&argc, argv);      // Initialize GLUT
    glutCreateWindow("OpenGL example");  // Create a window
    glutDisplayFunc(display);   // Register display callback
    glutKeyboardFunc(keyboard); // Register keyboard callback
    glutMainLoop();             // Enter main event loop

    return (EXIT_SUCCESS);
}

 


 



Attachments
opengl2.GIF
opengl2.GIF (5.98 KiB) Viewed 15425 times

Post a reply
  Related Posts  to : OpenGl simple example
 openGL in java     -  
 Drawing cone using openGL     -  
 Build Calculator in OpenGL     -  
 Drawing Octahedron using openGL     -  
 Draw 3d cube using openGL     -  
 Drawing Torus using OpenGL     -  
 Drawing teapot using OpenGL.     -  
 openGL shadow mapping example     -  
 Draw a solid sphere using openGL     -  
 3d OpenGL game with source code     -  

Topic Tags

C++ Graphics