PDA

View Full Version : Display List Not working (solved)



Joshhua5
06-14-2011, 02:57 AM
Hello, I'm trying to get this display list working but it doesn't draw, and I'm stumped.


#include <gl\glut.h>
#include <gl\GL.h>

GLuint DrawDL(0);
void WindowInitGL(float Width, float Height, int argc, char **argv)
{
glutInit(&amp;argc, argv);
glutInitWindowPosition(0, 0);
glutInitWindowSize(Width, Height);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
glutCreateWindow("Box Test");
}

void DisplayList()
{
DrawDL = glGenLists(2);

glNewList(DrawDL, GL_COMPILE);
glBegin(GL_TRIANGLES);
glVertex2f( -1, 1);
glVertex2f( -1,-1);
glVertex2f( 1,-1);
glVertex2f( 1, 1);
glColor3f(1, 0, 1);
glEnd();
glEndList();
}


void DrawFrame()
{
glClearColor(1,1,1,1);
glClearDepth(0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glOrtho(-10, 10, -10, 10, -1, 1);
glCallList(DrawDL);
glFlush();
glutSwapBuffers();
}



int main(int argc, char **argv)
{
WindowInitGL(800, 600, argc, argv);
DisplayList();

glutDisplayFunc(DrawFrame);
glutMainLoop();
}

Alfonse Reinheart
06-14-2011, 03:22 AM
glBegin(GL_TRIANGLES);
glVertex2f( -1, 1);
glVertex2f( -1,-1);
glVertex2f( 1,-1);
glVertex2f( 1, 1);
glColor3f(1, 0, 1);
glEnd();


I'm trying to figure out how this worked without displaylists. GL_TRIANGLES means individual triangles. So the number of vertices you give it should be a multiple of 3.

And glColor3f being last doesn't make sense at all. Sure, for every frame after the first, it will appear to work. But the very moment you try to render anything else that touches glColor3f, you're screwed.

It should come first, not last.

And there's no need to call glFlush.

I'd suggest getting this working without display lists, then modify it to implement display lists.

Joshhua5
06-14-2011, 03:24 AM
it does work Without display lists.

Joshhua5
06-14-2011, 03:26 AM
Okay well changing Triangles to Quads, worked and i moved Colour to the front.