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 4 of 4

Thread: Noobie question on display lists

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    9

    Noobie question on display lists

    There is no actual problem, I just want to understand display lists better.

    The code below is (obviously) part of a larger program. In main, init_ground is called. After, the glut loop is entered, and the callback functions are looped through, one of which calls a display function, which calls the display list 'ground'.

    The bit that confuses me is how does the display function know what the contents of the 2 arrays are (needed for the material properties) if it is only calling the display list?

    Code :
    void init_ground()
    {
    	GLfloat amb_and_diffuse[]= {0.1, 0.7, 0.1, 1.0};
    	GLfloat emission[]= {0.0, 0.2, 0.0, 1.0};
     
    	ground = glGenLists(1);
    	if (ground!=0)
    	{
    		glNewList(ground, GL_COMPILE);
    			glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, amb_and_diffuse);
    			glMaterialfv(GL_FRONT, GL_EMISSION, emission);
     
    			glBegin(GL_QUADS);
    				glNormal3f(0.0, 1.0, 0.0);
    				glVertex3f(-100.0, 0.0, -100.0);
    				glVertex3f(100.0, 0.0,-100.0);
    				glVertex3f(100.0, 0.0, 100.0);
    				glVertex3f(-100.0, 0.0, 100.0);
    			glEnd();
    		glEndList();
    	}
    	else
    		fprintf(stderr, "Error: OpenGL could not obtain a list for the ground\n");
    	return;
    }

  2. #2
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Noobie question on display lists

    http://www.opengl.org/sdk/docs/man/xhtml/glNewList.xml
    Apart from the exceptions listed in the documentation, every gl command is compiled within the display list, even glMaterialfv commands and their parameters.
    Imagine GL commands are assembly instructions for a Lego toy. Display list compiles the finished result to a 3D printing that can be build with 1 instruction.

  3. #3
    Junior Member Newbie
    Join Date
    Jan 2009
    Posts
    9

    Re: Noobie question on display lists

    So, if material commands require arrays outside of the display list, those arrays are compiled with the commands in the display list?

  4. #4
    Super Moderator OpenGL Lord
    Join Date
    Dec 2003
    Location
    Grenoble - France
    Posts
    5,655

    Re: Noobie question on display lists

    Yes.
    Think about it : if it was not the case, the performance benefits of using display lists would disappear.

Posting Permissions

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