# [SOLVED] [SDL] PNG Transparency with OpenGL?

## Recommended Posts

ShinkaFudan    100

##### Share on other sites
Jack Sotac    528
To clarify, is the problem that the terrain disappears or that the png image isn't being displayed with transparent areas.

Are you using Windows or Linux?

Have you tried disabling blending when drawing the map terrain.

Here's what I'm getting.

##### Share on other sites
ShinkaFudan    100
That's what you get when you run it? It's working for you... strange.

I'm using Windows...

To clarify, the problem is that the part that is transparent in your image is not in mine. It's just black. Now that I see it working for you, I'm a bit more confused. At least I know it's not technically a problem with my code.

Did you change anything to get that result? The uploaded project had glBlendFunc and glAlphaFunc commented out... Did you uncomment them? (As mentioned, for me this just makes everything disappear)

This is what I see:

[FILE REMOVED DUE TO PROBLEM BEING SOLVED]

and from another angle (W,A,S,D,Q,E, and the arrow keys move the camera)

[FILE REMOVED DUE TO PROBLEM BEING SOLVED]

[Edited by - ShinkaFudan on February 1, 2009 11:18:07 PM]

##### Share on other sites
ShinkaFudan    100
You must have changed something. I had someone else test it and they had a black part as well. Could you please tell me what you changed?

Or, if you didn't change anything, could you tell me what graphics card you have? Perhaps it is a hardware issue. The only people I can find to test this have nVidia cards, which is what I have as well as the person I had test it earlier with the same result as me.

[Edited by - ShinkaFudan on December 17, 2008 9:28:35 AM]

##### Share on other sites
Jack Sotac    528
Yeah I had to change some things to get it to run. For instance, I linked to the prebuilt SDL_image library instead of compiling it(likely has nothing to do with the problem). Also I un-commented the glBlendFunc() but left the glAlphaFunc() commented out. I'd also replaced image->pixels with surface->pixels in convert_surface(). This got things working which pointed me to a problem with convert_surface().

In any case, I think I've managed to get it back to where you were having the problem. Try these things before doing the blit.

SDL_Surface *image = SDL_CreateRGBSurface( SDL_SWSURFACE, w, h, 32, BMASK, GMASK, RMASK, AMASK );

I haven't checked, but mostly likely the value Amask you got from the main video surface is zero which messes up things when you really do need to create a surface with an alpha channel.

Also turn off the SRC_ALPHA flag on the source surface when you want to do direct copy blits.
SDL_SetAlpha(surface,0,0);
This allows all the alpha values from the source surface to be copied to the destination surface during blitting.

Lookup SDL_SetAlpha() and SDL_BlitSurface() in SDL's docwiki and you can see why RGBA blits to RGBA surfaces have a few gotchas(it's bitten me more than a few times).

In conclusion ,it looks like the alpha values weren't being copied to the texture surface so that was why nothing was showing up when the alpha blending mode was set.

Let me know if that fixes things. Good Luck.

btw, I'm using WindowsXP with an Nvidia card also

##### Share on other sites
ShinkaFudan    100
It seems that above all, it was that I had left out

SDL_SetAlpha(surface, 0, 0);

from the convert. I altered the rest as well, as those changes all seem to make sense. I'm a bit lost in the guide for those functions but I think I understand what the problem was. In any case, it's working great now.

Thank you so much for your help. (+rating)

##### Share on other sites
zer0sum    100
Quote:

Hi. I have a very similar problem and I'm trying to figure out where I went wrong.

Can I ask what blending you used in glBLendFunc to make this work?

Also, where and why did you use SDL_SetAlpha to make your conversion work?