Advertisement

Please help a new guy.

Started by September 25, 2002 11:21 AM
16 comments, last by LostBoy 22 years, 5 months ago
Here''s my situation. I am creating a mini golf game, in which a sphere is used as the ball, and the course is a loaded bitmap. Problem is, I can''t for the life of me keep the bitmap texture from appearing on my ball ! I have tried specifying a color for the ball and that didn''t work(what it gave me was whatever color I specified AND the texture). My second approach was to load two textures, one for the course and one for the ball, and then bind the textures to their respective objects. Well as you guesed, I was unsuccessful. Somehow only one of the textures made it through that proccess.Of course I realize that I am doing something wrong. I can''t find a tutorial on my level that explains how to do this. The first tut that has a texture surface and objects with different textures is NEHE #32 I think, but it uses TGA files and I know nothing about them. I am trying to stick with simple things for my learning process. I am definitely missing something here, and would be very greatful to whoever enlightens me. In fact, I would not doubt that I am doing things the hard way, being that I am new to Opengl. All that I am really trying to accomplish is having a bitmap as my course, and a ball of a red or white color.Then I will make the ball move. Then provide collision detection (ball bouncing off of walls and such). Then a nifty user interface which makes the game fun. BTW, I am keeping things 2D as far as the course go''s. I didn''t want to be too ambitious on my first attempt. Any input is much appreciated. JC
glDisable(GL_TEXTURE_2D);
Advertisement
If your ball is NOT textured, then all you have to do is calling glEnable(GL_TEXTURE_2D) before you render your course and call glDisable(GL_TEXTURE_2D) after, something like :

...
glEnable(GL_TEXTURE_2D);
render_course();
glDisable(GL_TEXTURE_2D);
render_ball();
...

hope this helps
1.
When GL_TEXTURE_2D is enabled, all objects you draw are textured with the last texture you binded with glBindTexture.

...
glEnable(GL_TEXTURE_2D); // Enable 2D Texturing
glBindTexture(tex1); // Bind the first texture
DrawObject1(); // Draw the object
glBindTexture(tex2); // Bind the second texture
DrawObject2(); // Draw another object
...


2.
If GL_TEXTURE_2D is not enabled, all objects should be untextured.


...
glEnable(GL_TEXTURE_2D); // Enable 2D Texturing
glBindTexture(tex1); // Bind the first texture
DrawObject1(); // Draw the object
glDisable(GL_TEXTURE_2D); // Disable 2D Texturing
DrawObject2(); // Draw untextured object
...


I hope this will help.

PM

[edited by - PM on September 25, 2002 12:36:55 PM]
PM Times change... Excuse my poor english!
Thanks for all of the help everyone ! But unfortunately I'm still having problems. Maybe my computer is posessed. Or maybe I'm just a dummy (probably the last case).

Here's my code (which still isn't working).

int DrawGLScene(GLvoid)

{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(-3.0f,0.0f,-3.5f);
glTranslatef(3.0f,0.0f,0.0f);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS);

//Texture and quad coordinates
glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f);
glDisable(GL_TEXTURE_2D);
glEnd(); *----- < Do I need this ?>

glColor3f(1.0f,0.0f,0.0f);
gluSphere(quadratic,0.035f,32,32); glColor3f(1.0f,1.0f,1.0f);
glColor3f(1.0f,1.0f,1.0f);
glEnd();



return TRUE;
}

[edited by - LostBoy on September 25, 2002 1:01:29 PM]
Whoops ! It doesn''t look very readable. Don''t know what happened. Sorry.
Advertisement
glDisable may NOT be called in glBegin();...glEnd(); block!!!

PM
PM Times change... Excuse my poor english!

    int DrawGLScene(GLvoid) {glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(-3.0f,0.0f,-3.5f); glTranslatef(3.0f,0.0f,0.0f); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); //Texture and quad coordinatesglTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glDisable(GL_TEXTURE_2D); glEnd(); *----- < Do I need this ?> glColor3f(1.0f,0.0f,0.0f);gluSphere(quadratic,0.035f,32,32); glColor3f(1.0f,1.0f,1.0f);glColor3f(1.0f,1.0f,1.0f);glEnd();return TRUE; }     


better?

wish i could REALLY help you but i'm still doing 2D games

question? if you are returning "TRUE" then shouldn't your function be: bool DrawGLScene (void) ?
or you just letting the compiler do a implicit cast for you, which would make TRUE into 1?

[edited by - Alpha_ProgDes on September 25, 2002 1:04:36 PM]

Beginner in Game Development?  Read here. And read here.

 

TRUE, FALSE are BOOL.
BOOL is defined like
#define BOOL int
or something like that.
BOOL is a 32-bit number.
PM Times change... Excuse my poor english!
Yeah!!!!!!!!!!!!!!!

It''s fixed ! Thanks a ton everyone. I spent hours on this problem alone.

JC

This topic is closed to new replies.

Advertisement