21. OpenGL Display Lists
An opengl display list is an object created and stored in the memory that can be called multiple times without opengl having to recreate the object again and again. This saves processing time and thus increases your frames
per second in your application when you move into worlds with multiple objects. In this OpenGL tutorial I will be teaching you how to set up and call these display lists to help optimise your code. I will be doing this with the glut cube but you may not notice the difference unless you change to code to create alot of cubes.
A display list can be treated just like any other object, you
can change its texture, lighting abilities, size, etc.
Although once the list has been created you cannot edit
the actual shape of the object in the list. You can scale it
with the scale command, but you cannot change the vertices etc
without recreating the whole list from scratch.
Now to create a list we first have to setup and unsigned integer
to hold the list. I have done it with:
GLuint cubelist;
next we move onto acctually creating the list. When doing this
there are 2 steps. The first is to set the list the generate a list
with:
cubelist = glGenLists(1);
then we tell it to make a new list using cubelist:
glNewList(cubelist,GL_COMPILE);
after this come whatever code you need for your object.
then after you have done all the code you need for your object
to function, just call:
glEndList();
to end the creation of the current active list.
and to call the list whenever you need it, you simply use
glCallList(cubelist);
and that is it, just remember to create the list before you call it
otherwise nothing will show.
If you have any queries regarding this tutorial, please email me at swiftless@gmail.com
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52. 53. 54. 55. 56. 57. 58. 59. 60. 61. 62. 63. 64. 65. 66. 67. 68. 69. 70. 71. 72. 73. 74. 75. 76. 77. 78. 79. 80. |
#include <GL/gl.h> #include <GL/glut.h> #include <stdlib.h> GLuint cubelist; //we are going to hold our list in here //create the cube display list void init (void) { void display (void) { void reshape (int w, int h) { void keyboard (unsigned char key, int x, int y) { int main (int argc, char **argv) {
|
Hey, just tried this tutorial and it all works very nicely (so good on you for that) but I am having some difficulty will using this with an object with variable… er… variable.
For this quad I am using a variable y value (in 3d space) which works fine normally, but when I put it into here the shape does not show the variable value changing at all (I’m trying to get water wave effects working on a game).
Any thoughts?
Thanks in advance
Hey TBM,
Your question doesn’t make much sense at first glance, what does the y value do? Also, it wouldn’t be wise to use variables in display lists, they are only meant to store shapes that don’t change.
Cheers,
Swiftless
Hey people,
I can’t enter into the GameMode, the ms-dos window appears with a message that “unrecognized string in game mode” , “cannot create windows in game mode” . i think its related to the glutGameModeString(“…”);, i copied the string from here too , still got the error
Please help me.
It means either the resolution you are trying to use or the refresh rate are not supported by your hardware, try changing the 75 to a 60 and running it.
These are great tutorials, you explain things very well 😀