26.3. Generic OpenGL code

Let’s look at an example of the kinds of calls that we feed into the OpenGL state-machine hopper so as to prepare to draw something. Specifically, let’s see what it would take to draw a white square.

//Initialize the Window (Described in next subsection) 
::glClearColor(0.0, 0.0, 0.0, 0.0); 
::glClear(GL_COLOR_BUFFER_BIT); 
::glColor3f(1.0, 1.0, 1.0); 
::glOrtho(0.0, 1.0, 0.0, 1.0, -1.0, 1.0); 
::glBegin(GL_POLYGON) 
    ::glVertex(0.25, 0.25, 0.0); 
    ::glVertex(0.75, 0.25, 0.0); 
    ::glVertex(0.75, 0.75, 0.0); 
    ::glVertex(0.25, 0.75, 0.0); 
::glEnd(); 
::glFinish(); 
//Update the Window (Described in next subsection) 

You can view a lot more code like this in the Pop Framework’s graphicsopengl.cpp file.

Get Software Engineering and Computer Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.