• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
lonesock

SOIL: new lightweight image loading lib

130 posts in this topic

How about modifying the texture creation code with a SOIL_FLAG_TEXTURE_RECTANGE flag? This would allow us to use the same function to load GUI textures, etc.
0

Share this post


Link to post
Share on other sites
@Merick Zero: I like that idea! I'm not sure of an elegant way to specify the color to be converted to transparency, but I'll try to come up with something. Did you mean like the exact color RGB will become alpha=0, or more like the "Color to Alpha" function of The GIMP (and I assume PhotoShop) where it maps a range of alpha values?

@swiftcoder: Thanks for being willing to do OS X testing! I'd really appreciate it. I've fixed the lines you (and Mogui) indicated for the soon-to-be-out next release, so hopefully now my claims of "cross-platform" will be out of the box, not "after extensive tweaking" [8^). Regarding the NPOT textures, what if the user does not specify SOIL_FLAG_POWER_OF_TWO or SOIL_FLAG_MIPMAPS (do I understand correctly that MIPmaps are forbidden to non-power-of-two textures?) and the texture is not already a POT, then SOIL could use GL_TEXTURE_RECTANGLE_ARB automatically?

Thanks
0

Share this post


Link to post
Share on other sites
Re: Mipmaps and NPOT:
From the OpenGL Extension registry for ARB_texture_non_power_of_two:
"When this extension is supported, mipmapping, automatic mipmap
generation, and all the conventional wrap modes are supported for
non-power-of-two textures".
For mip generation rules, check the registry entry: http://oss.sgi.com/projects/ogl-sample/registry/ARB/texture_non_power_of_two.txt
0

Share this post


Link to post
Share on other sites
Quote:
Original post by lonesock
Regarding the NPOT textures, what if the user does not specify SOIL_FLAG_POWER_OF_TWO or SOIL_FLAG_MIPMAPS (do I understand correctly that MIPmaps are forbidden to non-power-of-two textures?) and the texture is not already a POT, then SOIL could use GL_TEXTURE_RECTANGLE_ARB automatically?

Thanks


This was my initial idea, but I scrapped it because I wasn't sure whether such a strange beast as TEXTURE_RECTANGLE should ever be the default? I certainly wouldn't mind it that way though.

(note that you also need to exclude SOIL_FLAG_TEXTURE_REPEATS, as repeating is not supported)
0

Share this post


Link to post
Share on other sites
What I was thinking about was just something to remove solid-color background from images to make sprites for 2d.

I'm not too familiar with how the gimp function works, but why not do both and have it accept an array for the argument? Then you could determine which method to use by the structure of the array

something like

myarray = (255,0,255)

or

myarray = ( (123,50,45), (100,200,200), (0,0,155))
0

Share this post


Link to post
Share on other sites
Quote:
Original post by lonesock
Regarding the NPOT textures, what if the user does not specify SOIL_FLAG_POWER_OF_TWO or SOIL_FLAG_MIPMAPS and the texture is not already a POT, then SOIL could use GL_TEXTURE_RECTANGLE_ARB automatically?


I didn't read this carefully enough the first time round - one needs to be able to specify that the texture be loaded as GL_TEXTURE_RECTANGLE, even if the image is already Po2. This is because Po2 textures use pixel-based texture coordinates rather than normalised, so if one loads the wrong type by mistake, the GUI texturing blows up.

Quote:
Original post by Merick Zero
When using the SOIL_LOAD_RGBA flag, how about adding another argument that can let you specify a color value for a transparency mask for images that don't normally have transparency like bmp?


I don't like this idea. You want to increase the library complexity to make up for a deficiency in the art pipeline - it offers much more control if you use photoshop/Gimp to generate the alpha channel (and then use a format that support alpha, i.e. png), than if the programmer does it from a color/pixel value.

Basically, it is a classic case of separation of responsibility: SOIL's job is to load images into byte buffers/textures, and the artist's job is to ensure the images contain the necessary data.
0

Share this post


Link to post
Share on other sites
OK, today's version of SOIL:

* adds SOIL_FLAG_TEXTURE_RECTANGLE (thanks swiftcoder!)
* now forces SOIL_FLAG_POWER_OF_TWO if the user did not specify SOIL_FLAG_TEXTURE_RECTANGLE and if the hardware does not support ARB_texture_non_power_of_two (thanks Starfox!)

I only tested the SOIL_FLAG_TEXTURE_RECTANGLE on one image, so please let me know if I messed anything up. Note that if the user specifies SOIL_FLAG_TEXTURE_RECTANGLE and the hardware does not support it the function will return a 0 (error) because of the difference in addressing (pixels versus normalized [0,1]). If you load a cubemap, SOIL_FLAG_TEXTURE_RECTANGLE is automatically disabled. If SOIL_FLAG_TEXTURE_RECTANGLE is used successfully, mipmaps and texture repeats are disabled.

@Merick Zero: I'm sorry, I couldn't think of an easy way to add in that functionality without making the interface kludgy. The closest I came up with was the old Win2k (I think) icon hack where it would take the color in the corners as the transparency color. I think the best solution would be to just wrap SOIL_load_image() and SOIL_create_OGL_texture() in a function with your "sample to alpha" code sandwiched in between.

Thanks to everyone for their input and feedback!
0

Share this post


Link to post
Share on other sites
Quote:
Original post by lonesock
OK, today's version of SOIL:

* adds SOIL_FLAG_TEXTURE_RECTANGLE (thanks swiftcoder!)
* now forces SOIL_FLAG_POWER_OF_TWO if the user did not specify SOIL_FLAG_TEXTURE_RECTANGLE and if the hardware does not support ARB_texture_non_power_of_two (thanks Starfox!)

I only tested the SOIL_FLAG_TEXTURE_RECTANGLE on one image, so please let me know if I messed anything up. Note that if the user specifies SOIL_FLAG_TEXTURE_RECTANGLE and the hardware does not support it the function will return a 0 (error) because of the difference in addressing (pixels versus normalized [0,1]). If you load a cubemap, SOIL_FLAG_TEXTURE_RECTANGLE is automatically disabled. If SOIL_FLAG_TEXTURE_RECTANGLE is used successfully, mipmaps and texture repeats are disabled.


Line 961 (SOIL.c):
Quote:
opengl_texture_target = SOIL_TEXTURE_RECTANGLE_ARB;

Needs to be changed to:
Quote:
opengl_texture_target = opengl_texture_type = SOIL_TEXTURE_RECTANGLE_ARB;


To get this to work with any image. I am not entirely clear why there is both a target and a type argument here, but presumably it is needed for the cubemaps?
0

Share this post


Link to post
Share on other sites
Hi,

I was using SFML for image loading (it's Laurent Gomila's library), but since it didn't have any functions for loading number of mipmaps for DDS files, he gave me the link to your library, which is one of the simplest I've never tried :p.

But I have a few questions :

- Which method do you use for generating mipmaps ? gluBuild2DMipmaps, GL_MIPMAP generation or your own method ?
- Is there any way to get the width and height of a texture ?
- I have a problem for loading DDS files (while jpg, gif... there isn't any problem). The function is really simple :

[source="cpp"]void Texture2D::LoadCompressedTextureFromFile (const std::string & fileName_)
{
// We check if the hardware supports compressed texture
if (sf::OpenGLCaps::CheckExtension ("GL_ARB_texture_compression"))
{
GLuint imageID = SOIL_load_OGL_texture (fileName_.c_str(), SOIL_LOAD_AUTO, id, SOIL_FLAG_DDS_LOAD_DIRECT);

if (imageID == 0)
std::cerr << "Failed to load texture : " << fileName_ << std::endl;
}
else
std::cerr << "Your hardware doesn't support GL_ARB_texture_compression" << std::endl;
}


And I've effectively got an error. The DDS file is generated with "The Compressonator" (It's an ATI software I think), the mipmap were generated with it, it's a power of two texture, so I don't understand why it doesn't work.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Bakura
...
- Which method do you use for generating mipmaps ? gluBuild2DMipmaps, GL_MIPMAP generation or your own method ?
- Is there any way to get the width and height of a texture ?
- I have a problem for loading DDS files (while jpg, gif... there isn't any problem). The function is really simple :
...

Hi!

* mipmaps are done in software in SOIL, each pixel is the average of the 4 pixels in the mipmap level above. If you request mipmaps then I force the textures to a power of 2 so the mipmapping is really simple.

* SOIL doesn't report the size when directly uploading images to OpenGL textures, so you have two options:
1) use the OpenGL function glGetTexLevelParameter once the texture object is bound (which it is right after a call to SOIL's upload functions)
2) use a 2-step process where you call SOIL_load_image and get the image data (including size), then call SOIL_create_OGL_texture with the image data you just loaded.

* a few things about the source snippet and DDS loading:
1) what is "id"? If that isn't initialized to a value of 0 (a.k.a. SOIL_CREATE_NEW_ID), then SOIL will attempt to load the image into an existing ID. If "id" is a random number this will most likely fail.
2) SOIL checks for the necessary OpenGL extensions automatically. If DXT isn't supported, for example, SOIL will decompress the image then upload it as an uncompressed texture.
3) if the ID comes back 0, you can use the following code to see what SOIL was thinking:
std::cerr << SOIL_last_result() << std::endl;
4) it could very well be a bug in my DDS loading code. If you would like to send me the offending DDS file via email I'd be happy to debug SOIL using it. My email address is the same as my profile name, at gmail.com

Thanks for giving SOIL a try! [8^)
0

Share this post


Link to post
Share on other sites
Quote:
* mipmaps are done in software in SOIL, each pixel is the average of the 4 pixels in the mipmap level above. If you request mipmaps then I force the textures to a power of 2 so the mipmapping is really simple.

Ok :)

Quote:

* SOIL doesn't report the size when directly uploading images to OpenGL textures, so you have two options:
1) use the OpenGL function glGetTexLevelParameter once the texture object is bound (which it is right after a call to SOIL's upload functions)
2) use a 2-step process where you call SOIL_load_image and get the image data (including size), then call SOIL_create_OGL_texture with the image data you just loaded.

I didn't know glGetTexLevelParameter, that's exactly what I wanted, thanks ;)

Quote:
* a few things about the source snippet and DDS loading:
1) what is "id"? If that isn't initialized to a value of 0 (a.k.a. SOIL_CREATE_NEW_ID), then SOIL will attempt to load the image into an existing ID. If "id" is a random number this will most likely fail.
2) SOIL checks for the necessary OpenGL extensions automatically. If DXT isn't supported, for example, SOIL will decompress the image then upload it as an uncompressed texture.
3) if the ID comes back 0, you can use the following code to see what SOIL was thinking:
std::cerr << SOIL_last_result() << std::endl;
4) it could very well be a bug in my DDS loading code. If you would like to send me the offending DDS file via email I'd be happy to debug SOIL using it. My email address is the same as my profile name, at gmail.com


I'm using my own id number generated with glGenTextures, and I just don't want you create another ID :p. And my id is not 0, and it works with other format (jpg, bmp, gif...) so this is not a problem with the id.

But your function effectively return 0, so it fails, and when I call SOIL_last_result() it tells me : "Unable to open file".

I send you the file :)

0

Share this post


Link to post
Share on other sites
Hi, I linked in SOIL and included it in files where I use SOIL functions, but I still get this during the compilation process:


make client
gcc -Wall -O2 -std=c99 -c -o renderinggl.o renderinggl.c
gcc -lm -lSDL -lSDL_image -lSDL_gfx -lSDL_ttf -lGL -lSOIL client.o utils.o clientutils.o rendering.o options.o input.o renderinggl.o renderingsw.o utils.h clientutils.h client.h rendering.h options.h input.h renderingsw.h -o client
renderinggl.o: In function `init_gl':
renderinggl.c:(.text+0x397): undefined reference to `SOIL_load_OGL_texture'
collect2: ld returned 1 exit status
make: *** [client] Error 1
0

Share this post


Link to post
Share on other sites
To lonesock,

the "inline void check_for_GL_errors()" in SOIL.c stops it from compiling, so I removed the inline part. Doesn't inline have to be in the header?


To the corn guy,

try moving -lSOIL to the end of the command, sometimes gcc keeps a list of unresolved symbols so you might need that after the offending .o

[Edited by - Boder on February 6, 2008 8:21:53 PM]
0

Share this post


Link to post
Share on other sites
@Boder: I'm mostly a C++ guy, I hadn't realized the C "inline" keyword was so complicated. I'll try to look into this, but the inlining is not critical. Thanks for helping cornmander.

@Grantax: thanks!

@cornmander: it really does just sound like a linking-order issue, as Boder said.

@Bakura: I never heard the final result after our emails...did it work out OK?

To everyone, I'm interested in supporting loading of Radiance RGBE files into standard RGBA formats (8-bit or DXT5). Right now loading an HDR file rescales it to a LDR RGB image via simple scaling. I propose an alternate loading path (with all the same options) for loading HDR files into RGBA in one of 3 formats:

(range is in base 10 orders of magnitude, monotonic refers to the results of bilinear sampling)
RGBE: RGB * pow( 2.0, A - 128.0 )
range ~76 (orders of magnitude), error 0.2% to 0.4% throughout, NOT monotonic
(note: if this format was monotonic, it would be the clear winner, but since it isn't I personally would go with RGB/(A*A))

RGBdivA: RGB / A
range ~4.8, error 0% to 0.4% at the high end, IS monotonic

RGBdivA2: RGB / (A*A)
range ~7.2, error 0% to 0.77% at high end, IS monotonic
(note: the error is <= 0.43% if limited to 6.6 orders of magnitude, my personal favorite)

Does anyone have any opinions or advice on this proposed feature?
0

Share this post


Link to post
Share on other sites
I've ported your library to C# (using Mono). I've only tested what was in you original C example file, and it all seems to work fine, so I suspect everything is fine. If there are any bugs I can be contacted here on gamedev.

I have no place to permanently upload this, so if this link dies please contact me :-)
Released under public domain.

Thanks for such an awesome image loading library lonesock!!

Soil#: http://a-nub.pspsc.com/stuff/Soil%23.zip
mirror: http://www.sendspace.com/file/ki6kcs

Btw, compiled on Mac OS X!

[Edited by - bronxbomber92 on February 12, 2008 9:45:12 PM]
0

Share this post


Link to post
Share on other sites
Quote:
Original post by bronxbomber92
Btw, compiled on Mac OS X!

Good to hear - let me know if there were any problems.
0

Share this post


Link to post
Share on other sites
Love this library.

One thing that i'm sorely missing is configuring texture wrap modes aside from repeating. Mainly forcing a certain border color. I use that a lot.

An easy way of adding support for that could be to have a static float4 stored in SOIL that the user could change with like
SOIL_Set_Border_Color(float4);
and then have a flag such as SOIL_FLAG_BORDER_COLOR for the loading function that would use soil's static border var as a color.


0

Share this post


Link to post
Share on other sites
Hi, everyone. Sorry for the long silence. I'm expecting to be less busy in about a week, so I'll be making some updates, including a few of the requests (such as the ever popular "How big was the texture you just loaded?" [8^) and updating to the latest stb_image, etc.

Thanks for your patience.
0

Share this post


Link to post
Share on other sites
I'm still in that stubborn frame of mind where I want to write every last piece of my game myself but your little library there has so nearly tempted to change my ways. Even if I don't use it, you seem to have done an excellent job with the thing. Top stuff sir, your rate++ is in the post.
0

Share this post


Link to post
Share on other sites
!SOLVED!

I've just been trying to use SOIL and have been totally unsuccessful. Here are the problems I've encountered, so far.

I'm using C++ in VS 2005.

1. Using libSoil.a

(added a reference to libSoil.a and '#include "SOIL.h"')

Debug mode compiles but when run raises Unhandled exception and drops out to strstr.asm.

Build mode compiles but when run raises Unhandled exception

-=- -=- -=- -=- -=-


2. Including all the files

Debug mode acts as above, the error occurs in
int query_NPOT_capability( void )
if(
(NULL == strstr( (char const*)glGetString( GL_EXTENSIONS ),
"GL_ARB_texture_non_power_of_two" ) )
)
Build mode compiles but when run raises Unhandled exception

-=- -=- -=- -=- -=-


3. Compiling the library myself

had to add
  #ifdef _MSC_VER
#define inline __inline
#endif
to fix >>> error C2054: expected '(' to follow 'inline' <<<

the compiled library has the same problems as 1. above.


-=- -=- -=- -=- -=-

I also tried to compile and run test_SOIL.cpp from the src directory, but looking at the many, many rem's I'm guessing that this wasn't meant for release...

========================================================

All sorted.

It transpires that glGetString requires an OpenGL context to work, it may be good form to add a check to query_NPOT_capability to make sure it fails gracefully.

I'm pleased I sorted this one out since I like the fact that SOIL is a small-ish lib, and it's always pleasant to find why code is failing.

I started playing with FreeImage, which worked right off the bat, but a dll, lib and .h? C'mon, like that's too much work dude. So, now I can "go back" to playing with dirt... er, SOIL, I mean... Freudian slip?

HTH

[Edited by - Amnesiac5 on May 8, 2008 8:31:03 AM]
0

Share this post


Link to post
Share on other sites
hi!

I have a strange problem, sometimes my textures show a strange horzontal line at the bottom and another vertical one at the right. And sometimes it is working well.

Does anyone have any idea?


Code:
// model
m_plano = glGenLists(1);
glNewList(m_plano,GL_COMPILE);

glBegin (GL_QUADS);
// vertice 1
glTexCoord2f (0.0, 0.0);
glVertex3f (0.0, 0.0, 0.0);

// vertice 2
glTexCoord2f (0.0, 1.0);
glVertex3f (0.0, -1.0, 0.0);

// vertice 3
glTexCoord2f (1.0, 1.0);
glVertex3f (1.0, -1.0, 0.0);

// vertice 4
glTexCoord2f (1.0, 0.0);
glVertex3f (1.0, 0.0, 0.0);

glEnd ();
glEndList();


// load
tex_2d=SOIL_load_OGL_texture(nombre_archivo, SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID, 0);
[/code]

Thanks a lot for your help.

Picture:

0
If anyone is interested, I've packaged the SOIL library as a MacOSX framework. Looking forward to an update, especially size reporting!

0

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  
Followers 0