   Pre generate scenes
  Hi guys.I want to display something like the tv-noise. But, the size of each element in the noise is much bigger. We can consider them to be rectangles.I can draw them 'immediately' like below:for( i = 0; i < noRectangles; i ++ )   glColor3f(makeARandomColor......);   glBegin();glVertex(x,y,z);....   glEnd();But, the code above needs to compute a random color everytime when it draws, which might reduce the speed.So, instead, I also tried to use the 'display list', i.e. I generate some display lists using the above code, and put the code into my init_screen() function. When I need to draw it, I just use glCallList(listName). However, I noticed, when the number of the display lists increases, the speed reduced dramatically. It's even much much slower than in the 'immediate' mode.I've tested the code using 2 machines. One with dual-core with ATI HD2900 Pro and one with Pantium 2.8G with integrated Intel Graphics card.My question is: is there any other feature in OpenGL that can pre-generate the scenes?   
  Wait, you're not seriously calling glBegin and glEnd for every rectangle, are you?   ;  I am calling it for every rectangle. Is that a problem?Because every rectangle has its own colour, i do think it needs to have a glBegin() and glEnd().   ;  Yes, that's a big problem.  Excessive glBegin/glEnd calls waste bandwidth; do as much as you can in one batch:glBegin( /* ??? */ ); {for ( unsigned i = 0; i < noRectanges; ++i ) {// Alternatively, you can avoid floating point math here, and just use ints:unsigned c = rand()%255;glColor3ub( c, c, c );glVertex3f( x, y, z );}} glEnd();In any case, why not just use a shader or an animated texture?   ;  You might want to consider a custom shader/vertex buffer (VBO) for doing this. If you implement it that way you'll get a huge speedup over what you're doing. This will take a little bit of effort on your part to get implemented, but it is definitely something you should learn, as immediate mode and display lists are both depreciated now.One idea:Combine all of your "elements" into a single vertex buffer with no color information. Give each vertex an arbitrary index integer signifying which element it belongs to (so that all vertices of an element can have the same color).Each frame you can generate one random 'seed' and send that to gpu via a uniform. Then in the vertex shader define a simple function that takes that random number and the index integer of the vertex and maps it to a color. For example you can make your random function something like grayscaleColor = sin(1000*index*random_seed). (I realize thats not really random, but you can makeup whatever you want).Using this method you can have each of your elements draw every frame with a random color and only require something like 5 or less OpenGL calls (one to set the uniform random seed, one to draw the VBO, and a few to bind states). Feel free to ask more question if you need more explanation, I'm probably throwing a lot of new concepts at you, but that just highlights the power of custom opengl pipelines :)   ;  Actually, I am using the glColor3ub rather than glColor3f. I can't use texture, because I need to set a color for every rectangle. And currently I don't know what's a shader.But, ur code, I don't quite get it. In my loop, glBegin and End() only draws on rectangle. So after the loop, it will draw all the rectangles and these rectangles will construct a frame ( like a tv static noise). Maybe my original code was quite clear. So, what I am actually doing is to try to PRE-construct several these tv-static frames and when I need them, I just call the them randomly.So what I am actually doing is like this: In init function I pre generate the things I need://generate one rectangle.oneRectangle = glGenLists(1）；glNewList(oneRectangle,GL_COMPILE)   glBegin(GL_QUAD);glVertex(..);.....   glEnd();glEndList();//generate one frame (construct by many rectangles)oneFrame = glGenLists(noFrames）；glNewList(oneFrame,GL_COMPILE);  glColor3ub(a random color here for each rectangle);  glTranslatef(); move the next place for next rectangle  glCallList(oneRectangle);glEndList();In the draw functions, I call the frame list.drawingfunction(){  random = a new random number;  glCallList（oneFrame + random);};  I think see what you're trying to do. I don't really recommend it, but you're welcome to try. The approach I suggested was different (not 'pre creating' the scenes), but it would likely be fast enough that it would be a trivial cost.Just how many 'frames' are you trying to store in total? My only concern is that depending on how many elements you are drawing per frame, you could be eating up a huge amount of vram if you try to store more than a couple frames. That might explain why you're seeing slowdown.   ;Quote:Original post by karwostsI think see what you're trying to do. I don't really recommend it, but you're welcome to try. The approach I suggested was different (not 'pre creating' the scenes), but it would likely be fast enough that it would be a trivial cost.Just how many 'frames' are you trying to store in total? My only concern is that depending on how many elements you are drawing per frame, you could be eating up a huge amount of vram if you try to store more than a couple frames. That might explain why you're seeing slowdown.On the on hand, the bigger the number I set, the better (or more random) 'tv-noise' I would get. On the other hand, What you said is always true. The more I set the number, the more memory I need. I noticed, if I set the number more than 10, the frame rates reduced significantly. If I set it to be 64, it even stopped.You are also right, depend on the size of the rectangle and the number of frames, the 'immediate mode' and the VBO would take the upper hand in most cases. But, if each rectangle is very small, (but not a dot, still remain a rectangle,) the pre-generate idea is the best way.When I came across this pre-generate idea, I wanted to use space to treat for the efficiency. But, the real problem I think wasn't come from the display list. I just read some articles that claimed that the ATI HD 2XXX and 3XXXX doesn't support display list very much and in fact the display list feature is already deprecated. This might be the real problem. I am just thinking an alternative way to do this. If I didn't use OpenGL, if I used DirectDraw or SDL to render my scene, I would be able to use surfaces, then I could just drew everything on some surfaces beforehand. When I need it, I just Flip it onto the screen. That really worked. But, they are not OpenGL....   ;Quote:the 'immediate mode' and the VBO would take the upper hand in most cases.Just to make sure you understand the terminology, using immediate mode is the alternative to VBO. You can't use immediate mode and VBO, that doesn't make any sense. Immediate mode is any time you say "glBegin()", and I think that it is never what is your best choice (very slow and depreciated).Quote:I am just thinking an alternative way to do this.There's already been a few alternate suggestions in this thread. If you don't want to learn shaders for this that is fine, but I'm confused why you think using textures will not work for you? Your explanation that you need "one color for every rectangle" doesn't make sense to me, why can't you do this with a texture?If you want to use OpenGL commands to pre-build the frames, you could even do render-to-texture where you use OpenGL commands to draw a series of textures, and then random flip between them for your frames. If the detail is low you can even store this in a low resolution texture and stretch it to fill the screen if your squares are large.I wouldn't bother messing with Display List as as you said they are depreciated. I'm not sure what 'surfaces' are in the Context of SDL (kind of sounds like render-to-texture), but I'm certain that you can find OpenGL solutions that are at least as efficient (if not more so) than anything in SDL.   ;  Also I'm wondering, is your desired effect very high resolution TV noise? If that is the fact than this is probably the best/simplest use of a shader I've ever seen.I know you said you didn't know about shaders, but are essentially just a way to rewrite the entire pipeline on the graphics card. You can program them to do pretty much anything you can imagine.To get a tv-noise random image to appear on your screen all you would have to do is draw a single square on the screen, and then for the fragment shader set:main() {  float f = rand();// you might need to make your own pseudorandom generator  gl_FragColor = vec4(f,f,f,1);}This will set every pixel on the screen to a random grayscale value every frame. It will be insanely fast too. This will require an investment of your time to learn and set it up, but the rewards are well worth it and shaders are the only way to render anything in the new opengl that is not depreciated.