Below is an example of a base program in OpenGL, resulting in a window with a red triangle in the center.
[c]
#include <stdlib.h>
#include <GL/glut.h>
//Call Back Function
void draw (void)
{
//Set the background color of the Window
glClear Color(1,1,1,0);
//Clear Screen
glClear (GL_COLOR_BUFFER_BIT);
//Define the color of the drawing
glColor3i(1,0,0);
glBegin(GL_TRIANGLES);
//Defines the position of the vertex point
glVertex2i(-5,-5);
glVertex2i(0,5);
glVertex2i(5,-5);
glEndl();
//Draw the previously defined items
glFlush();
}
void keyboard(unsingned char key,int x,int y)
{
if(key==27)
{ exit(0); }
}
void initialize()
{
//define the 2d display window
glMatrixMode(GL_PROJECTION)
glOrtho2d(-15,15,-15,15);
glMatrixMode(GL_MODELVIEW);
}
int main(void)
{
//define the glut operation mode
glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
// specify window size
glutInitWindowSize(400,400);
//creates the window and inserts the title
glutCreateWindow(“First Program”);
//records drawing CallBack
glutDisplayFunc(draw);
//register the keyboard function
glutKeyboardFunc(keyboard);
initialize();
//Activate callback functions
glutMainLoop();
return 0;
}
[/c]___________________________________________________________________________