Archived

This topic is now archived and is closed to further replies.

show something on screen after certain time has elapsed

This topic is 5779 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

Hi, I am trying to render a shape after some time has elapsed. Instead of using a timer i am trying to use a simple counter. This is the code i have so far
  
static int counter = 0;
GLfloat tri_x, tri_y, tri_z;

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();
	
glBegin(GL_POINTS);
glColor3f(1.0f, 1.0f, 1.0f);
for(int i = 0; i <= 1024; i++)
	glVertex3f(stars1[i].x, stars1[i].y, stars1[i].z);
glEnd();

glBegin(GL_POINTS);
glColor3f(1.0f, 1.0f, 1.0f);
for(i = 0; i <= 1024; i++) {
	glVertex3f(stars2[i].x, stars2[i].y, stars2[i].z);
}
glEnd();

if(counter == 10) {
	glBegin(GL_TRIANGLE_FAN);
	glColor3f(1.0f, 0.3f, 0.2f);		
	for(i = 0; i <= 2.0f * 3.14 * 3; i++) {
		tri_x = 2.0f * cos(i) * 3;
		tri_y = 2.0f * sin(i) * 3;
		tri_z = -1000.0f;
		glVertex3f(tri_x, tri_y, tri_z);
	}
	glEnd();
}

glPopMatrix();

glFlush();

if(counter >= 10)
    counter = 10;

counter++;

  
Now the code in if never gets executed. I think I am going wrong somewhere but what am I doing wrong ? I am doing it the same way as the following is done. Without the if however it does draw to screen.
  
glRotatef(angle, 1.0, 0.0, 0.0); 
....
if(angle >= 360.0f) 
      angle = 0.0; 

angle++; 
  
Hope someone can help. Thank you.

Share this post


Link to post
Share on other sites
You clamp the counter to 10, then increment, for an eventual count of 11.

You should increment, then clamp.

And/or change your display query from (==10) to (>=10).

Or chuck the whole idea and do it right, track the real time.

I use glut, so a simple:

int millisecTime=glutGet(GLUT_ELAPSED_TIME);

zin



zintel.com - 3d graphics & more or less

Share this post


Link to post
Share on other sites