SOIL image library problem or texture lib problem

Apprentice
Posts: 6
Joined: 2010.03
Post: #1
Hi folks,

I am looking for an opengl texture loader for iphone that is fast, and can handle 8 bit pngs with alpha and without alpha.

The supplied code in the glsprite example works well but will crash out if I try an 8 bit png without alpha. It sometimes works with alpha. I've tried a lot of different code and had enough. Time to get a library that will do the work for me.

To this end I spent 2 days trying to get http://lonesock.net/soil.html SOIL working on iphone but it just won't work.

I include the .a file as a framework and include the SOIL.h file but I keep getting object errors when compiling.

If anyone knows the answer I would really appreciate a step by step example of how to get SOIL running.

Or perhaps you have a reliable library for iphone which can handle all forms of PNGs - that would work too, please post links or examples.

Thanks guys, my hair is running out!
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #2
I had a problem with SOIL too, but it's all working now. I asked a similar question a while back, it may be the same problem:

http://www.idevgames.com/forum/showthrea...OIL&page=3

~ Bring a Pen ~
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2010.03
Post: #3
Hi mikey thanks for the heads up.

I would like to thank AnotherJake for all his effort in helping you. He helped me so much. The crux of the problem was I was using the existing .a file. With AnotherJake's tutorial I was able to compile a new .a file (I had to mess around making a few folders so it wouldn't crash) - I now have it compiling and working.


Thanks guys!
Quote this message in a reply
Member
Posts: 281
Joined: 2009.04
Post: #4
No problem. Thanks to AnotherJake!

~ Bring a Pen ~
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2010.03
Post: #5
OH NO


big problem... it isn't working on the actual device! throws up an error. Does this mean I have to somehow build an .a file for arm cpus?
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2010.03
Post: #6
I have managed to get SOIL compiling natively in xcode instead of using .a files. I had to include

#import <OpenGLES/EAGLDrawable.h>
#import <QuartzCore/QuartzCore.h>
#import "EAGLView.h"

At the top of SOIL.c (I renamed c files to m though, not sure if that was worthwhile).

And then I uncommented/commented the CLAMP vars lower in the source (you'll get two errors).

However I'm seeing that SOIL does not load pngs which are less than 8 bit. ie 128 colour or whatever. All PNGs work regardless of bit depth in simulator though.

I am just going to stick with 256 colour pngs I guess. Thats a good file saving at least.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #7
SOIL is based on stb_image which specifies PNG files must be 8bit. That's 8bit per channel though, and has nothing to do with paletted PNG files as you're describing (but it should load those just fine too).

The problem you're seeing is likely due to Xcode mangling your PNG files when building for the device. You can uncheck "Compress PNG files" in your build settings to avoid that, or use a file extension other than ".png".
Quote this message in a reply
Moderator
Posts: 3,572
Joined: 2003.06
Post: #8
I just wanted to pop in and say thanks for all the "thanks" Smile

Other than that, I'm with Frank on the png mangle out of xcode. Definitely try disabling that first.
Quote this message in a reply
Sage
Posts: 1,482
Joined: 2002.09
Post: #9
If you just need png loading why not actually use libPNG? You don't need very much code to load a PNG into a texture, and there are examples available. Best of all, by not using a cobbled together image loading library, you won't run into files that don't work. Wink

Scott Lembcke - Howling Moon Software
Author of Chipmunk Physics - A fast and simple rigid body physics library in C.
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #10
I can't vouch for SOIL but I've been using both libpng and SOIL's progenitor stb_image for years, and when I need to load PNG files under my control, I always go for stb_image. It's smaller, faster, and just way way simpler than libpng - plus you get JPEG & PSD and a few other goodies for free.

stb_image & friends are absolutely not suitable for files you don't control though, so if you need to load any PNG file then definitely yes, go for libpng.
Quote this message in a reply
Member
Posts: 306
Joined: 2009.03
Post: #11
Hey Frank. Just wanted to thank you. About a month ago I was hitting all sorts of strange issues with libpng and you suggested that stb_image and it has worked great since then!
Quote this message in a reply
Apprentice
Posts: 6
Joined: 2010.03
Post: #12
Well I have it kinda working now. Thing is though, won't it slow my game down if my pngs aren't mangled by xcode? I thought it optimised them. Also, it swaps colour channels too doesn't it? I wouldn't like to end up with files with funny colours Smile
Quote this message in a reply
Member
Posts: 446
Joined: 2002.09
Post: #13
Lots of thank you's in this thread Wink ...

@hippocoder By the time OpenGL gets your textures, they are no longer PNG (just raw data) so no, they won't slow down your game. You also won't see funny colours if you use a standard loader with standard (un-Xcode-mangled) PNGs. Xcode mangles PNG for use with CoreGraphics/UIKit, which will load and display mangled PNGs faster. That only really makes sense when using UKit though, since views are typically purged and restored constantly to conserve memory (as far as I understand - I'm no UIKit guru).

If you really need better texture performance in OpenGL there are a few strategies you can use but that's a whole other thread.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  opengl es strange 16bit texture scale problem spuckfunkel 6 9,176 Aug 14, 2011 10:44 PM
Last Post: headkaze
  Scaling Problem in Cocos2d Jerm #1 7 9,984 May 18, 2011 11:02 AM
Last Post: EvolPenguin
  in simulator the app is working, on devices no...how can i find the problem? sefiroths 5 7,347 Jan 27, 2011 11:42 AM
Last Post: sefiroths
  Problem with Game Car nan2castillo 0 1,588 Nov 11, 2010 09:15 AM
Last Post: nan2castillo
  iPad window size problem the_wandering_monster 7 8,634 Oct 8, 2010 11:06 AM
Last Post: Rasterman