Unable to call multiple display list glCallList()

754 Views Asked by At

when i create a display list :

GLuint tampilkan()
{
    GLuint id = 0;

id = glGenLists(1);

glNewList(id, GL_COMPILE);

//bench
glPushMatrix();
glScalef(1.5,0.2,1.5);
GambarKu();
drawBox();
glPopMatrix();


//backbench
glPushMatrix();
glTranslatef(0.0f,2.5f,-1.3f);
glScalef(1.5,1.5,0.2);
GambarKu2();
drawBox();
glPopMatrix();

.... another foot using the same pattern push-pop matrix 

glEndList();    //=========================================================
return id;

}`

then i call that Display List in my "Display" Function :

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -7.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glCallList(tampilkan());
glPopMatrix();

glPushMatrix();
glLoadIdentity();
glTranslatef(0.0f, 0.0f, -5.0f);
glRotatef(yrot, 0.0f, 1.0f, 0.0f);
glCallList(tampilkan());
glPopMatrix();


glutSwapBuffers();

glFlush();

why its only showing one bench? (in other words just showing one of my display list)

it should be 2 bench with translation Z point at -5.0f and -7.0f

and when i change my first calllist glTranslatef(0.0f,0.0f,-8.0f) it doesn't change anything in the output. But, when i change my second calllist to glTranslatef(0.0f,0.0f,-8.0f) the bench, the output bench did translated its position to -8.0f (further than before -5.0f)

all i get is, this code only shows my second display list (with the Z point at -5.0f) and ignoring my first display list.

Anyone could help me with this? what did i do wrong?

1

There are 1 best solutions below

0
On

I don't know if this is going to solve your problem, but you're not supposed to create a new display list every time you draw it. Especially not twice the same.

When initializing your program, you create a display list once, and store its name (id). When rendering, you just call glCallList(id), twice in your case.