opengldisplaylist

display lists wont run


I am trying to create a tool that will draw a shape in openGL and then modify the values of the properties of that shape in a windows form. So if my shape is a rectangle, I will create a form that will allow the user to control the size, color etc of the rectangle. I have written the openGL code in managed c++ and the form in c#, and as some of these shapes got more complicated I decided to make display lists for them (for both performance and predictability purposes).

I define the display list in the constructor for the shape and I call the display lists in the render method.

My issue is that my display lists won't run at all. The parts that I render outside of a display list will be rendered, but the parts inside the display list will not be rendered.

Here's some sample code of my process:

//c# side
GLRectangle rect
public CSharpRectangle() {
    rect = new GLRectangle();
}

//managed c++ side
public GLRectangle() {
   width = 50;
   height = 50;
   //initialize more values
   rectDL = glGenLists(1);
   glNewList(rectDL, GL_COMPILE);
        renderRect();
   glEndList();
}
public render() {
     //Draw border
glBegin(GL_LINE_LOOP);
    glVertex2f(0, 0);
    glVertex2f(width, 0);
    glVertex2f(width, height);
    glVertex2f(0, height);
glEnd();

     //Draw interior
     glCallList(rectDL);
}
private renderRect() {
     glRectf(0,0,width,height);
}

In this example, the border of the rectangle would be rendered, but the rectangle itself won't be rendered... if I replace the display list with simply a method call, the rectangle is rendered fine. Does anyone know why this might be happening?


Solution

  • I want to give my 2 cents.

    The code in your question seems correct to me, so probably there something else in your application that make your display list not runnable.

    The only thing I can think is there's no current context when compiling the display list (indeed when executing GlRectangle constructor). So, is that routine executed in the same thread which have called glMakeCurrent? Is that routine called after glMakeCurrent?

    Further, check with glGetError after each OpenGL routine in order to validate the operation. In the case it returns an error, you can know what's wrong in your code..