Sign in to follow this  
Uphoreum

[OGL] PNG to Texture

Recommended Posts

Uphoreum    216
I've got bitmap loading/drawing working perfectly, but now I want to be able to load a PNG file. I'm using SDL_image to load the PNG. I stored it in an SDL_Surface*, like I did with the bitmap, but when I draw it, it comes out as a distorted mess. I'm guessing the parameters I sent to glTexImage2D are causing it to read it as though it did not have an alpha channel. Here's what I'm doing right now: glTexImage2D( GL_TEXTURE_2D, 0, 3, surface->w, surface->h, 0, GL_BGR, GL_UNSIGNED_BYTE, surface->pixels ); I also tried substituting GL_BGRA in, and I can see my image, but it's not proportional, and it's not transparent. The image is 32*32 pixels, so power of 2 is not a problem (unless my math is wrong, which it could be). I remember having an issue like this with another API because of filtering. Here are my filtering lines: glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); Thanks!

Share this post


Link to post
Share on other sites
Uphoreum    216
Nevermind, I figured it out.

I had to change the glTexImage2D line to:

glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, surface->w, surface->h, 0,
GL_RGBA, GL_UNSIGNED_BYTE, surface->pixels );

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this