THEORY: Quad Points and Speed

Started by
37 comments, last by Lord_Evil 16 years, 9 months ago
Hi, I'm trying to make a map editor. The editor works fine, except that it works really slowly, even though I have newish machine. The way the map is to be described, there is a grid of quads, each with 4 vertices with varying up/down coords. defined like so:
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0); glVertex3f(i.vertex1[0], i.vertex1[1], i.vertex1[2])
glTexCoord2f(0.0, 1.0); glVertex3f(i.vertex2[0], i.vertex2[1], i.vertex2[2])
glTexCoord2f(1.0, 1.0); glVertex3f(i.vertex3[0], i.vertex3[1], i.vertex3[2])
glTexCoord2f(1.0, 0.0); glVertex3f(i.vertex4[0], i.vertex4[1], i.vertex4[2])
glEnd();
...where the vertex[0] is xpos, vertex[1] is ypos and vertex[2] is zpos. Because each vertex's ypos will be a decimal value, I cannot use display lists with any practicality. The issue, again, is speed. With a 50x50 grid map, it hardly runs at all. (2, 3 fps). I know it can be done, as I have seen games for Windows 98 that do similar things at incredible speed on today's computers. For completeness, here is a link to the project: http://www.pygame.org/projects/10/455/?release_id=770 The project is done in Python/Pygame2.4/PyOpenGL. So, any tips on how to improve speed? Geometrian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
if your code is something like:

for i++ {
glBegin(GL_QUADS)
glTexCoord2f(0.0, 0.0); glVertex3f(i.vertex1[0], i.vertex1[1], i.vertex1[2])
glTexCoord2f(0.0, 1.0); glVertex3f(i.vertex2[0], i.vertex2[1], i.vertex2[2])
glTexCoord2f(1.0, 1.0); glVertex3f(i.vertex3[0], i.vertex3[1], i.vertex3[2])
glTexCoord2f(1.0, 0.0); glVertex3f(i.vertex4[0], i.vertex4[1], i.vertex4[2])
glEnd();
}


try something more like:

glBegin(GL_QUADS)
for i++ {
glTexCoord2f(0.0, 0.0); glVertex3f(i.vertex1[0], i.vertex1[1], i.vertex1[2])
glTexCoord2f(0.0, 1.0); glVertex3f(i.vertex2[0], i.vertex2[1], i.vertex2[2])
glTexCoord2f(1.0, 1.0); glVertex3f(i.vertex3[0], i.vertex3[1], i.vertex3[2])
glTexCoord2f(1.0, 0.0); glVertex3f(i.vertex4[0], i.vertex4[1], i.vertex4[2])
}
glEnd();

Cutting out the extra OpenGL calls should greatly improve rendering.
And since your just rendering a grid, you should use Triangle Strips, that'll cut out a load more glVertex calls.

If you really only see a few squares at a time, you could try Frustrum culling to determain what's visible or not, but if you do see most of the grid all the time, using a Display list will greatly improve performance.

Those are just some quick and easy techniques that should always be used, if these don't work, then it's goto be something else wrong, like a driver problem or something.
That first thing improves it a lot, 50x50 is now tolerable, though there is still a noticeable slowdown. My target map resolution is minimally 100x100. It is preferable to have something more like 150x150 or 200x200.
Quote:Original post by Johnny123
Cutting out the extra OpenGL calls should greatly improve rendering.
And since your just rendering a grid, you should use Triangle Strips, that'll cut out a load more glVertex calls.
I'm not sure exactly what you mean--is it that I should be using two triangles instead of a quad?
Quote:Original post by Johnny123
If you really only see a few squares at a time, you could try Frustrum culling to determain what's visible or not, but if you do see most of the grid all the time, using a Display list will greatly improve performance.
I will be seeing most of it, and like I said, using display lists is impractical. Each vertex has a y coordinate ranging from -3.0 to 3.0. The increments are in 0.1, so that's 30*30*30*30 = 810,000 display lists I would have to make. I'd rather not write a huge section of code to make and call them automatically.
Quote:Original post by Johnny123Those are just some quick and easy techniques that should always be used, if these don't work, then it's goto be something else wrong, like a driver problem or something.
I've seen this sort of thing done in .exe programs on this computer.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

From what I've gathered (I have, I'll admit, yet to learn the use of this myself), Vertex Buffer Objects might be a good way to go. As I understand it, they seem to provide a means to fast, alterable geometry - which, it seems to me, is pretty much what you want.

I suggest starting with a search of these forums using the keywords "vertex buffer object".

MWAHAHAHAHAHAHA!!!

My Twitter Account: @EbornIan

I did; I found a bunch of stuff about people having problems with it, not any basic info. about them, e.g. what they are, how they work, basic code.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

A triangle strip is used to cut out the number of Vertexes that you have to send to the renderer. It does use Triangles instead of Quads, but it removes the redundancy of points that are shared with multiple polygons.

Link to Triangle Strips:
http://www.opengl.org/resources/code/samples/sig99/advanced99/notes/node18.html

Wait, I'm not sure what your definition of Display lists are but, Link:
http://www.lighthouse3d.com/opengl/displaylists/

Give something like this a shot:


[INIT CODE]
GLuint myList;
myList= glGenLists(1);
glNewList(myList,GL_COMPILE);

glBegin(GL_QUADS)
for i++ {
glTexCoord2f(0.0, 0.0); glVertex3f(i.vertex1[0], i.vertex1[1], i.vertex1[2])
glTexCoord2f(0.0, 1.0); glVertex3f(i.vertex2[0], i.vertex2[1], i.vertex2[2])
glTexCoord2f(1.0, 1.0); glVertex3f(i.vertex3[0], i.vertex3[1], i.vertex3[2])
glTexCoord2f(1.0, 0.0); glVertex3f(i.vertex4[0], i.vertex4[1], i.vertex4[2])
}
glEnd();

glEndList();



[RENDER CODE]
glCallList(myList);


-----------
You have to think of OpenGL (or any Rendering API) as one big bottleneck, and the best way to speed it up, is to cut out as many calls to it as possible.
I will look into triangle strips. Yes, that is the way I do display lists. However, notice that changing a single vertex in a single quad means rebuilding the display list. Actually, I think I can do that. I will try to get it working that way. But now I'm curious, I looked around for something that fit what I needed, and I came across VBOs. Redirect here:
http://www.gamedev.net/community/forums/topic.asp?topic_id=456434

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Just a quick Question, Is this grid dynamic or static?
I kinda just assumed it was static. If it does in fact get modified often, like every frame, then Display lists may not be the way to go.
Um, semi-dynamic. The grid is static unless changed with an "a" or "z" key press. I should have made that more clear initially. I have redone the editor so it uses a display list, which is updated when an "a" or "z" key is pressed. It runs crystal clearly at 500x500 until "a" or "z" is pressed and it takes FOREVER to change (on my machine it just crashes). This is because it must build the list for (in the case of 500x500) 250,000 quads. Which is a lot. It takes a while to generate the first time around too. Is there a way to update only a portion of a display list?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Cool that makes a few things clearer.


You could used a Quad tree. Instead of having the entire grid in 1 single Display List, you can break it upto, say 20x20 grid squares per QuadTree node.

When ever a square changes, you just update the node that it's in. Updating a 20x node should be really fast; real-time.

http://www.gamedev.net/community/forums/topic.asp?topic_id=456434

[EDIT]
Umm, just make sure you clear the old list, and your not continually making a new one :)

This topic is closed to new replies.

Advertisement