Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: timerfunc

  1. #11
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    I got my stubbed out code to work, I am using the timerFunc() command and the Sleep() command to draw polygons across the top of the screen. thanks for all the help. next I have to incorporate this code into my space invaders game.

  2. #12
    Junior Member Newbie
    Join Date
    Oct 2016
    Posts
    10
    I am posting some code because it might help. all I want to do is draw a bug and then erase it and then draw a second bug in the same place and then erase it. then I want to move the bug to the right and then erase it and then draw a second bug and then erase it as well, I want to draw bugs like in space invaders.
    Code :
    void drawScene_bug()
    {
    	glEnable(GL_TEXTURE_2D);//space ship
    	glBindTexture(GL_TEXTURE_2D, _textureId_three);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
    	for (int i = 0; i <= 17; i++)
    	{
    		glColor3f(1.0f, 1.0f, 1.0f);
    		glBegin(GL_POLYGON);
    		glTexCoord2f(0.0f, 0.0f);
    		glVertex3f(bug[i]+bug_move, 9.0f, 0.0f);
    		glTexCoord2f(1.0f, 0.0f);
    		glVertex3f(bug[i]+bug_move, 10.0f, 0.0f);
    		glTexCoord2f(1.0f, 1.0f);
    		glVertex3f(bug[i + 1]+bug_move, 10.0f, 0.0f);
    		glTexCoord2f(0.0f, 1.0f);
    		glVertex3f(bug[i + 1]+bug_move, 9.0f, 0.0f);
    		glEnd();
    		i++;
    	}
    	glDisable(GL_TEXTURE_2D);
    }
     
    void eraseScene_bug()
    {
    	glEnable(GL_TEXTURE_2D);//space ship
    	glBindTexture(GL_TEXTURE_2D, _textureId_three);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
    	glDisable(GL_TEXTURE_2D);
     
    		for (int i = 0; i <= 17; i++)
    		{
    			glColor3f(0.0f, 0.0f, 0.0f);
    			glBegin(GL_POLYGON);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(bug[i] + bug_move, 9.0f, 0.0f);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex3f(bug[i] + bug_move, 10.0f, 0.0f);
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(bug[i + 1] + bug_move, 10.0f, 0.0f);
    			glTexCoord2f(0.0f, 1.0f);
    			glVertex3f(bug[i + 1] + bug_move, 9.0f, 0.0f);
    			glEnd();
    			i++;
    		}
    }
     
     
    void drawScene_bug_two()
    {
    	glEnable(GL_TEXTURE_2D);//space ship
    	glBindTexture(GL_TEXTURE_2D, _textureId_four);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
    	for (int j = 0; j <= 17; j++)
    	{
    		glColor3f(1.0f, 1.0f, 1.0f);
    		glBegin(GL_POLYGON);
    		glTexCoord2f(0.0f, 0.0f);
    		glVertex3f(bug_one[j] + bug_move, 9.0f + bug_down, 0.0f);
    		glTexCoord2f(1.0f, 0.0f);
    		glVertex3f(bug_one[j] + bug_move, 10.0f + bug_down, 0.0f);
    		glTexCoord2f(1.0f, 1.0f);
    		glVertex3f(bug_one[j + 1] + bug_move, 10.0f + bug_down, 0.0f);
    		glTexCoord2f(0.0f, 1.0f);
    		glVertex3f(bug_one[j + 1] + bug_move, 9.0f + bug_down, 0.0f);
    		glEnd();
    		j++;
    	}
    	glDisable(GL_TEXTURE_2D);
    }
     
    void eraseScene_bug_two()
    {
    	glEnable(GL_TEXTURE_2D);//space ship
    	glBindTexture(GL_TEXTURE_2D, _textureId_four);
     
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
     
    	glDisable(GL_TEXTURE_2D);
     
    		for (int j = 0; j <= 17; j++)
    		{
    			glColor3f(0.0f, 0.0f, 0.0f);
    			glBegin(GL_POLYGON);
    			glTexCoord2f(0.0f, 0.0f);
    			glVertex3f(bug_one[j] + bug_move, 9.0f + bug_down, 0.0f);
    			glTexCoord2f(1.0f, 0.0f);
    			glVertex3f(bug_one[j] + bug_move, 10.0f + bug_down, 0.0f);
    			glTexCoord2f(1.0f, 1.0f);
    			glVertex3f(bug_one[j + 1] + bug_move, 10.0f + bug_down, 0.0f);
    			glTexCoord2f(0.0f, 1.0f);
    			glVertex3f(bug_one[j + 1] + bug_move, 9.0f + bug_down, 0.0f);
    			glEnd();
    			j++;
    		}
    }
    Code :
    void drawScene() {
    	glClear(GL_COLOR_BUFFER_BIT);
    	drawScene_ship();
    	drawScene_bullet();
        drawScene_bug();
    //	Sleep(1000);
    //	eraseScene_bug();
    //	Sleep(1000);
    	drawScene_bug_two();
    //	Sleep(1000);
    //	eraseScene_bug_two();
    //	Sleep(1000);
    	upper_row_one();
    	upper_row_two();
    	upper_row_three();
    	upper_row_four();
    	upper_row_five();
    	upper_row_six();
    	upper_row_seven();
    	upper_row_eight();
    	upper_row_nine();
    	glutSwapBuffers();
    }

Posting Permissions

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