Sign in to follow this  

why so slow?

This topic is 3730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am a little confused now. Many of the games I play have many thousands of polygons in a scene with textures and whatnot, but I have created an OpenGL scene with 3000 points rotating around the origin and it runs slow on my computer? Is this because they are are rotating or something else?

Share this post


Link to post
Share on other sites
More likely than not it has to do with the method by which you are submitting the polygons to be rendered. glVertex() type functions run slowly, very slowly [they are the absolutely slowest form of putting geometry onto the hardware to be rendered. The only thing slower would be manually drawing things a pixel at a time].

The games you are referring to do not use glVertex, instead they store the geometry on the hardware in the form of a vertex buffer [think ogl calls them vertex objects, but they are the same thing], and draw them all at once.

It's not because it's rotating, of that you can be certain. Plenty of games have plenty of things that do a whole lot of rotating.

Share this post


Link to post
Share on other sites
Without seeing your code it's hard to say. You could be sending information to the video card inefficiently, you could be using inefficient programming language constructs or calling more expensive versions of functions, you could be performing redundant computations, etc., etc., etc.

Share this post


Link to post
Share on other sites
I'm using a display list to store the points. Here is some code to show you how I put it into the list.

void DrawLine(float originX, float originY, float originZ, float destinationX, float destinationY, float destinationZ)
{
glPointSize(6.0f);

glBegin(GL_POINTS);
glColor3f(0.0f, 0.0f, 0.0f);
glVertex3f(originX, originY, originZ);
glVertex3f(destinationX, destinationY, destinationZ);
glEnd();

glLineWidth(2.0f);

glBegin(GL_LINES);
glColor4f(0.0f, 0.0f, 0.0f, 0.2f);
glVertex3f(originX, originY, originZ);
glVertex3f(destinationX, destinationY, destinationZ);
glEnd();
}

void LoadData()
{
#define random() (rand()%20)-10

srand(time(NULL));

float _x = random();
float _y = random();
float _z = random();

float x;
float y;
float z;

glNewList(DATA_LIST_INDEX, GL_COMPILE);

for (int i=0 ; i<4000 ; ++i)
{
x = random();
y = random();
z = random();

DrawLine(_x,_y,_z,x,y,z);

_x = x;
_y = y;
_z = z;
}

glEndList();
}


Then how I display it.

void Draw(float time)
{
static float theta = 0.0f;

/* OpenGL animation code goes here */

glClearColor(1.0f, 1.0f, 1.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glLoadIdentity();

// Change field of view, aspect ration and draw distances.
gluPerspective(30.0f,(GLfloat)1024/(GLfloat)768, 0.2f ,80.0f);

// Move everything back so that it can be observed nicely.
glTranslatef(0.0f, -0.0f, -40.0f);

// Rotate forward a bit so it looke nicer.
glRotatef(25.0f, 1.0f, 0.0f, 0.0f);

// Start data matrix.
glPushMatrix ();
// Spin so user can observe space.
glRotatef(theta, 0.0f, 1.0f, 0.0f);
// Draw axis and data structure.
glCallList(AXIS_LIST_INDEX);
glCallList(DATA_LIST_INDEX);
// End data matrix,
glPopMatrix();

if ((theta + time) > 360)
theta = (theta + time) - 360;
else
theta += time;
}


The time parameter is incremented by a set time each time the display loops (just as a temp solution until a performance timer is implemented).

Share this post


Link to post
Share on other sites
You're making A LOT of state changes. You don't need to render one point or one line at a time, you can render multiple primitives inside a single glBegin()/glEnd() block. What you should be doing is to rearrange your calls so you have something like:


glNewList(...)

glPointSize(6.0f)
glBegin(GL_POINTS);
DrawAllPoints();
glEnd()

glLineWidth(2.0f)
glBegin(GL_LINES);
DrawAllLines();
glEnd();

glEndList();




Other than that, rendering lines is often pretty expensive, I have a witnessed a complex scene running substantially slower in wireframe mode than in textured mode. It probably has something to do with how the card renders the lines; it could be possible that, internally, it renders 2 triangles for each line.

Share this post


Link to post
Share on other sites
WOW! Ok I took out the lines and increased the number of points to 10,000 which ran about 50fps. Then making only one call to glBegin and it climbed to 73-75 (its capped). I guess that makes a difference :D Lesson learned.

Share this post


Link to post
Share on other sites

This topic is 3730 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this