PDA

View Full Version : Display Lists Problem



jerryd
06-04-2013, 02:04 PM
OpenGL forum,

Windows XP

I've used Game Maker, DarkBasic and SFML and want to move
up to openGL. My laptop is quite old so I have to stick to
older versions of OpenGL.

I'm reading the "red book" and have some simple programs working
but I'm stuck on "display lists". I can define a display list
and call the function but it never gets displayed on the screen.

ex:
#define MyTriangle 1

void buildTriangle()
{
glBegin(GL_TRIANGLES); // start a triangle definition
glVertex2f(0.f, 300.f); // first pair of Vertices
glVertex2f(200.f, 0.f); // second pair of Vertices
glVertex2f(400.f, 300.f); // third pair of Vertices
glEnd(); // end
glEndList();
}


I call this function in the "main()" with buildTriangle(); and
then I use glCallList(MyTriangle); followed by GLWindow.Display();

Nothing shows up on the screen. I can do this by using in-line
code.

Any suggestions?

Jerryd

Carmine
06-04-2013, 04:33 PM
You must have a 'glNewList' statement for every 'glEndList'.
In your case it would go before your 'glBegin' command.
Look up 'glNewlist' for the syntax.

jerryd
06-04-2013, 05:49 PM
Carmine,
Thanks for the reply.

I read up on glNewList and changed my code to:
GLuint MyTriangle = glGenLists(1);
void buildTriangle()
{
glNewList(MyTriangle, GL_COMPILE);
glBegin(GL_TRIANGLES); // start a triangle definition
glVertex2f(0.f, 300.f); // first pair of Vertices
glVertex2f(200.f, 0.f); // second pair of Vertices
glVertex2f(400.f, 300.f); // third pair of Vertices
glEnd(); // end
glEndList();
}

but it still doesn't show up?

Jerryd

Carmine
06-05-2013, 10:44 AM
Carmine,
Thanks for the reply. I read up on glNewList and changed my code .... but it still doesn't show up?
Jerryd The next thing I would do is comment out the calls to NewList and EndList.
Does the triangle show up? If not there could be any number of things wrong like
not setting up the projection matrices properly.

jerryd
06-05-2013, 06:04 PM
Carmine,
Commenting out those lines didn't fix it.

Here is my setup:

sf::Window GLWindow(sf::VideoMode(800, 600, 32), "OpenGL Window");
glViewport(0,0,800,600);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(0, 800, 600, 0, -1, 1);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

When I put the triangle definition in the main and not in a
display list it works.

Jerryd

jerryd
06-05-2013, 07:40 PM
OpenGL forum,

Here's kind of an update.

If I call the display list function before the loop in my main
and don't clear the buffer in the loop the triangle shows up
every other frame. I don't even execute a glCallList(MyTriangle);

int main()
{
buildTriangle();

while (GLWindow.IsOpened())
{
GLWindow.Display();
}

return EXIT_SUCCESS;
} // end main()

I just can't figure out how OpenGL works with the graphics card.

Jerryd

Carmine
06-06-2013, 10:48 AM
Looks like your problems are more basic than Display List issues.
At this point I'd refer you to the older, classic, Nehe Tutorials.
The first few actually deal with displaying at triangle
Get one of those basic tutorials working, then gradually alter it, till you get your program.
By 'working', I mean find the source code version closest to your situation, compile, link,
and execute it. Source code is provided for many different programming environments.

jerryd
06-06-2013, 01:31 PM
Carmine,

Thanks for all your help so far, I'll go read the Nehe Tutorials.
I hope they apply to my old version of OpenGL.

One more thing about my current program. I can display a triangle
and execute some keyboard directed transformations on it. I just
can't get the display list to work.

Jerryd