I'm trying to make a basic 2D engine, and am having problems...I enabled blending using glEnable(GL_BLEND);, set glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);, am loading a TGA that I know has an Alpha bit with some transparency(I exported the transparency bit to a file, and it's there), Texture Mapped the TGA to a quad, then tried to display it over another texture mapped quad...I loaded it last, and the Z is much higher, and I'm in glOrtho, yet there's nothing transparent at all in the quad. It's still just a solid block.

I'm programming in C.
I don't understand why it's not working...though another odd thing is that when I call glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT), and I've used a glColor somewhere in my main loop, the color stays...it doesn't clear it...seriously confusing me. I have set glClearColor... Any ideas? Particularly the first problem. Thanks.

glClearColor doesn't clear the color for function glColor, this function specifies the color for color buffer, that means what is the color of the screen after calling SwapBuffers.

yaro

Finder

04-26-2003, 11:23 AM

Hey,

The glTexImage2D has GL_RGBA...still can't figure it out
Thanks about the info for glColor. http://www.opengl.org/discussion_boards/ubb/smile.gif

shinpaughp

04-26-2003, 04:30 PM

How do you set glOrtho - specifically actual near and far parameters passed to the function and what is the z depth of your textured quad? Just want to make sure you aren't placing the quad outside of the near and far clip planes.

Finder

04-26-2003, 05:14 PM

Looks ok,

glOrtho(0.0,800.0,0.0,600.0,1.0,20.0);
The first textured quad(the background) is at -15.0, and the supposed to be transparent one is at -5

Thanks

shinpaughp

04-26-2003, 07:58 PM

Is the TGA with transaprency in front or in back? And the other textured quad... does it have alpha?

Finder

04-26-2003, 08:02 PM

The TGA with transparency is in front. The background TGA does have alpha, but all of it is set to 1.

Was also curious if it had something to do with the poor fact that I'm running windows? Normal polies work fine blended...just not RGBA textures. I've statically linked the library, so I don't see a problem...but if that is it, is there a way to fix it?

[This message has been edited by Finder (edited 04-26-2003).]

shinpaughp

04-26-2003, 09:59 PM

Very odd.

If you turn off blending can you see it?

Edit:
Also, are you drawing the TGA quad first or last, and do you have depth testing enabled?

[This message has been edited by shinpaughp (edited 04-26-2003).]

Finder

04-26-2003, 10:03 PM

Sure, I can see it...the whole picture that is. Same as with blending on. Just no transparency. http://www.opengl.org/discussion_boards/ubb/frown.gif

the funny thing is that if I set transparency with glColor4f(1.0,1.0,1.0,0.5)...it shows it with transparency. But of course I can't change the individual bits *easily* with this.
Thanks for all of the help...sorry for being a pain. ;-p

Edit:
Yes, the "transparent" quad is drawn last...and I have tried both depth testing enabled and disabled...doesn't seem to make a difference. But normally, it is enabled.

[This message has been edited by Finder (edited 04-26-2003).]

[This message has been edited by Finder (edited 04-26-2003).]

shinpaughp

04-26-2003, 10:14 PM

Oh, you can see the quad, it just isn't transparent??? Try

glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);

Finder

04-26-2003, 10:21 PM

Yep, I can see it. But nothing is transparent.
I did have:
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
and tried the new color one...but no difference. Everything's still opaque.
Sorry for the confusion.

[This message has been edited by Finder (edited 04-26-2003).]

shinpaughp

04-26-2003, 10:31 PM

Could you send me screenshots or post them.

Finder

04-26-2003, 10:37 PM

www.mycgiserver.com/~finder83/screenshot.jpg

It might take a bit of looking to find the image that's supposed to be transparent...it's the little cursor in the cupboard. Btw, I'll delete this image after you view it 'cause it copywritten(used with permission)

shinpaughp

04-26-2003, 10:40 PM

Images usually don't show. If you have a web page, post a link to where the image can be found there or just email them.

And should you just see the black part and the white should be transaprent?

Finder

04-26-2003, 10:52 PM

Yeah, pretty much...it's just supposed to be a hand cursor(will rework the artwork later. ;-p), so the inside part of the hand should be opaque while the outside white should be transparent
Which I've checked time and time again that the Alpha channel was right, and it is...even output its contents to a file and it lined up perfectly. http://www.opengl.org/discussion_boards/ubb/frown.gif

[This message has been edited by Finder (edited 04-26-2003).]

shinpaughp

04-26-2003, 11:26 PM

I think the problem is that OpenGL clamps the resulting fragments between 0 and 1.

edit:

Actually, try

glBlendFunc(GL_SRC_ALPHA, GL_ONE);

That should work as expected. Hope it does. Else I am out of ideas.

Good luck

[This message has been edited by shinpaughp (edited 04-27-2003).]

Finder

04-26-2003, 11:35 PM

nope...same outcome. Going to try and read in the tga so that each bit is between 0 and 1...no idea if it'll work but may be worth a try

shinpaughp

04-26-2003, 11:40 PM

Reread my post. I edited it probably after you read it first time.

I tested it with backgraound alpha = 1.0f and textured quad in front with alpha ranging from 0 to 1. Worked great.

Finder

04-26-2003, 11:41 PM

Ah, that got the black transparent(kinda odd...thought the source was alpha??)

Hehe, have a good night and thanks again! http://www.opengl.org/discussion_boards/ubb/smile.gif

Finder

04-27-2003, 12:53 AM

To wrap this up,

I don't think that the problem was with opengl at all...(cries)...it was with the gimp. Apparently alpha masks and alpha layers are two different things. I retried printing the alpha layer out to a file...and I just got straight 255's across the board! In other words, TGA in gimp isn't handle as RGBA...but rather it simply deletes(??) something else, or has an extension, or something...thanks all for the help! Hopefully if I get a graphics program that handles alpha layers correctly it will fix the problem entirely.