4. include <GL/glut.h>
void display(){
glClear(GL_COLOR_BUFFER_BIT);
Adding required libraries to the project
Define a method to display
glClear — clear buffers to preset values
3 values :
• GL_COLOR_BUFFER_BIT- Indicates the buffers currently
enabled for color writing.
• GL_DEPTH_BUFFER_BIT- Indicates the depth buffer.
• GL_STENCIL_BUFFER_BIT - Indicates the stencil buffer.
glColor — set the current color
glColor3f(1,0,0);
7. glEnd(); glBegin and glEnd delimit the vertices that define a primitive
or a group of like primitives.
glFlush — force execution of GL commands in finite timeglFlush();
glutSwapBuffers(); glutSwapBuffers- swaps the buffers of the current window
if double buffered.
} End of Display function
Code review cont…
8. main function
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_RGBA);
glutInitWindowSize(512,512);
glutCreateWindow("");
glutDisplayFunc(display);
gluOrtho2D(0,640,0,640);
glClearColor(0.5,0.7,0.5,0);
glutMainLoop();
return 0;
}
main()
The entry point into any console application. As you delve into graphics
development, you'll notice that it isn't always this. However, to keep
things simple, let's just stick with main on its own.
int argc;
Stands for argument count. In other words, how many things are being
passed into the program.
char **argv; or char *argv[];
Both do the exact same thing. Short for argument vector, or in other
words, this is a multidimensional array that will store all arguments
being passed to the function.
9. is used to initialize the GLUT library.glutInit(&argc, argv);
glutInitDisplayMode - sets the initial display mode.glutInitDisplayMode(GLUT_RGBA);
Code review cont…
10. Code review cont…
glutInitWindowSize(512,512); glutInitWindowPosition and glutInitWindowSize set the initial
window position and size respectively.
glutCreateWindow creates a top-level window.
glutCreateWindow("");
glutDisplayFunc sets the display callback for the current window.
glutDisplayFunc(display);
11. Code review cont…
gluOrtho2D(0,640,0,640); gluOrtho2D — define a 2D orthographic projection matrix
glClearColor(0.5,0.7,0.5,0); glClearColor — specify clear values for the color buffers
12. Code review cont…
glutMainLoop(); glutMainLoop enters the GLUT event processing loop.
return 0;
}
Return 0 and end of the main function