Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Oluf

How to make a ball?

This topic is 5219 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

hey...I am in the middel of making a pong game and its going ok..just untill i reached the part where I had to make the ball I go no idea how to do this..make a black box and texture it with a round ball or? I have looked a bit at the forum to see if I could find anyone else who had this prob and it seemed there was however i didnt find any help on what i need I am use openGL to this...any help would be great

Share this post


Link to post
Share on other sites
Advertisement
Make a transparent box with round ball on it would be fine. Probably the best and maybe the only real solution. Sure you could make a ten thousand polygons to create a circle, but that would be terribly slow (for a pong game). Use your alpha channel and the power of textures (tga, if you have one more question).

Oxyd

- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
thanks a lot...might have to ask about that aplha channel but i will try and see if i can figure it out

thank you

Share this post


Link to post
Share on other sites
looks like I am going to need more help with this

I followed the nehe texture tutorial and did 100% as it said
The only thing where I did not follow what was said was when applying the texture (they are useing a 3d shape where i only got a 2d)
Now, the weird thing is that my colors are weird, before I put in the texture code my 2 bars (those 2 that have to go up and down and hit the ball) where red, now I simply cant see them!
I tryed changing the background color and then I could see the 2 bars perfetly well(however they were black and not red as i told them to be)

Oh..and one of the worst things is...no texture on my small quad either

-----------

glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);
glColor3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);

glEnd();

Share this post


Link to post
Share on other sites
Have you enabled the texturing using glEnable?

Oxyd

- Unreadable code is code written on a piece of paper, but not the one, in which the programmer is using a space in the place you don''t.
- Real programmers aren''t afraid of goto

Share this post


Link to post
Share on other sites
"glEnable(GL_TEXTURE_2D);"
In InitGL...

if that is what you mean then yes

Share this post


Link to post
Share on other sites
You need to enable and disable textures at the right time. Enable with glEnable(GL_TEXTURE_2D) and disable with glDisable(GL_TEXTURE_2D). The reason your paddles aren't showing up correctly is because textures are enabled and the paddles don't have texture coordinates, so it tries to supply the colour from the texture but can't so it just uses black. At least I think that's how it works...

Regardless, just make sure you enable textures just before drawing the ball and disable them just after.

EDIT: Your texture coordinates seem a little weird. I don't know if you have to follow clockwise/counter-clockwise ordering with texture coordinates but even if you don't, the fact you have them in that weird order is likely the cause of no texture showing up on the ball.

So try this:


glEnable (GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]);
glBegin(GL_QUADS);

glColor3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f);
glVertex3f(-0.5f, 0.5f, 0.0f);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, 0.5f, 0.0f);
glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f);
glVertex3f(-0.5f, 0.0f, 0.0f);

glEnd();
glDiable (GL_TEXTURE_2D);


-Auron

[edited by - Auron on June 5, 2004 12:28:43 PM]

Share this post


Link to post
Share on other sites
ah I see

Well my colors are back to normal now...however I still dont got any texture

Share this post


Link to post
Share on other sites
Nevermind my last post...it works! thanks a lot people!

(i had to removed the glColor() of cuase heh)

Share this post


Link to post
Share on other sites
Looks like I once again need some help (would be much more fun if I could figure it out myself..)

Could anyone give me some tips on how I should move the ball? like I got it right now the points for the ball is made like this :

glVertex3f(ballLTX, ballLTY, 0.0f)

So I can move all 4 points both up and down, however when I try and say "ballLTX+=0.2f; " my program crashes (no compiler error or anything)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!