About glGet()

Started by
1 comment, last by V-man 15 years, 8 months ago
I want to render some lamps , so I use glGetLightfv() to get the position of a lamp.But I find that the first time when I use the function glGetLightfv()spend much more time then the others. The glut is used in the project. The display() function is like this: for(int i=0;i<light_num;i++) { glGetLightfv(GL_LIGHT0,GL_POSITION,ltPosition); ......move coord to ltPosition ......renfer the lamp } The image is correct. The time spending for rendering each lamp: 0.079584 0.000152 0.000132 0.000122 0.000113 0.000122 0.000123 0.000117 What result this?Are there some details I forget to set?
Advertisement
You might find it easier to keep the positions of your lamps stored elsewhere (a customised 'light' structure or a simple array would work), that way you've always got access to them and there's no need to keep asking where they are when you want to do things with them.

As for it taking longer the first time, it's not something you're going to avoid, regardless of what you try. If it kept happening every few frames or something, then you'd have something to complain about, but otherwise, don't worry about it. If you feel it's really that horrible, try implementing a simple loading screen before you start rendering everything, and you might find it disappears (the first frame always takes a bit of time to render, but after that, it's usually fine).
glGet are always slow. Try to avoid it.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement