Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem using opengl for 2d

Started by Squirrelion May 5, 2004 at 12:19 PM 2 replies 750+ views
Original Post
Squirrelion
Squirrelion
I''m trying to draw 2d images onto the screen with parts of it 100% opaque and parts completely transparent. My boring work might have made me stupid or something, but I just can''t solve this problem by myself: when I draw a quad with a texture, it either draws alpha(meaning alpha=0) as black or blends the image with the background. Here''s what I have: -An png image with an alpha channel -A "loadtexture" function that should take use of tha alpha value -glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); (according to googling, this should work) I''ve tried glBlendFunc with several different parameter combinations. I''m using sdl to load the texture images(and other stuff that are highly irrelevant)
EricDB
EricDB
Try this (it''s cut from my Python code, but OpenGL is OpenGL so you should get the idea):

glDepthMask(False)
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
glBindTexture(GL_TEXTURE_2D, self.id)

<...do some quads...>

glEnable(GL_BLEND)
glDepthMask(True)


The good news is that you''re not limited to 100% opaque or transparent. The entire range of your PNG''s alpha channel is at your disposal.

The bad news...hm, I can''t think of any. OpenGL for 2D rocks! :-)
Squirrelion
Squirrelion
nope... That''s practically identical to my code...
it still leaves the bits with alpha value 0 to black.

EricDB
EricDB
Well, hmm...maybe the problem is getting the correct RGBA data into OpenGL then. Since my code uses the pygame library, which uses SDL for that, I''m not sure I can help you there...but that''s probably where you should be looking.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.