Sign in to follow this  
phil67rpg

rendering bullets in asteroids game

Recommended Posts

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

Share this post


Link to post
Share on other sites
assainator    685
[quote name='phil67rpg' timestamp='1326333572' post='4901860']
[font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff][font=Consolas][size=2][color=#0000ff]void[/color][/size][/font][/color][/size][/font][/color][/size][/font][font=Consolas][size=2][font=Consolas][size=2][color=#000000] RenderBullet()[/color][/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]{[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]glColor3f(0.0f,1.0f,0.0f);[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]glBegin(GL_POINTS);[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]glVertex3f(0.0f,0.5f+k,0.0f);[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]glEnd();[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]k+=0.1f;[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]glutSwapBuffers();[/size][/font][/size][/font]
[font=Consolas][size=2][font=Consolas][size=2]}[/size][/font][/size][/font]
[/quote]
[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
phil67rpg    443
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);[/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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;[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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();[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font]
[font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"][font="Consolas"][size="2"][color="#008000"]glutSwapBuffers();[/color][/size][/font][/color][/size][/font][/color][/size][/font]

Share this post


Link to post
Share on other sites
SimonForsman    7642
[quote name='phil67rpg' timestamp='1326511548' post='4902552']
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);[/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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);[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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;[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/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();[/size][/font][/size][/font][/color][/size][/font][/color][/size][/font][/color][/size][/font]
[font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000][font=Consolas][size=2][color=#008000]glutSwapBuffers();[/color][/size][/font][/color][/size][/font][/color][/size][/font]
[/quote]

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
fastcall22    10840
[url="http://www.opengl.org/resources/libraries/glut/spec3/node21.html"]glutSwapBuffers[/url] 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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this