• Advertisement
Sign in to follow this  

rendering bullets in asteroids game

This topic is 2200 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]void[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"][color="#000000"] RenderBullet()[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]{[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glColor3f(0.0f,1.0f,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glBegin(GL_POINTS);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,0.5f+k,0.0f);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glEnd();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]k+=0.1f;[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]glutSwapBuffers();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]}[/font][/font]

Share this post


Link to post
Share on other sites
Advertisement

[font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]void[/font][/font][/font][font=Consolas][size=2][font=Consolas][size=2][color=#000000] RenderBullet()[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]{[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]glColor3f(0.0f,1.0f,0.0f);[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]glBegin(GL_POINTS);[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]glVertex3f(0.0f,0.5f+k,0.0f);[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]glEnd();[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]k+=0.1f;[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]glutSwapBuffers();[/font][/font]
[font=Consolas][size=2][font=Consolas][size=2]}[/font][/font]

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

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

// Swap buffers
glutSwapBuffers();
}
[/source]

Share this post


Link to post
Share on other sites
well I am able to draw a single bullet but then my ships disappears.
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]glClear(GL_COLOR_BUFFER_BIT);[/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][font="Consolas"][size="2"]glColor3f(0.0f,1.0f,0.0f);[/font][/font][/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][font="Consolas"][size="2"]glBegin(GL_POINTS);[/font][/font][/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][font="Consolas"][size="2"]glVertex3f(0.0f,0.5f+k,0.0f);[/font][/font][/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][font="Consolas"][size="2"]k+=0.1f;[/font][/font][/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][font="Consolas"][size="2"]glEnd();[/font][/font][/font][/font][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]glutSwapBuffers();[/font][/font][/font]

Share this post


Link to post
Share on other sites

well I am able to draw a single bullet but then my ships disappears.
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000]glClear(GL_COLOR_BUFFER_BIT);[/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][font=Consolas][size=2]glColor3f(0.0f,1.0f,0.0f);[/font][/font][/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][font=Consolas][size=2]glBegin(GL_POINTS);[/font][/font][/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][font=Consolas][size=2]glVertex3f(0.0f,0.5f+k,0.0f);[/font][/font][/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][font=Consolas][size=2]k+=0.1f;[/font][/font][/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][font=Consolas][size=2]glEnd();[/font][/font][/font][/font][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000]glutSwapBuffers();[/font][/font][/font]


Don't swap the buffers after drawing the bullet, only swap buffers at the end of each frame.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement