• Advertisement
Sign in to follow this  

a simple one with a simple answer

This topic is 4434 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 new to OpenGL and I have a simple question that has to have a simple answer. How can I delay my drawing. Long story short, I need to create an application that has to draw points according to specific patterns and it should be done in an animated kind of way. So, I need to delay my drawing. Thanks a lot.

Share this post


Link to post
Share on other sites
Advertisement
Well, inside your app logic you could use some sleep()'s or just keep track of time.

So basically you add a new point to render whenever you feel like it.

Share this post


Link to post
Share on other sites
I think one method that could work in your situation is to use the current time to control a flag for when something is drawn. For example:

// tells when something should ne drawn
int doDraw[10] = {0};
static DWORD last = GetTickCount();

// If one second has passed (1 sec = 1000 ms)
if(GetTickCount() - last >= 1000)
{
static int ctr = 0;
doDraw[ctr] = true;
ctr++;

// Once the anim is complete, reset the anim
if(ctr >= 10)
{
ctr = 0;
for(int x = 0; x < 10; x++)
doDraw[x] = 0;
}
}

// Clear the screen here //

if(doDraw[0])
{
// Draw point 1
}
if(doDraw[1])
{
// Draw point 1
}
...
if(doDraw[9])
{
// Draw point 10
}

// Swap Buffers here //


That's one way to do it, but if you have a lot to do, then it might be too much. You'd have to give more details of what you are doing and what you're working with to give us a better understanding of what would work best for you.

Share this post


Link to post
Share on other sites
make a point class with a Draw() routein and give the class a "delay" member. When the object is created set delay to 0. Then every frame loop through all your points call Draw(). Within draw there should be a test

if(delay < TIME_TO_DRAW)
{
delay++;
return;
}

Now this method will be rather tedious with many points (you have to edit delay for each instance individually but if its just a few then its fine.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
this is my code :

glBegin(GL_POINTS); glColor3f(1.0f,0.0f,0.0f);
Sleep(1000);
glVertex3f( 0.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glEnd();

glTranslatef(3.0f,0.0f,0.0f);
glColor3f(0.5f,0.5f,1.0f);
glBegin(GL_POINTS);
glVertex3f(-1.0f, 1.0f, 0.0f);
Sleep(1000);
glEnd();

glBegin(GL_POINTS);
glVertex3f(2.0f, 0.2f, 0.5f);
Sleep(1000);
glEnd();

glBegin(GL_POINTS);
glVertex3f(1.0f, 0.2f, 0.5f);
Sleep(1000);
glEnd();

the thing is that the points are delayed as they should be, but they are not shown. When I run the program, it begins proccesing and it keeps on doing for 4 seconds and afterwards it displays the window with the points already drawn.
Any clue?

Share this post


Link to post
Share on other sites
Your vertices do not get drawn at the instant you call glVertex(). They get added to internal buffers, processed by the graphics card at it's leisure, and (usually) drawn into an off-screen buffer instead of onto the screen directly. They won't show up until you call wglSwapBuffers(). So if you want to pause to keep them on screen, pause after that call.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement