Jump to content
  • Advertisement
Sign in to follow this  
Teejay

OpenGL Functioncall in time Intervall

This topic is 2539 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 want to call a Function, that a draws a random point onto the screen, in a special time intervall. For example after 10s for 5secs. After further 10s again...(or as long as score ist between 2 and 4 for example)
Is there any special function in OpenGL?
I can post my Code to see the problem:
glutTimerFunc(value, timer, value)
calls
glutDisplayFunc(drawScene);
in void drawScene(void):
glPointSize(20);
if (score==2) {
glBegin(GL_POINTS);
glVertex2f(randomnumber(), 0.2);
glEnd();
}
is responsible for the points. The problem is, that it draws the point, when the score is 2, but after 10ms he is drawing it on another position and so on...

Here my complete code:
I skipped uninmportant parts, so if you need them, just ask.

int main(int argc, char **argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA);
glutInitWindowPosition(100,100);
glutInitWindowSize(HEIGHT, WIDTH);
glutCreateWindow("Breakout The Game");
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluOrtho2D(0,WIDTH,HEIGHT,0);
glutDisplayFunc(drawScene);
glutSpecialFunc(Steuerung);
glutKeyboardFunc(Keypress);
berechneWinkel(vBallx, vBally, Winkel);
glutTimerFunc(10, timer, 0);
glutMainLoop();
return 1;
}

void timer(int value)
{
posx+=vBallx;
posy+=vBally;
kollision_wand(posx, posy);
kollision_board(posx, posy, moveX);
kollision_bricks(posx,posy);
if (posy<=-1)
{
reset();
}
glutPostRedisplay();
if (pause==1)
{
glutTimerFunc(value, timer, value);
}
}

void drawScene(void)
{
glPointSize(20);
if (score==2) {
glBegin(GL_POINTS);
glVertex2f(randomnumber(), 0.2);
glEnd();
}
glutSwapBuffers();
}

float randomnumber(void)
{
int randomnumber;
float itemx;
srand((unsigned int)time(NULL));
randomnumber = rand() % 190 -95;
itemx=randomnumber/100.0; //vorsicht -0.95 bis 0.94 ist der Bereich
return itemx;
}

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!