Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: glutTimerFunc problem

  1. #1
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    118

    glutTimerFunc problem

    Code :
    void collision(int v)
    {
    	collision_bug_one(0.0f, 10.0f);
    	glutPostRedisplay();
    	glutTimerFunc(1000, collision, 0);
    }
     
    void coll_sprite()
    {
    	if (board[0][0] == 1)
    	{
    		collision(0);
    		flag[0][0] = 1;
    	}
    }
     
    void erase_sprite()
    {
    	if (flag[0][0] == 1)
    	{
    		glColor3f(0.0f, 0.0f, 0.0f);
    		glBegin(GL_POLYGON);
    		glVertex3f(0.0f, 10.0f, 0.0f);
    		glVertex3f(0.0f, 9.0f, 0.0f);
    		glVertex3f(1.0f, 9.0f, 0.0f);
    		glVertex3f(1.0f, 10.0f, 0.0f);
    		glEnd();
    	}
    }
    I am using glutTimerFunc to wait a small amount of time to display a collision sprite before I black out the sprite. unfortunately my code only blacks out the said sprite without drawing the collision sprite, I have done a great deal of research on the glutTimerFunc and animation.

  2. #2
    Junior Member Regular Contributor
    Join Date
    Jan 2013
    Posts
    118
    well I have made some progress
    Code :
    void collision(int value)
    {
    	if (value >= 0)
    	{
    		if ((value % 2) == 0)
    		{
    			collision_bug_one(0.0f, 10.0f);
    			glutPostRedisplay();
    			glutTimerFunc(1000, collision, value--);
    		}
    		else
    		{
    			collision_bug_one(0.0f, 10.0f);
    			glutPostRedisplay();
    			glutTimerFunc(1000, collision, value--);
    		}
    		cout << value << endl;
    	}
    }
     
    void coll_bug_one()
    {
    	float x = -0.5f + scroll;
    	float y = -8.0f + up;
    	float oWidth = 0.5f;
    	float oHeight = 0.5f;
     
    	float xTwo = 0.0f;
    	float yTwo = 9.0f;
    	float oTwoWidth = 0.5f;
    	float oTwoHeight = 0.5f;
     
    	if (checkCollide(x, y, oWidth, oHeight, xTwo, yTwo, oTwoWidth, oTwoHeight) == 1)
    	{
    		glutTimerFunc(1000, collision, 5);
    		board[0][0] = 1;
    	}
    }
    I just need a little help.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •