Jump to content
  • Advertisement
Sign in to follow this  

[OGL] PNG to Texture

This topic is 4097 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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
Advertisement
That doesn't seem to be working either. I was doing what it said under the alpha channel section.

Anyone have any other ideas?

Share this post


Link to post
Share on other sites
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!