Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 8 of 8

Thread: Display Lists Problem

  1. #1
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    5

    Display Lists Problem

    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

  2. #2
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    189
    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.

  3. #3
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    5
    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

  4. #4
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    189
    Quote Originally Posted by jerryd View Post
    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.
    Last edited by Carmine; 06-05-2013 at 02:51 PM.

  5. #5
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    5
    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

  6. #6
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    5
    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

  7. #7
    Junior Member Regular Contributor
    Join Date
    Apr 2012
    Location
    Los Angeles
    Posts
    189
    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.

  8. #8
    Junior Member Newbie
    Join Date
    Jun 2013
    Posts
    5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •