Skip to main content
GameDev.net gamedev.net
🔒 Locked

drawing lines incrementely

Started by tylerbingham Dec 11, 2002 at 12:02 AM 0 replies 250+ views
Original Post
tylerbingham
tylerbingham
I have this problem. I want to use GL_LINES to draw a screen saver pattern, but I can''t figure out how to do this without a for statement with calls to glVertex: glBegin(GL_LINES); glColor3d(r,g,b); for(float j=-10;j<10;j+=0.5f) { glVertex2f(0,0); glVertex2f(j,-6); } glEnd(); I want "j" to increment over time not all at once. I have tried this: static float j=-10; glBegin(GL_LINES); glColor3d(r,g,b); glVertex2f(0,0); glVertex2f(j,-6); glEnd(); j+=0.1f; but it doesn''t work. I kinda want the lines to draw every 2 or 3 seconds, maybe I should use a timer?? A timer seems like a waste of system resources for something so simple, though.
lc_overlord
lc_overlord
Use a while loop and a timer.
the timer is a lifesaver when it comes to running programs at a custom speed.

let's say you want to add a bar every 0.5 seconds

t=0 and k=-10 is a float
timer is a float containing time lapsed since the last frame(or 1/fps)


    
t=t+timer;
while (t>0.5) {t=t-0.5f; k=k+0.5f;}
glBegin(GL_LINES);
glColor3d(r,g,b);
for(float j=-10;j<k;j+=0.5f)
{
glVertex2f(0,0);
glVertex2f(j,-6);
}
glEnd();


Run this for every frame.
The for loop can be replaced with a while loop if it causes problems.

[edited by - lc_overlord on December 11, 2002 9:04:32 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.