#include //we're going to build the main function of our application. //The main function will perform the required initializations and start the event processing loop. //All the functions in GLUT have the prefix glut, //and those which perform some kind of initialization have the prefix glutInit. void renderScene(void); void main(int argc, char **argv) { //The first thing you must do is call the function glutInit. It initializes GLUT library. //use the same parameters as those to main() glutInit(&argc, argv); //2. Define the display mode using the function glutInitDisplayMode(unsigned int mode) // mode -> specifies the display mode (a Bollean combination of possible predefined values in GLUT: color mode, number and type of buffers) // (1) color model constants include: GLUT_RGBA (default) or GLUT_RGB or GLUT_INDEX // (2) number of buffers: GLUT_SINGLE or GLUT_DOUBLE // (3) other particular set of buffers: GLUT_DEPTH, GLUT_ACCUM, GLUT_STENCIL... // check detailed explanations at: // http://pyopengl.sourceforge.net/documentation/manual/glutInitDisplayMode.3GLUT.html // just OR all parameters you want here glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA); //3. Define our window //3.1. Establish the window's position, i.e. its top left corner. //In order to do this we use the function glutInitWindowPosition. //void glutInitWindowPosition(int x, int y); // x-> number of pixels from the left of the screen // y-> number of pixels from the top of the screen glutInitWindowPosition(100,100); //3.2. Choose the window size, using the function glutInitWindowSize(int width, int height). // width -> the width of the window, height -> the height of the window glutInitWindowSize(640,480); //3.3 After these settings, we can create the window with a title glutCreateWindow("Hello World"); //4. Assign a function responsible for the rendering (register a callback) //void glutDisplayFunc(void (*func)(void)); // func -> the name of the function to be called when the window needs to be redrawn (should not be NULL) glutDisplayFunc(renderScene); //Finally, get in the application event processing loop // GLUT provides a function that gets the application in a never ending loop, // always waiting for the next event to process glutMainLoop(); } void renderScene(void) { glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_TRIANGLES); glVertex3f(-0.5,-0.5,0.0); glVertex3f(0.5,0.0,0.0); glVertex3f(0.0,0.5,0.0); glEnd(); glFlush(); }