Jump to content
  • Advertisement
Sign in to follow this  
knobby67

OpenGL Can some opengl flag stop alphafunc working

This topic is 3884 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 all, I've been working on OpenGL code for a few months now all is working fine except for tga transparency. First let me say I totally understand the theory. It's just I can't get it to work with my own code. My guess is I'm setting some flag in screen setup or in my modelloader that won't allow the image to go transparent. My other theory is I used SDl image to load the TGA and that may cause a problem? I'm hoping someone here has experience this. And can give some pointers So when I use glAlphaFunc(GL_GREATER,0.1f); my object totally vanishes when I use glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); the object vanishes when I use glBlendFunc(GL_ONE,GL_ONE_ONE); the whole object goes transparent as if the alpha channel has no masking effect. I know my tga is ok as it's of a net tutorial. So can anyone advise if 1 some opengl flag has an effect 2 sdl image does not load tga correctly (I don't think it's this as I've tried loading with another method) 3 is it possible my mitmap filters have some effect I'm using glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR_MIPMAP_NEAREST ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR ); and glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); gluBuild2DMipmaps( GL_TEXTURE_2D, 3, surface->w, surface->h,GL_RGBA,GL_UNSIGNED_BYTE, surface->pixels ); Thanks in advance this has me totally baffled.

Share this post


Link to post
Share on other sites
Advertisement
I think you might need to change 3 to 4 in gluBuild... like so:


gluBuild2DMipmaps( GL_TEXTURE_2D, 4, surface->w, surface->h, GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );



I've never found an actual explanation of the 1, 2, 3, and 4 options for the internal format parameter, but I'm guessing they correspond to bits per pixel / num channels or something, so 3 would effectively be GL_RGB (or an equivalent one that OpenGL chooses perhaps based on the format of the data you put in), 4 would be GL_RGBA8 or equivalent etc.

After that just using glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) (and not forgetting glEnable(GL_BLEND) as I always do) should work fine.

If that doesn't work it must be something else. :)

Oh, and the default value of GL_TEXTURE_ENV_MODE is GL_MODULATE, so you shouldn't need to change that.

Share this post


Link to post
Share on other sites
thanks tried it and all I get is a totally invisible object. But I must say I have learn something about the 3 4 parameter so thanks :)

Share this post


Link to post
Share on other sites
Putting number as the second parameter to that function (and the glTexImage*() functions) is the old OpenGL1.0 way of doing things, since GL1.1 you could supply GL_RGB, GL_RGBA etc to that parameter to specify the internal format.

And yes, I know the tutorials online don't do that, but that's because tutorials suck and everyone learnt from old tutorials and just never updated their knowledge before making their own equally sucky tutorial [smile]

Share this post


Link to post
Share on other sites
Will Nehe ever get updated? I'm going to stop refering people to that bulldink. All their tutorials use glaux. Some authors fix their tutorials but some never intend to come back to them.

Share this post


Link to post
Share on other sites
is there someway I can test a loaded in texture to see if it has the alpha channel is included in the OpenGL code?

Share this post


Link to post
Share on other sites
Bloody hell solved it, I never use set the GL_COLOR_MATERIAL flag! I use 3ds models which give light/material properties so I never use coloured quads, how come now texture tutorial tells you to set that flag !

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!