• 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

A new update is out:
* fixed a rare memory error in up_scale_image (thanks Pete!)
* sped up the up_scale_image function
* added SOIL_FLAG_NTSC_SAFE_RGB to SOIL, which causes SOIL to scale the RGB values from [0,255] to [16,235], the "safe range" for NTSC output devices (a.k.a. most US TV sets). Alpha levels remain untouched.

I plan on trying to optimize my MIPmap generation code, as that seems to be the most common bottleneck now. I will also be playing with a few different programming languages to make sure they can use SOIL (thanks for the inspiration, Merick Zero!)
0

Share this post


Link to post
Share on other sites
I've got a problem using this in FreeBasic. First, if I make multiple calls to SOIL_load_OGL_texture using the SOIL_CREATE_NEW_ID flag, all of them end up returning 0 for the texture id. Aside from the fact that it just keeps over-writing the same texture with the new image, 0 is also what gets returned on an error

However, if I do specify a number for the texture id it works fine.
0

Share this post


Link to post
Share on other sites
I will look into this, thanks for the info.

*Edited to load 2 images*

OK, I have it working with the following lines:

dim shared g_texture as GLuint
dim shared g_texture2 as GLuint
g_texture = SOIL_load_OGL_texture( "terrain.bmp", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )
g_texture2 = SOIL_load_OGL_texture( "mars-ter.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )

And here is the header file (I re-ran SWIG with the latest version, so make sure you are using the latest libSOIL.a file); SOIL.bi

''
''
'' Jonathan Dummer
'' Simple OpenGL Image Library
'' MIT License
''
'' I'm using Sean's Tool Box image loader as a base:
'' http://www.nothings.org/
''
'' Note: header translated with help of SWIG FB wrapper
'' Check the SOIL.h file for more information
''
#ifndef __SOIL_bi__
#define __SOIL_bi__

#inclib "SOIL"

enum
SOIL_LOAD_AUTO = 0
SOIL_LOAD_L = 1
SOIL_LOAD_LA = 2
SOIL_LOAD_RGB = 3
SOIL_LOAD_RGBA = 4
end enum

enum
SOIL_CREATE_NEW_ID = 0
end enum

enum
SOIL_FLAG_POWER_OF_TWO = 1
SOIL_FLAG_MIPMAPS = 2
SOIL_FLAG_TEXTURE_REPEATS = 4
SOIL_FLAG_MULTIPLY_ALPHA = 8
SOIL_FLAG_INVERT_Y = 16
SOIL_FLAG_COMPRESS_TO_DXT = 32
SOIL_FLAG_DDS_LOAD_DIRECT = 64
SOIL_FLAG_NTSC_SAFE_RGB = 128
end enum

enum
SOIL_SAVE_TYPE_TGA = 0
SOIL_SAVE_TYPE_BMP = 1
SOIL_SAVE_TYPE_DDS = 2
end enum

const SOIL_DDS_CUBEMAP_FACE_ORDER = "EWUDNS"

declare function SOIL_load_OGL_texture cdecl alias "SOIL_load_OGL_texture" (byval filename as zstring ptr, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_load_OGL_cubemap cdecl alias "SOIL_load_OGL_cubemap" (byval x_pos_file as zstring ptr, byval x_neg_file as zstring ptr, byval y_pos_file as zstring ptr, byval y_neg_file as zstring ptr, byval z_pos_file as zstring ptr, byval z_neg_file as zstring ptr, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_load_OGL_single_cubemap cdecl alias "SOIL_load_OGL_single_cubemap" (byval filename as zstring ptr, byval face_order as zstring ptr, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_load_OGL_texture_from_memory cdecl alias "SOIL_load_OGL_texture_from_memory" (byval buffer as ubyte ptr, byval buffer_length as integer, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_load_OGL_cubemap_from_memory cdecl alias "SOIL_load_OGL_cubemap_from_memory" (byval x_pos_buffer as ubyte ptr, byval x_pos_buffer_length as integer, byval x_neg_buffer as ubyte ptr, byval x_neg_buffer_length as integer, byval y_pos_buffer as ubyte ptr, byval y_pos_buffer_length as integer, byval y_neg_buffer as ubyte ptr, byval y_neg_buffer_length as integer, byval z_pos_buffer as ubyte ptr, byval z_pos_buffer_length as integer, byval z_neg_buffer as ubyte ptr, byval z_neg_buffer_length as integer, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_load_OGL_single_cubemap_from_memory cdecl alias "SOIL_load_OGL_single_cubemap_from_memory" (byval buffer as ubyte ptr, byval buffer_length as integer, byval face_order as zstring ptr, byval force_channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_create_OGL_texture cdecl alias "SOIL_create_OGL_texture" (byval data as ubyte ptr, byval width as integer, byval height as integer, byval channels as integer, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_create_OGL_single_cubemap cdecl alias "SOIL_create_OGL_single_cubemap" (byval data as ubyte ptr, byval width as integer, byval height as integer, byval channels as integer, byval face_order as zstring ptr, byval reuse_texture_ID as uinteger, byval flags as uinteger) as uinteger
declare function SOIL_save_screenshot cdecl alias "SOIL_save_screenshot" (byval filename as zstring ptr, byval image_type as integer, byval x as integer, byval y as integer, byval width as integer, byval height as integer) as integer
declare function SOIL_load_image cdecl alias "SOIL_load_image" (byval filename as zstring ptr, byval width as integer ptr, byval height as integer ptr, byval channels as integer ptr, byval force_channels as integer) as ubyte ptr
declare function SOIL_load_image_from_memory cdecl alias "SOIL_load_image_from_memory" (byval buffer as ubyte ptr, byval buffer_length as integer, byval width as integer ptr, byval height as integer ptr, byval channels as integer ptr, byval force_channels as integer) as ubyte ptr
declare function SOIL_save_image cdecl alias "SOIL_save_image" (byval filename as zstring ptr, byval image_type as integer, byval width as integer, byval height as integer, byval channels as integer, byval data as ubyte ptr) as integer
declare sub SOIL_free_image_data cdecl alias "SOIL_free_image_data" (byval img_data as ubyte ptr)
declare function SOIL_last_result cdecl alias "SOIL_last_result" () as zstring ptr

#endif


Note that returning 0 signifies an error, as you mentioned, because OpenGL will return a 0 if it fails to generate a texture ID. Binding a 0 as your texture ID is now (I believe) undefined.

[Edited by - lonesock on October 17, 2007 1:35:44 PM]
0

Share this post


Link to post
Share on other sites
Which version of the FreeBasic compiler did you test it with? With 0.18 r2, this code:

#include once "GL/gl.bi"
#include once "soil.bi"

dim shared g_texture as GLuint
dim shared g_texture2 as GLuint

screen 18

glGenLists 10

g_texture = SOIL_load_OGL_texture( "ball.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )
print g_texture
print *SOIL_last_result

g_texture2 = SOIL_load_OGL_texture( "mc.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )
print g_texture2
print *SOIL_last_result


sleep


gives me this output:

0
Image loaded as an OpenGL texture


0
Image loaded as an OpenGL texture


Just in case, I did re-download the .zip from your link, but the libsoil.a in the archive is the same as the one I was already using.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by Merick Zero
gives me this output:
0
Image loaded as an OpenGL texture

Well, the 0 is most likely because there is no OpenGL context yet. If I understand the FreeBasic docs correctly, you need to say "screen 18,16,,&h02" or something similar to actually initialize the OpenGL driver. I've had trouble doing just that simple example, though...it seems that if you don't actually display anything then the context is not created. However when I drop the SOIL test code into already working OpenGL examples (provided with the FB compiler) it has worked.

The "Image loaded as an OpenGL texture" part means that SOIL doesn't detect this class of error. I will get working on that.
0

Share this post


Link to post
Share on other sites
Ah, so that's what was wrong

#include once "fbgfx.bi"
#include once "GL/gl.bi"
#include once "soil.bi"

dim shared g_texture as GLuint
dim shared g_texture2 as GLuint

screenres 648,480,32, 1, FB.GFX_OPENGL, FB.GFX_MULTISAMPLE

glGenLists 10
open cons for output as #1

g_texture = SOIL_load_OGL_texture( "ball.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )
print #1, g_texture
print #1, *SOIL_last_result

g_texture2 = SOIL_load_OGL_texture( "mc.png", SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS )
print #1, g_texture2
print #1, *SOIL_last_result


while not multikey(FB.SC_ESCAPE)
flip
wend


"fbgfx.bi" puts the constants for the internal graphics and keyboard scancodes into the FB namespace
0

Share this post


Link to post
Share on other sites
heya,
Im testing your image loading libery and having problem with this little snippet:


#include <soil.h>
#include <glfw.h>

int main(int argc,char *argv[])
{
GLuint tex_2d;

tex_2d=SOIL_load_OGL_texture("somepicname.png",SOIL_LOAD_AUTO,SOIL_CREATE_NEW_ID,
SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT);

return 0;
}


and these are errors:

error LNK2005: _SOIL_DDS_CUBEMAP_FACE_ORDER already defined in main.obj

fatal error LNK1169: one or more multiply defined symbols found

libs (glfw,soil,opengl32,glu32) are linked staticly in console project VC++2005EE and compiled as C language,

thanks for your time,
Dancho
0

Share this post


Link to post
Share on other sites
@Dancho: Thanks for testing SOIL! I'm not sure why that error occurs, but I have a suspicion. I have 2k5 EE at home, so I will test this within a few days. In the mean time you may be able to get it to compile and run by commenting out the offending lines (you can pass in "EWUDNS" instead if needed):

/*
const char SOIL_DDS_CUBEMAP_FACE_ORDER[] =
{ 'E', 'W', 'U', 'D', 'N', 'S' };
*/

BTW, in that snippet SOIL_load_OGL_texture will have trouble because there is no OpenGL context. You will need to call glfwInit() and glfwOpenWindow(...) before SOIL can upload OpenGL textures. It can still load them just fine for other purposes (via SOIL_load_image(), etc.).

Thanks again for testing SOIL and for the feedback!
0

Share this post


Link to post
Share on other sites
@lonesock
np,I think that SOIL project have a great potential and Im glad I could help hounting all bugs...
0

Share this post


Link to post
Share on other sites
OK, new SOIL release with some fixes and some new features. Here is a Copy-n-Paste of the changelog:

* correctly reports when there is no OpenGL context (thanks Merick Zero!)
* upgraded to stb_image 1.03 with support for loading the HDR image format
* fixed loading JPEG images while forcing the number of channels (e.g. to RGBA)
* changed SOIL_DDS_CUBEMAP_FACE_ORDER to a #define (thanks Dancho!)
* reorganized my additions to stb_image (you can define STBI_NO_DDS to compile SOIL without DDS support)
* added SOIL_FLAG_CoCg_Y, will convert RGB or RGBA to YCoCg color space (link)

Thanks again to everyone for your feedback and helping find bugs!
0

Share this post


Link to post
Share on other sites
@lonesock

that snippet is now working ok with your lib,
but when I try to compile a VC8 SOIL.sln I get this error:

1>LIB : fatal error LNK1181: cannot open input file '.\lib\stb_image.obj'

regards,
Dancho



0

Share this post


Link to post
Share on other sites
Quote:
Original post by Dancho
...when I try to compile a VC8 SOIL.sln...

Argh! I renamed a few files in my quest to make DDS loading easy to compile in/out of SOIL, and forgot to update all the Visual Studio projects (I do all my hobby stuff on CodeBlocks). I'm so sorry, I'll get that updated soon.

Thanks,
0

Share this post


Link to post
Share on other sites
Hey Lonesock,

Your SOIL is great, thanks. Just a couple problems building on OSx.

Soil.c line 1428 should be

CFRelease( extensionName ); (I think)


and SOIL.c line 78 (I just deleted APIENTRY)

after that, it builds and works fine (I only tried SOIL_load_OGL_texture with PNGs)


Matt
0

Share this post


Link to post
Share on other sites
Once I've used SOIL_load_OGL_texture to load a texture, how do I remove it from memory? SOIL_free_image_data doesn't seem to do anything
0

Share this post


Link to post
Share on other sites
Hi

Thanks for this great library, I'm probably going to integrate it into my own library to get rid of DevIL for image loading. As in public domain, I should be able to include the SOIL files directly into my project instead of building it as a separate library, right (my library is open-source, under the zlib/png license) ?

Just a few suggestions to improve integration of SOIL into other libraries :

- You should split the functions into 2 separate sets of files : those for pure image loading / saving, and those related to OpenGL textures. Then you can add the ability to use the first subset of the whole library with a define, like SOIL_USE_OPENGL or SOIL_DONT_USE_OPENGL. Your library is very useful to add image loading to higher-level libraries (like mine), but not everybody will want the OpenGL stuff.

- There are still a lot of warnings when compiling (I use level 4 in Visual Studio), mainly due to implicit casts or signed/unsigned mismatches. They can be easily corrected, so I think it would be a good idea to fix them to make compiling cleaner.

- There is a bug (or at least an inconsistent behavior) when loading a DDS : if the source image has no alpha, it will convert the output to 3 components even when the caller requested 4.

- Do you think PNG and JPEG formats can be supported for saving ? Or maybe I should rather contact the author of stb_image ?
0

Share this post


Link to post
Share on other sites
@Mogui: Thanks for letting me know. I was pointed towards another error I had with that segment of code, which might fix this problem too. The next release will have the fix and I'll try to PM you to see if it fixed the issue.

@Merick Zero: Sorry if the docs are unclear. The SOIL_free_image_data() function is actually for use with SOIL_load_image() or similar which returns an array of unsigned chars. If you are done with the OpenGL texture, simply call the glDeleteTextures() function, like this:
glDeleteTextures( 1, &my_tex_ID );

@LaurentGom: You're welcome! "Public Domain" as in if you want to take the code, rename it LOIS and sell it as a closed source project to Microsoft, that's OK with me [8^) Your suggestions are excellent. If I may comment on them very quickly:
1) People can just use stb_image if they want image loading only (with my DDS additions if so desired). What other functionality does SOIL offer that you would want with the image loading stuff?
2) I am leaving the stb_image code mostly untouched, but if you find any of those warning in any other piece of code, please PM or email the list to me and I would be happy to fix them!
3) Ouch! I'll look into that.
4) I think contacting Sean (see his site here) would be a good idea.

Again, thank you all for your feedback & bug reports!
0

Share this post


Link to post
Share on other sites
Thanks for the informations.

Just a few precisions for 1) : in the version I downloaded (a few days ago), DDS and PNG was not part of stb_image. Same for the general load / save functions (they were mixed with the OpenGL ones in SOIL.h).
It seems to have changed, so I should just get the latest version.
0

Share this post


Link to post
Share on other sites
when using soil to load an image, is there any way to get the alpha value from a certain pixel inside the image, either from the image buffer created by SOIL_load_image or from the gl texture itself? Basically what I want to do is create an array with 0's and 1's to use as data for pixel perfect collision in 2d games
0

Share this post


Link to post
Share on other sites
Hi, All. There is a new release of SOIL; here's the changelog:

* upgraded to stb_image 1.04, some tiny bug fixes
* there is now a makefile (under projects) for ease of building under Linux (thanks D J Peters!)
* Visual Studio 6/2003/2005 projects are working again (thanks Dancho!)
* patched SOIL for better pointer handling of the glCompressedTexImage2D extension (thanks Peter Sperl!)
* fixed DDS loading when force_channels=4 but there was no alpha; it was returning 3 channels. (Thanks LaurentGom!)
* fixed a bunch of channel issues in general. (Thanks Sean Barrett!)

@Mogui: could you check and see if the compilation issue is gone now?

@LaurentGom: DDS loading and saving (and the DXT compression) code is still separate from the stb_image code, but hopefully modular enough that you can just include those files in your projects. Also, I fixed the 3-channel DDS loading issue.

@Merick Zero: you can load the image using SOIL_load_image(), forcing 4 channels by using SOIL_LOAD_RGBA, then make a copy of only the alpha channel (every 4th byte). You could then upload the image as an OpenGL texture using SOIL_create_OGL_texture() with the image data you just loaded.

@D J Peters: The latest SOIL release has a makefile under the projects directory so you can make the library easily under Linux. Just go to the projects/makefile directory and run 'make'. I haven't been able to test it under Linux, but it works under MSYS on Windows. Please let me know if you have any problems.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by lonesock@D J Peters: ...Please let me know if you have any problems.

first thanx for this fine short lib
and no problems to build the lib on linux.

can i use it for http://fsr.sf.net Free Speed Racer is it open source ?

Joshy
0

Share this post


Link to post
Share on other sites
Quote:
Original post by D J Peters
first thanx for this fine short lib
and no problems to build the lib on linux.

can i use it for http://fsr.sf.net Free Speed Racer is it open source ?

Joshy

You are welcome! I'm glad to hear there were no build problems. SOIL is released to the Public Domain, so yes, you can use it for free in any project you want, even commercial closed-source projects.
0

Share this post


Link to post
Share on other sites
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?
0

Share this post


Link to post
Share on other sites
SOIL seems to work fine in OS X, apart from a couple of updates to the includes, etc.

Here is the diff of the changes I had to make to get it to work (updates to the right):

Quote:

23c23
< #include <GL/gl.h>
---
> #include <OpenGL/gl.h>
24a25
> #define APIENTRY
1529c1530
< CFRelease( functionName );
---
> CFRelease( extensionName );


Edit: I love this library! If you need a long-term OS X maintainer, I am available... just drop me an email (swiftcoder@gmail.com) whenever you need a new release testing ;)

[Edited by - swiftcoder on November 4, 2007 2:05:03 PM]
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