View more

View more

View more

Image of the Day Submit

IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

130 replies to this topic

#81swiftcoder  Senior Moderators

Posted 07 November 2007 - 04:58 AM

Quote:
 Original post by lonesockRegarding 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 ZeroWhen 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.

#82lonesock  Members

Posted 10 November 2007 - 07:53 AM

OK, today's version of SOIL:

* 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!

#83swiftcoder  Senior Moderators

Posted 11 November 2007 - 08:03 AM

Quote:
 Original post by lonesockOK, 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?

#84Bakura  Members

Posted 28 December 2007 - 02:21 AM

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.

#85lonesock  Members

Posted 28 December 2007 - 06:39 AM

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.

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^)

#86Bakura  Members

Posted 28 December 2007 - 08:26 AM

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 :)

#87cornmander  Members

Posted 31 December 2007 - 12:55 PM

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':
collect2: ld returned 1 exit status
make: *** [client] Error 1

#88Grantax  Members

Posted 01 January 2008 - 04:57 AM

No updates since 2007, this sucks. :D

j/k, great work. :)

#89Boder  Members

Posted 06 February 2008 - 01:21 PM

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]

#90lonesock  Members

Posted 08 February 2008 - 09:31 AM

@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?

#91Bakura  Members

Posted 10 February 2008 - 10:25 PM

Yes, it worked :). Sorry for not having answered you sooner :D

#92bronxbomber92  Members

Posted 12 February 2008 - 02:45 PM

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.

Released under public domain.

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]

#93desudesu  Members

Posted 17 February 2008 - 01:46 AM

Awesome library, I'm definitely going to replace SDL_img with it. Thanks!

#94swiftcoder  Senior Moderators

Posted 17 February 2008 - 01:51 AM

Quote:
 Original post by bronxbomber92Btw, compiled on Mac OS X!

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

#95bjarnia  Members

Posted 12 April 2008 - 02:30 AM

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.

#96lonesock  Members

Posted 16 April 2008 - 07:23 PM

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.

#97ghosted  Members

Posted 16 April 2008 - 09:17 PM

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.

#98Amnesiac5  Members

Posted 07 May 2008 - 02:31 AM

!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

  #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]

#99ricardo_ruiz_lopez  Members

Posted 19 May 2008 - 09:38 PM

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);

// 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();

[/code]

Thanks a lot for your help.

Picture:

#100syndicatedragon  Members

Posted 23 May 2008 - 11:42 AM

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

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.