Jump to content
  • Advertisement
Sign in to follow this  
bregchel

OpenGL Texturing Issue with OpenGL

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

Hi, 

 

I'm working with opengl texturing in 2D, but I need help :) first of all, I'm new at OpenGL, so try not to be so technical in your explanation, i will thank you so much :)

 

To explain my problem, look at this picture:

 

texturing.png

 

as you can see, the ship and the asteroids are quads textured, but i want to "not print" the "black" parts of the quads.

I try to use BLENDING, and although the black parts disappear, the colors blend with the background.

 

 

This is how i am blending

 

 

glMatrixMode(GL_MODELVIEW);
glPushMatrix(); // guardamos la matriz actual
glTranslatef(centro.x, centro.y, 0.0);
glRotatef(theta, 0.0, 0.0, 1.0);
glTranslatef(-centro.x, -centro.y, 0.0);
 
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glBindTexture(GL_TEXTURE_2D, texture.TexName());
 
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
 
glColor3f(1.0, 1.0, 1.0);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(centro.x - dx, centro.y + dy, 0.0);
glTexCoord2f(0.0, 1.0); glVertex3f(centro.x + dx, centro.y + dy, 0.0);
glTexCoord2f(1.0, 1.0); glVertex3f(centro.x + dx, centro.y - dy, 0.0);
glTexCoord2f(1.0, 0.0); glVertex3f(centro.x - dx, centro.y - dy, 0.0);
glEnd();
 
glDisable(GL_BLEND);
glDisable(GL_TEXTURE_2D);
glPopMatrix(); // restablecemos la matriz original
 

 

Any ideas?

Thank you!!

Share this post


Link to post
Share on other sites
Advertisement
It looks like your ship and asteroid textures aren't defined with an alpha channels to define the transparent bits. Wikipedia article on alpha compositing which explains the idea. Search for creating alpha channels in your preferred bitmap editor for how to do it. You'll need to change your texture bits to load an RGBA texture (not just an RGB one).

When you've got that sorted out, change you blend func to glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA). The first value is how much of the source texture to use, the second is now much of the background is used. So when a pixel's alpha is one, all the source will be used and none of the background. When it's zero, none of the source and all of the background. If a pixels alpha is 0.5, half of each will be used. It calculates the colour as:

final colour = src colour * src alpha + dst colour * (1 - src alpha)

Share this post


Link to post
Share on other sites

Is the alpha channel of the texture properly defined to mask out the unwanted areas of the sprites?

 

where do I do that?

Share this post


Link to post
Share on other sites

Your paint program can probably add an alpha channel to your image. Unless you're using color keying, the alpha channel has to be in the image to begin with.

Share this post


Link to post
Share on other sites

And make sure that you load with an internal format of GL_RGBA (GL_RGBA8 if using modern OpenGL) otherwise you'll lose that alpha channel when you create a texture from the image.

Share this post


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

  • 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!