How to make a ball?

Started by
10 comments, last by Oluf 19 years, 10 months ago
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
Its all a matter of will power
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
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
Its all a matter of will power
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();
Its all a matter of will power
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
"glEnable(GL_TEXTURE_2D);"
In InitGL...

if that is what you mean then yes
Its all a matter of will power
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]
ah I see

Well my colors are back to normal now...however I still dont got any texture
Its all a matter of will power
Nevermind my last post...it works! thanks a lot people!

(i had to removed the glColor() of cuase heh)
Its all a matter of will power
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)
Its all a matter of will power

This topic is closed to new replies.

Advertisement