Loading Textures in OpenGL using libpng - Printable Version
+- iDevGames Forums (http://www.idevgames.com/forums)
+-- Forum: Development Zone (/forum-3.html)
+--- Forum: Game Programming Fundamentals (/forum-7.html)
+--- Thread: Loading Textures in OpenGL using libpng (/thread-4425.html)
Loading Textures in OpenGL using libpng - Taxxodium - Mar 21, 2006 04:28 AM
I found an interesting article that shows how you can read a PNG file with libpng and use it as an OpenGL texture. I'm gonna give it a try on my upcoming game.
Here's the link: http://www.macdevcenter.com/pub/a/mac/2005/10/14/texture-maps.html?page=2
Loading Textures in OpenGL using libpng - OneSadCookie - Mar 21, 2006 05:09 AM
I believe it'll just crash for anything other than a 24-bit true-color PNG. Feel free to try it, but make sure you test it with 32-bit PNGs, 8-bit indexed PNGs, etc.
should be safe, though it's perhaps a little more complex than you generally want.
Loading Textures in OpenGL using libpng - djohnson - Apr 3, 2006 01:13 PM
Does anyone have a simple tutorial that shows how to tie this all together? I have done the following, but only see a white quad...
Here is the draw function:
It will draw a quad at the correct spot just as it should. However, it will NOT display the texture. I have tried using glIsTexture(texName) and it always shows GL_FALSE. Any ideas?
edit: I know textures are working b/c my text is displaying correctly and it is formed from text->textures.
update: After further inspection, it seems that the function, load_png_image, is not correctly loading the data for the image. When I get back to work tomorrow, I will see if I can figure out what is going on with the data part of the Image struct. OSC, since it is your code, any specific ideas on why it would be returning the width, height, bit_depth, color_type, but not the data?
Loading Textures in OpenGL using libpng - djohnson - Apr 4, 2006 01:08 PM
Each day brings me one step closer to figuring this out...
This, when added to the Nehe Lesson 6 tutorial, produces a very nice .png textured quad to appear on my screen. However, the exact same code will not work in my project. I figured I was creating the OpenGLView incorrectly, but it is setup the same. I will continue to work on my base code and see why it is not work. Thanks for the png code OSC.
Loading Textures in OpenGL using libpng - Taxxodium - Apr 4, 2006 01:13 PM
You either use libpng or NSBitmapImageRep, not both, that's just asking for trouble. If you use NSBitmap, which is not recommended, you don't need to call libpng to load the png file as an openGL texture.
Loading Textures in OpenGL using libpng - djohnson - Apr 4, 2006 01:49 PM
Yeah, I am just using libpng now. I was only using some old bitmap code to see why my quad wasnt being textured.
Guess what? After waking up, I noticed I was calling my setup code before the OpenGL context was active.
Loading Textures in OpenGL using libpng - ThemsAllTook - Apr 4, 2006 04:19 PM
Taxxodium Wrote:If you use NSBitmap, which is not recommendedI've recently discovered a 100% safe way to use NSBitmapImageRep:
Loading Textures in OpenGL using libpng - OneSadCookie - Apr 4, 2006 06:03 PM
Of course, that copies the image data behind the scenes, which is inefficient, and should probably be avoided if at all possible...
Loading Textures in OpenGL using libpng - ThemsAllTook - Apr 4, 2006 09:18 PM
Yes, there's of course a tradeoff between speed and certainty of your image format. I suppose you could check the NSBitmapImageRep's format before calling that function, and if it's already in a usable state, use its bitmapData directly. I have no idea how often that would be the case, though.
Loading Textures in OpenGL using libpng - glMatt - Apr 4, 2006 09:21 PM
Wouldn't know if this is what you are looking for...