Jump to content

  • Log In with Google      Sign In   
  • Create Account


Texturing Issue with OpenGL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 bregchel   Members   -  Reputation: 102

Like
0Likes
Like

Posted 29 April 2013 - 01:03 PM

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



Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 7780

Like
0Likes
Like

Posted 29 April 2013 - 01:36 PM

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



#3 dave j   Members   -  Reputation: 581

Like
0Likes
Like

Posted 29 April 2013 - 01:45 PM

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)

#4 bregchel   Members   -  Reputation: 102

Like
0Likes
Like

Posted 29 April 2013 - 04:07 PM

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

 

where do I do that?



#5 Brother Bob   Moderators   -  Reputation: 7780

Like
0Likes
Like

Posted 29 April 2013 - 04:10 PM

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.



#6 mhagain   Crossbones+   -  Reputation: 7431

Like
0Likes
Like

Posted 29 April 2013 - 05:09 PM

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.


It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS