PDA

View Full Version : hard slow down when adding a triangle



mcbastian
11-15-2000, 01:53 AM
HI!

I have a problem with OpenGL. I Use MS-VC6
and a RIVA TNT2 with ELSA relevator-driver.
I have a scene where a wave is displayed.
(sorry for my bad english!)

i use:

before display is called within the OnIdle event:

glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();

glLookAt(......);


// function not complete
float x,y,z,k,x1......;
int i,j;
void display()
{
k+=0.05;

// for each little square.....

for (i=0;i<10;i++)
{
for (j=0;j<10;j++)
{
// here are 8 sine and cosine-calls
// standard-math.h
// not optimized.....
// it's a square in x-z, splitted in many
// triangles. in this cut off part, the y-
// part is calculated....
// triangle 1
glBegin(GL_TRIANGLES);
glvertex3f(x1,y1,z1)
glvertex3f(x2,y2,z2)
glvertex3f(x3,y3,z3)
glEnd();

/* the big square is split in 100 little squares, and every little square is split in 2 triangles, to get a smoth wave. it's a sine in x-direction and a cosine in z-direction.
if you whish, i can post the whole code.
*/
// triangle 2
glBegin(GL_TRIANGLES);
glvertex3f(x1,y1,z1)
glvertex3f(x4,y4,z4)
glvertex3f(x3,y3,z3)
glEnd();

/* this will run very fast and good, but if i add the following, the speed is slowed down a lot...
btw: I use LIGHTNING with 1 lightsource
the polygones are filled.
when the polygon-mode is set from GL_FILL to GL_LINE it runs as fast as without the following....
*/

//
glBegin(GL_QUADS);
glvertex3f(-1,1,-2);
glvertex3f(-1,-1,-2);
glvertex3f(1,-1,-2);
glvertex3f(1,1,-2);
glend();
}
}
}
if i comment out the last glbegin-glend statements the program will run much faster. but why? adding a single fixed polygon slows down so much ?????

thanx 4 help!

Bastian.

Michael Steinberg
11-16-2000, 05:58 AM
Well, it's just a guess, but when you wrote all the triangles to the driver, the pipeline went fuller and fuller. The driver "empties" the pipeline very slow, since you use software lighting. Now, when you say glBegin(GL_QUADS), the driver has to empty the pipeline, change Face Definition state and will then draw your quad.
Maybe, if you specify you last polygon as GL_TRIANGLE it will get faster.

Well, it's just a guess however.

mcbastian
11-16-2000, 06:24 AM
no. when using GL_TRIANGLES it won't get much faster. better, it won't get faster :-)
I found the mistake. i have to put the quad OUTSIDE the for-statement :-) that happens when you code at 1:00 am http://www.opengl.org/discussion_boards/ubb/smile.gif
the next is, to use ONE glBegin()-glEnd statement http://www.opengl.org/discussion_boards/ubb/smile.gif

CU! Bastian

Michael Steinberg
11-16-2000, 06:30 AM
Oh yes...
That is adding code to the board. You can't see anything, especially no tabs of for statements...

Well, I know what you mean. I'm living in germany, and if I want to be efficient on the board, I have to wait for american time...

Efficiency of using a message board:
1/(question_answer_time-question_post_time)