OpenGL confusion

Started by
5 comments, last by xjaspeersx 22 years, 4 months ago
I just started playing with OpenGL, and I''m getting a little confused. I have a TGA image that I load as a texture, and I basically want to use it as a sprite. I load it as an RGBA texture, and all the alpha values in the texture are set to 255, except the areas I don''t want drawn, in which the alpha values are set to 0. I am calling: glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); and the texture is drawn with no problems, except I can see all the black areas that aren''t supposed to be drawn. I have confirmed there is nothing wrong with the image. I even made it write the RGBA value of each pixel to a text file for the heck of it. But it is still showing those pixels with an alpha value of 0. It seems like I''m doing everything right, so I''m wondering what kind of mistakes I could be making... Here''s my setup: MSVC 6.0 1280x1024x32 display mode VisionTek GeForce3 ti200
Advertisement
Blending in this case is probably not what you want to use. because blending requires readback from the framebuffer, you can fill the memory bandwithd quite fast. Since the pixels in the sprite is either fully visible, or not visible at all, I recomend using alpha test instead. Alpha test will reject fragments based on their alpha value.
  glAlphaFunc(GL_EQUAL, 1);glEnable(GL_ALPHA_TEST);// draw spriteglDisable(GL_ALPHA_TEST);  

This will tell OpenGL to reject all fragments whose alpha value does not equal 1. And this is, as far as I understand, what you want. It doens''t involve blending at all, and can save quite alot of memory bandwidth.
Thanks, appreciate the info. It''s still doing the same thing though. Something''s really wrong I''ll keep looking. Anyone have any ideas, common mistakes?

Thanks again.
Do you mean the black areas are semi-transparent, or completely opaque?

If it''s semi-transparent, you must have blending on, becuause otherwise you can''t get this semi-transparent effect. If it''s completely opaque, it''s probably your texture that doesn''t have proper alpha values.

Or do you mean you can see a black outline in the edge of the sprite (not the edge of the texture, but in the edge between the actual sprite, and the parts that''s not visible)?
It''s completely opaque.
according to what you wrote in your post, your alpha value for visible pixels is 255 so you need:

  glAlphaFunc(GL_EQUAL, 255);glEnable(GL_ALPHA_TEST);// drawglDisable(GL_ALPHA_TEST);  


is that what you did?
glAlphaFunc takes a float as reference. A reference of 255 will be clamped to 1.0f. Whay he meant by 255, was probably the unsigned char value, which is the same as a float value of 1.0.

And if it''s completely opaque, it''s probably wrong with the texture. Are you sure the alpha value of each pixel in the image is set properly? Try set glAlphaFunc(GL_EQUAL, 0) instead. Might be that you set black pixels to 255, and the sprite to 0.

This topic is closed to new replies.

Advertisement