PDA

View Full Version : very high fps with just a few lines



svg
06-11-2001, 08:00 AM
Does anyone know how i can get a very high fps when i'm using a loop:

glbegin(gl_lines);
for x := 0 to 99 do
for y := 0 to 99 do
begin
glvertex3f(x,y,0);
glvertex3f(x+1,y,0);

glvertex3f(x+1,y,0);
glvertex3f(x+1,y+1,0);

glvertex3f(x+1,y+1,0);
glvertex3f(x,y+1,0);

glvertex3f(x,y+1,0);
glvertex3f(x,y,0);

end;
glend;

when i'm using this i'll get a fps around 15 to 20. but i think i can get a much higher performance.

can somebody help.

please know i'm just 14 years old and want to become a real programmer in 3D

Boresight
06-11-2001, 10:15 AM
Try put that code in a display list

Deiussum
06-11-2001, 10:51 AM
Display lists might help, but you are drawing a lot more lines than you really need to get the same display. If you change your loops a bit you can do the whole thing in 1 for loop with a lot fewer lines and that would probably speed you up more than anything else.

For instance you could get the same result with this...

glbegin(gl_lines);
for x:=0 to 100 do
begin

glvertex3f(x,0,0);
glvertex3f(x,100,0);

glvertex3f(0,x,0);
glvertex3f(100,x,0);
end
glend;

[This message has been edited by Deiussum (edited 06-11-2001).]

zed
06-11-2001, 04:28 PM
it looks like your lines are joined up if so
it'll be better using GL_LINE_STRIP or GL_LINE_LOOP

B. Jacob
06-11-2001, 11:37 PM
Why don't you try to use a vertex array ?
I don't know this technique very well, so I couldn't help you more, but I think it is the good direction to look in.

bsperlin
06-12-2001, 04:40 AM
A quick look at Deiussem rewrite of the nested loops: I don't think that it's the same as the original. For example, at some point of the original x=20 and y=20 simultaneously, but the rewrite doesn't have this situation.
Barry

svg
06-12-2001, 06:13 AM
well, I do know how to use it and I do. But my fps is still round the same numbers.

And i want to get some kind of a mountain in my scene so i use more like this code:
glnewlist(MY_FIELD, gl_compile);
glbegin(gl_lines);
for x := 0 to 99 do
for y := 0 to 99 do
begin
glvertex3f(@terrain[x,y]);
glvertex3f(@terrain[x+1,y]);

glvertex3f(@terrain[x+1,y]);
glvertex3f(@terrain[x+1,y+1]);

glvertex3f(@terrain[x+1,y+1]);
glvertex3f(@terrain[x,y+1]);

glvertex3f(@terrain[x,y+1]);
glvertex3f(@terrain[x,y]);
glend;
glendlist;

Deiussum
06-12-2001, 07:10 AM
Originally posted by bsperlin:
A quick look at Deiussem rewrite of the nested loops: I don't think that it's the same as the original. For example, at some point of the original x=20 and y=20 simultaneously, but the rewrite doesn't have this situation.
Barry

I don't quite understand what you mean. Walk though a few loops of his code and you see he is just drawing a grid of squares left to right, bottom to top. He's going to have a LOT of lines that are redundant. You can get the same effect by just drawing a bunch of horizontal and vertical lines, which my code does.

Take your example for instance. When x=20, y=20 my solution covers that because when x=20 it drew a line from (20,0) to (20,100) which goes through the same line on the left that he would have written. The bottom would have been taken care of by drawing the line (0,20)-(100,20). When my x=21 it would draw the line to the left side and top of his box when x=20, y=20.

Now if he wants to do a heightmap, as it appears from is later post, then my rework wouldn't work because he couldn't assign individual heights. His original code had all heights of 0, so my rework is perfectly valid.

svg
06-12-2001, 08:15 AM
you're right.

But when i said i wanted to make a field with a mountain.
I mean that in your 21 * 21 grid a mountain is.
this mountain is at point 5,5 and to make it a mountain the y isn't 0 but 1.

Thanks anyway.

Zadkiel
06-12-2001, 08:37 AM
When I tried this a while ago I drew the terrain with a series of triangle strips and then I used a technique that I read in the red book online that described how to render none see-through faces in a wireframe mode.

Unfortunatly on most machines lines will always be slow.

Tim Stirling
06-12-2001, 08:54 AM
As Zadkiel has just mentioned lines are very slow on most comsumer hardware and you are drawing a lot of lines so what every you do you may only get a similar FPS.

bsperlin
06-12-2001, 09:11 AM
Yes, Deiussum, you are right! Sorry, I looked at it too fast.
Barry

Deiussum
06-12-2001, 09:49 AM
Using a combination of line strips and a modified version of my algorithm above, you could probably get SOME speedup and be able to use different z values for everything. As your algorithm stands, you are basically drawing all lines that aren't on the border of the grid twice. By just using vertical and horizontal line strips, you could ensure that each one is only drawn once. Using line strips would also considerably reduce the number of vertices you have to send as well.

If you're not sure what I mean, let me know and I'll write up a quick little algorithm describing what I mean. Basically, it means that instead of sending each vertex (except the edges) to the renderer 4 times (once for each line it's a part of), you would only send them twice (once going horizontally, once vertically).

Probably not a huge speedup, but it might help some. As others have already pointed out, drawing lines can be pretty slow on most cards.



[This message has been edited by Deiussum (edited 06-12-2001).]

zed
06-12-2001, 07:23 PM
i had a closer look at your code + it looks like u want to draw a grid.
well if thats the case only 200 lines r needed total 100 vertical and 100 horizontal
the length of each line is x*100
eg
loop horizontal lines
{
glVertex2f(0,x);
glVertex2f(100*1,x); // (100x1 equals the whole width)
}

svg
06-13-2001, 06:25 AM
I didn't test the new stuff.
(6 to 11).
But what DEIUSSUM said about
the lines I'm drawing 4 times and what you told me was something i should know.
it's so damn easy. But thanks,
now i draw a lot less lines so my fps
will be some higher. I suppose.

I am really greatfull for all help. But this doesn't mean that you guys out there can
still help me with improving my fps.

everything is worth, is it.

or whatever. Thanks.

svg
06-15-2001, 11:56 AM
Damn, it didn't increased my fps not. well, just a bit.
it's now round 20. without texture.
ouf. with texture I tried I had the first time to reboot my computer.
and the second time my fps was so worde, go so worse it was 1.2 per second that's so worse.
can nobody tell me how to get a boost with texture. or am i doing high texture quality. or something

thanks anyway.

ffish
06-15-2001, 04:40 PM
Your z value is always 0 so it's series of lines in the xy plane? Draw the lines you want in a 2D drawing package (Photoshop etc) on a white or black background, save to an image file, and make one textured quad using the image as the texture. You can use the alpha test to only display the lines and not the background of the texture. Easy and fast.

Hope that helps.

pATChes11
06-15-2001, 04:50 PM
It would help to know what video card you have. If it is a 3Dfx card, set your color depth in Windows and your app to 16bit. I think the latest reference drivers for the earlier-than-Voodoo3 allow 16bit rendering in a 32bit mode, but I can't remember. I have a GeForce2 GTS now, which proves to be much better. http://www.opengl.org/discussion_boards/ubb/smile.gif When I do anything with texturing in software, my FPS goes down to like 5 or so (with linear/linear mipping http://www.opengl.org/discussion_boards/ubb/smile.gif), but I have a pretty decent system. In hardware, my FPS for something like what you're doing is uncountable with Windows' millisecond counter http://www.opengl.org/discussion_boards/ubb/redface.gif)

Deiussum
06-18-2001, 05:23 AM
ffish,

I thought that he just wanted a drawn grid at first too, but if you read one of his later posts it sounds like he wants to be able to change the z values at sometime to use it as a form of heightmap, so the single textured quad wouldn't work so well for that.

svg,
Thinking of that, though, if you could draw up a texture in photoshop as ffish suggested, then draw your scene with triangle strips, it might give you some speedup. You'd have to get the texcoords just right so that the intersection of lines on the texture matched up with vertices in the triangle strips, but that shouldn't be too difficult. Anyway, it's a thought. http://www.opengl.org/discussion_boards/ubb/smile.gif