Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 16, 2009, 02:10 AM   #1
biosopher
macrumors newbie
 
Join Date: Jan 2009
Apple's GLSprite and non-256x256 image

Does anyone know why GLSprite only works with .png of size 256x256?

I have used the GLSprite code unaltered except for swapping the default png with either a 32x32 or 16x16 image. This results in messed up texture mapping. However if I put in any 256x256 images, the textures map properly.

Is this a problem with GLSprite's image loader or do I somehow misunderstand the way texture mapping occurs for images that are not 256x256 pixels?

Thanks,
Anthony
biosopher is offline   0 Reply With Quote
Old Jan 16, 2009, 05:49 AM   #2
CommanderData
macrumors regular
 
Join Date: Dec 2007
OpenGL in general- textures are always a power of two, which means 16x16 and 32x32 are acceptable sizes. I believe you need to study the the GLSprite code more closely to understand your problem...

Just in case you're wondering... I don't see a problem with the loading with my quick read through. My version does retrieve width and height from the spriteImage CGImage. Does yours?

EDIT - one last thought! Are you seeing problems in the Simulator, or on an actual iPhone when you test it???

Last edited by CommanderData; Jan 16, 2009 at 07:03 AM.
CommanderData is offline   0 Reply With Quote
Old Jan 16, 2009, 10:23 AM   #3
biosopher
Thread Starter
macrumors newbie
 
Join Date: Jan 2009
Thanks for the reply.

It's very odd. I've dug thru the code for a couple hours and don't see where the 256 would be 'locked in'. As you say, the width/height seem to be pulled from the image.

Oddly even more, I've been able to use 64x64 & 128x128 images without a problem. It's only the smaller sizes that cause the image corruption.

It's also not an image format problem as I've created my own 64, 128, and 256 png's without a problem.
biosopher is offline   0 Reply With Quote
Old Jan 16, 2009, 11:50 AM   #4
xsmasher
macrumors regular
 
Join Date: Jul 2008
Quote:
Originally Posted by biosopher View Post
I have used the GLSprite code unaltered except for swapping the default png with either a 32x32 or 16x16 image. This results in messed up texture mapping. However if I put in any 256x256 images, the textures map properly.
Yes, I believe there is a problem with smaller images - or maybe just a bug in the GLsprite sample. I got the same result with small images - some transparent portions had garbage in them.

I fixed it by changing the malloc call to a "calloc" call - that clears the memory before the image is loaded. Now my 16x16 sprites look just fine.

Code:
//original call
//spriteData = (GLubyte *) malloc(width * height * 4);
//clear the memory
spriteData = (GLubyte *) calloc(width * height, 4);
Addendum: I guess this is a bug in the GLSprite example. I don't see anything in CGBitmapContextCreate that says it clears the buffer, just that it "creates a context," so I guess we're responsible for clearing the memory before drawing an image with an alpha.

Last edited by xsmasher; Jan 16, 2009 at 12:08 PM. Reason: added my code
xsmasher is offline   0 Reply With Quote
Old Jan 16, 2009, 02:47 PM   #5
CommanderData
macrumors regular
 
Join Date: Dec 2007
xsmasher, that makes sense all right~ great find! If the PNGs did not contain alpha transparent sections he would have never noticed it!

It is odd that this appears more obviously/frequently with smaller images, but maybe that's because the iPhone is able to squeeze that smaller malloc'ed memory into more areas... areas that may be polluted with unused bytes.
CommanderData is offline   0 Reply With Quote
Old Jan 17, 2009, 01:20 PM   #6
biosopher
Thread Starter
macrumors newbie
 
Join Date: Jan 2009
Thanks xsmasher!

That solved the problem. People at Apple's dev forum thought the limit was 64x64 so I'll pass your info on & enlighten them.

discussions.apple.com/thread.jspa?messageID=7621828

Anthony
biosopher is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
Apple TV: Center Image, not Fill -BigMac- Apple TV and Home Theater 3 Apr 19, 2014 10:12 AM
Possible to access Origional image file from texted image? (to view metadata) inck243 iPhone Tips, Help and Troubleshooting 2 Dec 8, 2013 12:47 AM
Apple Preview Image Resize leerkeller Digital Photography 5 Jun 9, 2013 08:21 PM
Apple tv image quality Purakane Apple TV and Home Theater 16 Oct 31, 2012 05:22 AM
French Paris Apple Store protest alters Service Quality to harm Apple image TRONgK Apple, Industry and Internet Discussion 0 Sep 27, 2012 06:43 PM

Forum Jump

All times are GMT -5. The time now is 07:08 PM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC