Display Lists § What is Display Lists? A group of OpenGL functions to be executed on GPU § Why using Display Lists is fast? glNewList(index, GL_COMPILE); glBegin(GL_TRIANGLES); … glEnd(); glEndList();
Display List Functions § GLuint glGenLists (GLsizei index) Generates one or more unused indices. Each display list is identified by an integer index. § void glNewList(GLuint list, GLenum mode) § void glEndList(void) Specifies the start and the end of a display list. GL_COMPILE: creates the list but the commands are not executed. GL_COMPILE_AND_EXECUTE: creates the list and executes the commands immediately. § void glCallList(GLuint listID) Calls a display list and to render a single frame now.
// myDisplay void myDisplay() { glClear(GL_COLOR_BUFFER_BIT); // compare this with example from Lecture 05. glCallList(drawDL); // call the list glTranslatef(0.05f, 0.05f, 0.0f); glRotatef(180, 0.0, 0.0, 1.0); glCallList(drawDL); // call the list glFlush(); //forces issued commands to execute }
Reading § To understand the design of display list: Red Book: chapter 7, pp.199-201 § To learn how to use display list: Red Book: chapter 7, example 7-1, 7-2
Pop-up Menu § Create a menu: int glutCreateMenu(void (*func)(int value)) func – the function that will handle the menu events. Returned value is the menu identifier. § Add entries to the menu: void glutAddMenuEntry(char *name, int value) Name – the string that show up in the menu Value – return to the function when menu entry is selected
Pop-up Menu § Attach menu to a mouse button void glutAttachMenu(int mouseButton) § Attach a submenu void glutAddSubMenu(char *entryName, int index) entryName – name of submenu entry in the menu. index – the index of submenu
Example 2 // https://github.com/javiergs/SER332/blob/master/Lecture10/ScreenShot%20example_two.png void createMenus() { //add entries to submenu Colores int menuA = glutCreateMenu(menuListener); glutAddMenuEntry("Red", 1); glutAddMenuEntry("Blue", 2); glutAddMenuEntry("Green", 3); glutAddMenuEntry("White", 4); //add entries to submenu Position int menuB = glutCreateMenu(menuListener); glutAddMenuEntry("Top", 5); glutAddMenuEntry("Center", 6); glutAddMenuEntry("Down", 7); // create main menu int menu = glutCreateMenu(menuListener); glutAddSubMenu("Colores", menuA); glutAddSubMenu("Position", menuB); // attach the menu to the right button glutAttachMenu(GLUT_RIGHT_BUTTON); } void myInit() { createMenus();
// processMenuEvents void menuListener(int option) { switch (option) { case 1: r = 1.0f; g=0.0f; b=0.0f; break; case 2: r = 0.0f; g = 0.0f; b = 1.0f; break; case 3: r = 0.0f; g = 1.0f; b = 0.0f; break; case 4: r = 1.0f; g = 1.0f; b = 1.0f; break; case 5: position_y = 0.3f; break; case 6: position_y = 0.0f; break; case 7: position_y = -0.3f; break; } glutPostRedisplay(); }