Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

rendering bullets in asteroids game

4: Adsense

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   

407
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();
}

#2 Sponji   Members   

2422
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   

407
Like
0Likes
Like

Posted 12 January 2012 - 04:13 PM

can you post some code

#4 assainator   Members   

685
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   

407
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   Members   

7633
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   

407
Like
-1Likes
Like

Posted 13 January 2012 - 11:31 PM

what do you mean by frame

#8 fastcall22   Moderators   

10700
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.
zlib: eJzVVLsSAiEQ6/1qCwoK i7PxA/2S2zMOZljYB1TO ZG7OhUtiduH9egZQCJH9 KcJyo4Wq9t0/RXkKmjx+ cgU4FIMWHhKCU+o/Nx2R LEPgQWLtnfcErbiEl0u4 0UrMghhZewgYcptoEF42 YMj+Z1kg+bVvqxhyo17h nUf+h4b2W4bR4XO01TJ7 qFNzA7jjbxyL71Avh6Tv odnFk4hnxxAf4w6496Kd OgH7/RxC




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.