Skip to main content
gamedev.net
🔒 Locked

Functioncall in time Intervall

Started by Teejay Nov 7, 2011 at 9:57 PM 0 replies 550+ views
Original Post
Teejay
Teejay
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;
}

Topic Locked

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

Sign in to reply to this topic.