Total members 11889 |It is currently Fri Mar 29, 2024 8:37 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





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 15160 times ]

_________________
M. S. Rakha, Ph.D.
Queen's University
Canada
Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

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



Topic Tags

C++ Graphics






Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com