Jump to content

  • Log In with Google      Sign In   
  • Create Account

rendering bullets in asteroids game


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 11 January 2012 - 07:59 PM

well I want to draw a single bullet and move it on the screen for an asteroids game
here is the code I am using
void RenderBullet()
{
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.5f+k,0.0f);
glEnd();
k+=0.1f;
glutSwapBuffers();
}

Sponsor:

#2 Sponji   Members   -  Reputation: 1249

Like
0Likes
Like

Posted 12 January 2012 - 01:35 AM

Swap buffers only once after you have drawn everything. Don't do it for every bullet, makes no sense.
Derp

#3 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 12 January 2012 - 04:13 PM

can you post some code

#4 assainator   Members   -  Reputation: 681

Like
1Likes
Like

Posted 13 January 2012 - 09:48 AM

void RenderBullet()
{
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.5f+k,0.0f);
glEnd();
k+=0.1f;
glutSwapBuffers();
}

void RenderFunctionName()
{
	// Prepare OGL scene (clearBufferBit, etc.)

    // Draw scene
    DrawAstroids();
	DrawBullets();

    // Swap buffers
	glutSwapBuffers();
}

"What? It disintegrated. By definition, it cannot be fixed." - Gru - Dispicable me

"Dude, the world is only limited by your imagination" - Me


#5 phil67rpg   Members   -  Reputation: 767

Like
0Likes
Like

Posted 13 January 2012 - 09:25 PM

well I am able to draw a single bullet but then my ships disappears.
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.5f+k,0.0f);
k+=0.1f;
glEnd();
glutSwapBuffers();

#6 SimonForsman   Crossbones+   -  Reputation: 6109

Like
0Likes
Like

Posted 13 January 2012 - 10:34 PM

well I am able to draw a single bullet but then my ships disappears.
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0f,1.0f,0.0f);
glBegin(GL_POINTS);
glVertex3f(0.0f,0.5f+k,0.0f);
k+=0.1f;
glEnd();
glutSwapBuffers();


Don't swap the buffers after drawing the bullet, only swap buffers at the end of each frame.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!

#7 phil67rpg   Members   -  Reputation: 767

Like
-1Likes
Like

Posted 13 January 2012 - 11:31 PM

what do you mean by frame

#8 fastcall22   Crossbones+   -  Reputation: 4332

Like
0Likes
Like

Posted 14 January 2012 - 12:49 AM

glutSwapBuffers presents the frame (the rendered image) to the display device. Assisnator's code should hint that for each frame, you should clear the buffer before drawing, and present the buffer after drawing. Your code and the problems you're describing suggest you are mixing quite a few of these within drawing a scene.
c3RhdGljIGNoYXIgeW91cl9tb21bMVVMTCA8PCA2NF07CnNwcmludGYoeW91cl9tb20sICJpcyBmYXQiKTs=




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS