Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


OpenGL confusion


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
6 replies to this topic

#1 xjaspeersx   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 December 2001 - 12:28 AM

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

Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8430

Like
Likes
Like

Posted 13 December 2001 - 12:39 AM

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 sprite

glDisable(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.

#3 xjaspeersx   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 December 2001 - 12:45 AM

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.

#4 Brother Bob   Moderators   -  Reputation: 8430

Like
Likes
Like

Posted 13 December 2001 - 02:37 AM

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)?

#5 xjaspeersx   Members   -  Reputation: 122

Like
Likes
Like

Posted 13 December 2001 - 10:40 AM

It''s completely opaque.

#6 ykarj   Members   -  Reputation: 122

Like
Likes
Like

Posted 14 December 2001 - 02:24 AM

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);
// draw

glDisable(GL_ALPHA_TEST);


is that what you did?

#7 Brother Bob   Moderators   -  Reputation: 8430

Like
Likes
Like

Posted 14 December 2001 - 10:43 AM

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.




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