Simple OpenGL Image Library

From Libregamewiki
Jump to: navigation, search

The Simple OpenGL Image Library or SOIL is a public domain image loading library, written in C. The library allows users to load images directly to OpenGL textures.

The Simple OpenGL Image Library can load bitmap, jpeg, png, tga, and dds files.

Example of Use[edit]

The following example is a simple function built to load an image and return the OpenGL texture result.

GLuint GetTexture(std::string Filename)
{
	GLuint tex_ID;

	tex_ID = SOIL_load_OGL_texture(
				Filename.c_str(),
				SOIL_LOAD_AUTO,
				SOIL_CREATE_NEW_ID,
				SOIL_FLAG_POWER_OF_TWO
				| SOIL_FLAG_MIPMAPS
				| SOIL_FLAG_MULTIPLY_ALPHA
				| SOIL_FLAG_COMPRESS_TO_DXT
				| SOIL_FLAG_DDS_LOAD_DIRECT
				| SOIL_FLAG_INVERT_Y
				);

		if( tex_ID > 0 )
		{
			glEnable( GL_TEXTURE_2D );
			glBindTexture( GL_TEXTURE_2D, tex_ID );
			
			return tex_ID;
		}
		else
			return 0;
}


External links[edit]