novice gl question

Started by
6 comments, last by shizik 22 years, 5 months ago
hello, I am trying to create a simple sprite based game and am having a problem my sprites are quads textured with the bitmap of the sprite. I was able to make the black background around the sprite be transparent by: glEnable(GL_TEXTURE_2D); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA,GL_ONE); glBindTexture(GL_TEXTURE_2D, texture[0]); glBegin(GL_QUADS); glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); glDisable(GL_BLEND); now when I compose my scene I want my sprites to be on the foreground and lets say a bunch of points or quads on the background, I have enabled depth-testing, but my background objects are always overwriting my sprites, NO MATTER what their Z position is whats going on?
Advertisement
If I know what you mean, I had this problem a while ago too. The best way of getting around it is to disable Depth Testing, and sort the objects yourself. If you think about it, that method is faster too. Instead of testing for each pixel, you test once per object.

[Resist Windows XP''s Invasive Production Activation Technology!]
I believe what you''ll want to do is draw all of your background objects first, making sure that GL_DEPTH_TEST is enabled.

Then draw your sprites with GL_DEPTH_TEST disables. I believe this will fix your problem.. let me know
neither of these two solutions work

when I set the backgorund to green, it seems that the texture on my sprite is being blended with the background color
why is this happening?

anything I draw seems to superimpose itself over my sprite
even if I draw it before the sprite and behind the sprite

any ideas?
thanks
I would personally use .tga files for sprites cuz of the alpha channel in them and use
glAlphaFunc(GL_GREATER, 0.1f);
glEnable(GL_ALPHA_TEST);
That will make everything that is black (in the alpha channel in the tga file) not appear if ya need more help be glad to help ya.
quote:Original post by shizik
when I set the backgorund to green, it seems that the texture on my sprite is being blended with the background color
why is this happening?

anything I draw seems to superimpose itself over my sprite
even if I draw it before the sprite and behind the sprite

Why didn''t you say that in the first place? That''s different than what I though you meant .

[Resist Windows XP''s Invasive Production Activation Technology!]
I''m just beginning in OpenGL, so correct me if I''m wrong, but can''t you disable blending or use some sort of masking to accomplish your intended effect?

Oh, and how are you guys doing the "quote: HR ''whatever'' HR"? Does this form even support HTML?
Yes this form supports html tags. To make a quote-thingy you write:


Quoted text here

But without spaces within the [ and ] brackets.

Or you can simply click the little "quote"-link in the top-right corner of a post. (clicking the "quote" or "edit" links on a post containing special tags is a good way to see how to write them).

Edited by - Dactylos on October 19, 2001 9:42:00 AM

This topic is closed to new replies.

Advertisement