A Sample Port of a Display List

This topic gives an IRIS GL sample of code that defines three display lists; one of the display lists refers to the others in its definition. Following the IRIS GL sample is a sample of what the code looks like when ported to OpenGL.

IRIS GL Sample Display List Code

makeobj(10);  // 10 object 
    cpack(0x0000FF); 
    recti(164, 33, 364, 600);   // Hollow rectangle 
closeobj(); 
 
makeobj(20);  // 20 object 
    cpack(0xFFFF00); 
    circle(0, 0, 25);           // Unfilled circle 
    recti(100, 100, 200, 200);  // Filled rectangle 
closeobj(); 
 
makeobj(30);  // 30 object 
    callobj(10); 
    cpack(0xFFFFFF); 
    recti(400, 100, 500, 300);  // Draw filled rectangle 
    callobj(20); 
closeobj(); 
 
// Now draw by calling the lists 
call(30); 
 

OpenGL Sample Display List Code

Here is the preceding IRIS GL code translated to OpenGL:

glNewList(10, GL_COMPILE);            // List #10 
    glColor3f(1, 0, 0); 
    glRecti(164, 33, 364, 600); 
glEndList(); 
 
glNewList(20, GL_COMPILE);            //List #20 
    glColor3f(1, 1, 0);               // Set color to YELLOW 
    glPolygonMode(GL_BOTH, GL_LINE);  // Unfilled mode 
    glBegin(GL_POLYGON);  // Use polygon to approximate a circle 
        for(i=0; i<100; i++) { 
            cosine = 25 * cos(i * 2 * PI/100.0); 
            sine =   25 * sin(i * 2 * PI/100.0); 
            glVertex2f(cosine, sine); 
        } 
    glEnd(); 
    glBegin(GL_QUADS); 
        glColorf(0, 1, 1);            // Set color to CYAN 
        glVertex2i(100, 100); 
        glVertex2i(100, 200); 
        glVertex2i(200, 200); 
        glVertex2i(100, 200); 
    glEnd(); 
glEndList(); 
 
glNewList(30, GL_COMPILE);            // List #30 
    glCallList(10); 
        glColorf(1, 1, 1);            // Set color to WHITE 
        glRecti(400, 100, 500, 300); 
    glCallList(20); 
glEndList(); 
 
// Execute the display lists 
glCallList(30);