PDA

View Full Version : render optimization question



Sickboy
01-14-2004, 04:58 AM
Hi guys,

at the moment i have about 3000 Points in about 5500 triangles and my System (Athlon 2000, 64mb gfx card) slow down when my openGL window has to display them.
The big trouble is that i need to display alot of more points in the future http://www.opengl.org/discussion_boards/ubb/frown.gif

I have all Points and triangles stored in two vector.

When i render the scene i do the following:

std::vector<std::vector<double> > MyMeshPoints = controller->m_Datas.getMeshPoints();
std::vector<std::vector<double> > MyMeshTriangles = controller->m_Datas.getMeshTriangles();
int iAmountMeshTriangles = MyMeshTriangles.size();

int l,m,n;
glLineWidth(0.5);
glColor4f (0.0, 0.0, 0.4,0.5);
glPolygonMode(GL_FRONT, GL_LINE);
for (int k=0; k<iAmountMeshTriangles; k++)
{
l = MyMeshTriangles[k][0];
m = MyMeshTriangles[k][1];
n = MyMeshTriangles[k][2];
glBegin(GL_TRIANGLES);

GLfloat iPointx = convertRechengebietX_ToOpenGL(MyMeshPoints[l][1]);
GLfloat iPointy = convertRechengebietY_ToOpenGL(MyMeshPoints[l][2]);
glVertex2f(iPointx,iPointy);

iPointx = convertRechengebietX_ToOpenGL(MyMeshPoints[m][1]);
iPointy = convertRechengebietY_ToOpenGL(MyMeshPoints[m][2]);
glVertex2f(iPointx,iPointy);

iPointx = convertRechengebietX_ToOpenGL(MyMeshPoints[n][1]);
iPointy = convertRechengebietY_ToOpenGL(MyMeshPoints[n][2]);
glVertex2f(iPointx,iPointy);

glEnd();
}


It would be nice if someone could give me some hints, what i could do to improve my code.

And a second simple question.
I have the possibility to zoom and scroll inside my openGL window.I do it by recalculating all points and redrawing the scene every time.
Is there a better solution?

thx in advance
daSickboy [daNoob]

mikael_aronsson
01-14-2004, 05:38 AM
Hi !

I don't think the performance problem has much to do with OpenGL, first of all you should have a look at convertRechengebietX/Y_ToOpenGL(), is this an inline function ? does it do something complex ?

Try to preprocess your data in some way so that you don't have to do it over and over again for each frame if you don't need to.

To get faster OpenGL rendering you need to put your vertex data in memory that can be accessed by the GPU, use display lists or vertex buffers.

A few hundred thousands of vertices should not be a big problem to handle.

Mikael

Mikael

Sickboy
01-14-2004, 05:58 AM
Thatīs my function to convert the point values for displaying.

float COpenGL::convertRechengebietX_ToOpenGL(double RechengebietX)
{
int offset = controller->iXOffset;
int zoom = controller->iZoom;
double width = controller->width;
float result = ( (( RechengebietX - offset) *iZoom) / (width)) *2 - 1.0;
return result;
}

Do you think it would help in this case to use a display list you mentioned?

thx
daSickboy

chowe6685
01-14-2004, 07:23 AM
also move the glBegin()...glEnd() out of the loop, you are calling them 5500 times, no wonder things are slowing down