Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

first commit

  • Loading branch information...
commit e20258d97af1ebb39ba34a994730a8fe8afea352 0 parents
@kbranigan authored
58 Makefile
@@ -0,0 +1,58 @@
+# SOIL makefile for linux (based on the AngelScript makefile)
+# Type 'make' then 'make install' to complete the installation of the library
+
+# For 'make install' to work, set LOCAL according to your system configuration
+LOCAL = /usr/local
+
+LIB = libSOIL.a
+INC = SOIL.h
+
+SRCDIR = src
+LIBDIR = lib
+INCDIR = src
+OBJDIR = obj
+
+CXX = gcc
+CXXFLAGS = -O2 -s -Wall
+DELETER = rm -f
+COPIER = cp
+
+SRCNAMES = \
+ image_helper.c \
+ stb_image_aug.c \
+ image_DXT.c \
+ SOIL.c \
+
+OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.c=.o)))
+BIN = $(LIBDIR)/$(LIB)
+
+all: $(BIN)
+
+$(BIN): $(OBJ)
+ rm $(BIN)
+ ar r $(BIN) $(OBJ)
+ ranlib $(BIN)
+ @echo -------------------------------------------------------------------
+ @echo Done. As root, type 'make install' to install the library.
+
+$(OBJDIR)/%.o: $(SRCDIR)/%.c
+ $(CXX) $(CXXFLAGS) -o $@ -c $<
+
+
+clean:
+ $(DELETER) $(OBJ) $(BIN)
+
+install: $(BIN)
+ @echo Installing to: $(LOCAL)/lib and $(LOCAL)/include...
+ @echo -------------------------------------------------------------------
+ $(COPIER) $(BIN) $(LOCAL)/lib
+ $(COPIER) $(INCDIR)/$(INC) $(LOCAL)/include
+ @echo -------------------------------------------------------------------
+ @echo SOIL library installed. Enjoy!
+
+uninstall:
+ $(DELETER) $(LOCAL)/include/$(INC) $(LOCAL)/lib/$(LIB)
+ @echo -------------------------------------------------------------------
+ @echo SOIL library uninstalled.
+
+.PHONY: all clean install uninstall
3  README
@@ -0,0 +1,3 @@
+This is a clone of Simple OpenGL Image Library from http://lonesock.net/soil.html which hasn't changed since July 7, 2008.
+
+I wanted to work with the code and seeing it was MIT license and the original svn repo is offline, I figured it was acceptable to post it here.
132 projects/VC6/SOIL.dsp
@@ -0,0 +1,132 @@
+# Microsoft Developer Studio Project File - Name="SOIL" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Static Library" 0x0104
+
+CFG=SOIL - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "SOIL.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "SOIL.mak" CFG="SOIL - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "SOIL - Win32 Release" (based on "Win32 (x86) Static Library")
+!MESSAGE "SOIL - Win32 Debug" (based on "Win32 (x86) Static Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "SOIL - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD CPP /nologo /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_MBCS" /D "_LIB" /YX /FD /c
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ELSEIF "$(CFG)" == "SOIL - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD CPP /nologo /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_MBCS" /D "_LIB" /YX /FD /GZ /c
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LIB32=link.exe -lib
+# ADD BASE LIB32 /nologo
+# ADD LIB32 /nologo
+
+!ENDIF
+
+# Begin Target
+
+# Name "SOIL - Win32 Release"
+# Name "SOIL - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=..\..\src\image_DXT.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\image_helper.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\SOIL.c
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\stb_image_aug.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=..\..\src\image_DXT.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\image_helper.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\SOIL.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\stb_image_aug.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\stbi_DDS_aug.h
+# End Source File
+# Begin Source File
+
+SOURCE=..\..\src\stbi_DDS_aug_c.h
+# End Source File
+# End Group
+# End Target
+# End Project
29 projects/VC6/SOIL.dsw
@@ -0,0 +1,29 @@
+Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "SOIL"=".\SOIL.dsp" - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
21 projects/VC7.1/SOIL.sln
@@ -0,0 +1,21 @@
+Microsoft Visual Studio Solution File, Format Version 8.00
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SOIL", "SOIL.vcproj", "{35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}"
+ ProjectSection(ProjectDependencies) = postProject
+ EndProjectSection
+EndProject
+Global
+ GlobalSection(SolutionConfiguration) = preSolution
+ Debug = Debug
+ Release = Release
+ EndGlobalSection
+ GlobalSection(ProjectConfiguration) = postSolution
+ {35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}.Debug.ActiveCfg = Debug|Win32
+ {35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}.Debug.Build.0 = Debug|Win32
+ {35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}.Release.ActiveCfg = Release|Win32
+ {35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}.Release.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ EndGlobalSection
+ GlobalSection(ExtensibilityAddIns) = postSolution
+ EndGlobalSection
+EndGlobal
147 projects/VC7.1/SOIL.vcproj
@@ -0,0 +1,147 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="7.10"
+ Name="SOIL"
+ ProjectGUID="{35D9B7E3-EE73-4C06-9B98-FCB7F7644C99}"
+ Keyword="Win32Proj">
+ <Platforms>
+ <Platform
+ Name="Win32"/>
+ </Platforms>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="Debug"
+ IntermediateDirectory="Debug"
+ ConfigurationType="4"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="TRUE"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="5"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="4"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="$(OutDir)/SOIL.lib"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="Release"
+ IntermediateDirectory="Release"
+ ConfigurationType="4"
+ CharacterSet="2">
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="4"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="TRUE"
+ DebugInformationFormat="3"/>
+ <Tool
+ Name="VCCustomBuildTool"/>
+ <Tool
+ Name="VCLibrarianTool"
+ OutputFile="$(OutDir)/SOIL.lib"/>
+ <Tool
+ Name="VCMIDLTool"/>
+ <Tool
+ Name="VCPostBuildEventTool"/>
+ <Tool
+ Name="VCPreBuildEventTool"/>
+ <Tool
+ Name="VCPreLinkEventTool"/>
+ <Tool
+ Name="VCResourceCompilerTool"/>
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"/>
+ <Tool
+ Name="VCXMLDataGeneratorTool"/>
+ <Tool
+ Name="VCManagedWrapperGeneratorTool"/>
+ <Tool
+ Name="VCAuxiliaryManagedWrapperGeneratorTool"/>
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}">
+ <File
+ RelativePath="..\..\src\image_DXT.c">
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.c">
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.c">
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.c">
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
+ <File
+ RelativePath="..\..\src\image_DXT.h">
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.h">
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.h">
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.h">
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug.h">
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug_c.h">
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}">
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt">
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
20 projects/VC8/SOIL.sln
@@ -0,0 +1,20 @@
+
+Microsoft Visual Studio Solution File, Format Version 9.00
+# Visual Studio 2005
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SOIL", "SOIL.vcproj", "{C32FB2B4-500C-43CD-A099-EECCE079D3F1}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|Win32.Build.0 = Debug|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|Win32.ActiveCfg = Release|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
209 projects/VC8/SOIL.vcproj
@@ -0,0 +1,209 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="SOIL"
+ ProjectGUID="{C32FB2B4-500C-43CD-A099-EECCE079D3F1}"
+ RootNamespace="SOIL"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\src\image_DXT.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\..\src\image_DXT.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug_c.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
26 projects/VC9/SOIL.sln
@@ -0,0 +1,26 @@
+
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "SOIL", "SOIL.vcproj", "{C32FB2B4-500C-43CD-A099-EECCE079D3F1}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Debug|x64 = Debug|x64
+ Release|Win32 = Release|Win32
+ Release|x64 = Release|x64
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|Win32.ActiveCfg = Debug|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|Win32.Build.0 = Debug|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|x64.ActiveCfg = Debug|x64
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Debug|x64.Build.0 = Debug|x64
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|Win32.ActiveCfg = Release|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|Win32.Build.0 = Release|Win32
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|x64.ActiveCfg = Release|x64
+ {C32FB2B4-500C-43CD-A099-EECCE079D3F1}.Release|x64.Build.0 = Release|x64
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
337 projects/VC9/SOIL.vcproj
@@ -0,0 +1,337 @@
+<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="SOIL"
+ ProjectGUID="{C32FB2B4-500C-43CD-A099-EECCE079D3F1}"
+ RootNamespace="SOIL"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="131072"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ <Platform
+ Name="x64"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Debug|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_LIB"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|x64"
+ OutputDirectory="$(SolutionDir)$(PlatformName)\$(ConfigurationName)"
+ IntermediateDirectory="$(PlatformName)\$(ConfigurationName)"
+ ConfigurationType="4"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ TargetEnvironment="3"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_LIB"
+ RuntimeLibrary="2"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLibrarianTool"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath="..\..\src\image_DXT.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.c"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.c"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath="..\..\src\image_DXT.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\image_helper.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\SOIL.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stb_image_aug.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug.h"
+ >
+ </File>
+ <File
+ RelativePath="..\..\src\stbi_DDS_aug_c.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ <File
+ RelativePath=".\ReadMe.txt"
+ >
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
89 projects/codeblocks/SOIL.cbp
@@ -0,0 +1,89 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="Simple OpenGL Image Library" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="lib-Release">
+ <Option output="..\..\lib\libSOIL" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="" />
+ <Option object_output="obj\Release\" />
+ <Option type="2" />
+ <Option compiler="gcc" />
+ <Option createDefFile="1" />
+ <Compiler>
+ <Add option="-Os" />
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ <Target title="test-Debug">
+ <Option output="..\..\testSOIL" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="..\..\" />
+ <Option object_output="obj\" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O" />
+ <Add option="-pg" />
+ <Add option="-g" />
+ </Compiler>
+ <Linker>
+ <Add option="-pg -lgmon" />
+ <Add library="opengl32" />
+ <Add library="gdi32" />
+ </Linker>
+ </Target>
+ <Target title="test-Release">
+ <Option output="..\..\testSOIL" prefix_auto="1" extension_auto="1" />
+ <Option working_dir="..\..\" />
+ <Option object_output="obj\" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-Os" />
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ <Add library="opengl32" />
+ <Add library="gdi32" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ </Compiler>
+ <Unit filename="..\..\src\SOIL.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="..\..\src\SOIL.h" />
+ <Unit filename="..\..\src\image_DXT.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="..\..\src\image_DXT.h" />
+ <Unit filename="..\..\src\image_helper.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="..\..\src\image_helper.h" />
+ <Unit filename="..\..\src\stb_image_aug.c">
+ <Option compilerVar="CC" />
+ </Unit>
+ <Unit filename="..\..\src\stb_image_aug.h" />
+ <Unit filename="..\..\src\stbi_DDS_aug.h" />
+ <Unit filename="..\..\src\stbi_DDS_aug_c.h" />
+ <Unit filename="..\..\src\test_SOIL.cpp">
+ <Option target="test-Debug" />
+ <Option target="test-Release" />
+ </Unit>
+ <Extensions>
+ <code_completion />
+ <envvars />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
320 soil.html
@@ -0,0 +1,320 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
+<HTML>
+<HEAD>
+ <META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
+ <TITLE>lonesock.net: SOIL</TITLE>
+<style type="text/css">
+<!--
+body { color: #000000; background-color: #FFFFFF; }
+.style1 { color: #505050; }
+.style2 { color: #A0A0A0; }
+.style3 { color: #8080FF; font-weight: bold; }
+.style15 { color: #8080FF; font-weight: bold; }
+.style17 { color: #008080; }
+.style18 { color: #800000; }
+.style4 { color: #F000F0; }
+.style5 { color: #0000A0; font-weight: bold; }
+.style16 { color: #00A000; font-weight: bold; }
+.style6 { color: #0000FF; }
+.style12 { color: #0000FF; }
+.style7 { color: #E0A000; }
+.style8 { color: #000000; }
+.style9 { color: #00A000; }
+.style10 { color: #FF0000; }
+.style34 { color: #000000; background-color: #80FFFF; font-weight: bold; }
+.style35 { color: #FFFFFF; background-color: #FF0000; font-weight: bold; }
+--></style>
+</HEAD>
+<BODY LANG="en-US" DIR="LTR">
+<PRE STYLE="margin-bottom: 0.2in; text-align: center">
+<FONT SIZE=4 STYLE="font-size: 16pt"><B>Simple OpenGL Image Library</B></FONT>
+</PRE>
+<P>
+<B>Introduction:</B><BR><BR>SOIL is a tiny C library used primarily
+for uploading textures into OpenGL. It is based on stb_image version
+1.16, the public domain code from Sean Barrett (found <A HREF="http://www.nothings.org/stb_image.c">here</A>).
+I have extended it to load TGA and DDS files, and to perform common
+functions needed in loading OpenGL textures. SOIL can also be used
+to save and load images in a variety of formats (useful for loading
+height maps, non-OpenGL applications, etc.)<BR>
+<BR>
+<B>Download:</B>
+<BR>
+<BR>
+You can grab the latest version of SOIL <A HREF="http://www.lonesock.net/files/soil.zip">here</A>.
+(July 7, 2008: see the change log at the bottom of this page.)<BR>
+You can also checkout the latest code from the new SVN repository, login as guest/guest:<BR>
+<A HREF="svn://www.twisted-works.com/jdummer/public/SOIL">svn://www.twisted-works.com/jdummer/public/SOIL</A><BR>
+(thanks for the SVN hosting, Sherief!)
+<BR>
+<BR>
+<B>License:</B>
+<BR>
+<BR>
+Public Domain
+<BR>
+<BR>
+<B>Features:</B>
+</P>
+<UL>
+ <LI>Readable Image Formats:
+ <UL>
+ <LI>BMP - non-1bpp, non-RLE (from stb_image documentation)
+ <LI>PNG - non-interlaced (from stb_image documentation)
+ <LI>JPG - JPEG baseline (from stb_image documentation)
+ <LI>TGA - greyscale or RGB or RGBA or indexed, uncompressed or RLE
+ <LI>DDS - DXT1/2/3/4/5, uncompressed, cubemaps (can't read 3D DDS files yet)
+ <LI>PSD - (from stb_image documentation)
+ <LI>HDR - converted to LDR, unless loaded with *HDR* functions (RGBE or RGBdivA or RGBdivA2)
+ </UL>
+ <LI>Writeable Image Formats:
+ <UL>
+ <LI>TGA - Greyscale or RGB or RGBA, uncompressed
+ <LI>BMP - RGB, uncompressed
+ <LI>DDS - RGB as DXT1, or RGBA as DXT5
+ </UL>
+ <LI>Can load an image file directly into a 2D OpenGL texture, optionally performing the following functions:
+ <UL>
+ <LI>Can generate a new texture handle, or reuse one specified
+ <LI>Can automatically rescale the image to the next largest power-of-two size
+ <LI>Can automatically create MIPmaps
+ <LI>Can scale (not simply clamp) the RGB values into the "safe range" for NTSC displays (16 to 235, as recommended <a href="http://msdn2.microsoft.com/en-us/library/bb174608.aspx#NTSC_Suggestions">here</a>)
+ <LI>Can multiply alpha on load (for more correct blending / compositing)
+ <LI>Can flip the image vertically
+ <LI>Can compress and upload any image as DXT1 or DXT5 (if EXT_texture_compression_s3tc is available), using an internal (very fast!) compressor
+ <LI>Can convert the RGB to YCoCg color space (useful with DXT5 compression: see <a href="http://developer.nvidia.com/object/real-time-ycocg-dxt-compression.html">this link</a> from NVIDIA)
+ <LI>Will automatically downsize a texture if it is larger than GL_MAX_TEXTURE_SIZE
+ <LI>Can directly upload DDS files (DXT1/3/5/uncompressed/cubemap, with or without MIPmaps). Note: directly uploading the compressed DDS image will disable the other options (no flipping, no pre-multiplying alpha, no rescaling, no creation of MIPmaps, no auto-downsizing)
+ <LI>Can load rectangluar textures for GUI elements or splash screens (requires GL_ARB/EXT/NV_texture_rectangle)
+ </UL>
+ <LI>Can decompress images from RAM (e.g. via <a href="http://icculus.org/physfs/">PhysicsFS</a> or similar) into an OpenGL texture (same features as regular 2D textures, above)
+ <LI>Can load cube maps directly into an OpenGL texture (same features as regular 2D textures, above)
+ <UL>
+ <LI>Can take six image files directly into an OpenGL cube map texture
+ <LI>Can take a single image file where width = 6*height (or vice versa), split it into an OpenGL cube map texture
+ </UL>
+ <LI>No external dependencies
+ <LI>Tiny
+ <LI>Cross platform (Windows, *nix, Mac OS X)
+ <LI>Public Domain
+</UL>
+
+<PRE STYLE="margin-bottom: 0.2in"><B>ToDo:</B></PRE>
+<UL>
+ <LI>More testing
+ <LI>add HDR functions to load from memory and load to RGBE unsigned char*
+</UL>
+<P><BR><B>Usage:</B><BR><BR>SOIL is meant to be used as a static
+library (as it's tiny and in the public domain). You can use the static
+library file included in the zip (libSOIL.a works for MinGW and Microsoft
+compilers...feel free to rename it to SOIL.lib if that makes you happy),
+or compile the library yourself. The code is cross-platform and has been
+tested on Windows, Linux, and Mac. (The heaviest testing has been on the
+Windows platform, so feel free to email me if you find any issues with
+other platforms.)
+<BR><BR>Simply include SOIL.h in your C or C++ file,
+link in the static library, and then use any of SOIL's functions. The
+file SOIL.h contains simple doxygen style documentation. (If you use the
+static library, no other header files are needed besides SOIL.h) Below
+are some simple usage examples:
+</P>
+<pre>
+<code><span style="font: 8pt Courier New;"><span class="style1">/* load an image file directly as a new OpenGL texture */
+</span><span class="style11">GLuint tex_2d </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_texture
+ </span><span class="style10">(
+ </span><span class="style6">"img.png"</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_AUTO</span><span class="style10">,
+ </span><span class="style11">SOIL_CREATE_NEW_ID</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_MIPMAPS </span><span class="style10">| </span><span class="style11">SOIL_FLAG_INVERT_Y </span><span class="style10">| </span><span class="style11">SOIL_FLAG_NTSC_SAFE_RGB </span><span class="style10">| </span><span class="style11">SOIL_FLAG_COMPRESS_TO_DXT
+ </span><span class="style10">);
+
+</span><span class="style1">/* check for an error during the load process */
+</span><span class="style5">if</span><span class="style10">( </span><span class="style4">0 </span><span class="style10">== </span><span class="style11">tex_2d </span><span class="style10">)
+{
+ </span><span class="style11">printf</span><span class="style10">( </span><span class="style6">"SOIL loading error: '%s'\n"</span><span class="style10">, </span><span class="style11">SOIL_last_result</span><span class="style10">() );
+}
+
+</span><span class="style1">/* load another image, but into the same texture ID, overwriting the last one */
+</span><span class="style11">tex_2d </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_texture
+ </span><span class="style10">(
+ </span><span class="style6">"some_other_img.dds"</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_AUTO</span><span class="style10">,
+ </span><span class="style11">tex_2d</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_DDS_LOAD_DIRECT
+ </span><span class="style10">);
+
+</span><span class="style1">/* load 6 images into a new OpenGL cube map, forcing RGB */
+</span><span class="style11">GLuint tex_cube </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_cubemap
+ </span><span class="style10">(
+ </span><span class="style6">"xp.jpg"</span><span class="style10">,
+ </span><span class="style6">"xn.jpg"</span><span class="style10">,
+ </span><span class="style6">"yp.jpg"</span><span class="style10">,
+ </span><span class="style6">"yn.jpg"</span><span class="style10">,
+ </span><span class="style6">"zp.jpg"</span><span class="style10">,
+ </span><span class="style6">"zn.jpg"</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_RGB</span><span class="style10">,
+ </span><span class="style11">SOIL_CREATE_NEW_ID</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_MIPMAPS
+ </span><span class="style10">);
+
+</span><span class="style1">/* load and split a single image into a new OpenGL cube map, default format */
+</span><span class="style1">/* face order = East South West North Up Down => "ESWNUD", case sensitive! */
+</span><span class="style11">GLuint single_tex_cube </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_single_cubemap
+ </span><span class="style10">(
+ </span><span class="style6">"split_cubemap.png"</span><span class="style10">,
+ </span><span class="style6">"EWUDNS"</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_AUTO</span><span class="style10">,
+ </span><span class="style11">SOIL_CREATE_NEW_ID</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_MIPMAPS
+ </span><span class="style10">);
+
+</span><span class="style1">/* actually, load a DDS cubemap over the last OpenGL cube map, default format */
+</span><span class="style1">/* try to load it directly, but give the order of the faces in case that fails */
+</span><span class="style1">/* the DDS cubemap face order is pre-defined as SOIL_DDS_CUBEMAP_FACE_ORDER */
+</span><span class="style11">single_tex_cube </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_single_cubemap
+ </span><span class="style10">(
+ </span><span class="style6">"overwrite_cubemap.dds"</span><span class="style10">,
+ </span><span class="style11">SOIL_DDS_CUBEMAP_FACE_ORDER</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_AUTO</span><span class="style10">,
+ </span><span class="style11">single_tex_cube</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_MIPMAPS | SOIL_FLAG_DDS_LOAD_DIRECT
+ </span><span class="style10">);
+
+</span><span class="style1">/* load an image as a heightmap, forcing greyscale (so channels should be 1) */
+</span><span class="style5">int </span><span class="style11">width</span><span class="style10">, </span><span class="style11">height</span><span class="style10">, </span><span class="style11">channels</span><span class="style10">;
+</span><span class="style5">unsigned char </span><span class="style10">*</span><span class="style11">ht_map </span><span class="style10">= </span><span class="style11">SOIL_load_image
+ </span><span class="style10">(
+ </span><span class="style6">"terrain.tga"</span><span class="style10">,
+ &amp;</span><span class="style11">width</span><span class="style10">, &amp;</span><span class="style11">height</span><span class="style10">, &amp;</span><span class="style11">channels</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_L
+ </span><span class="style10">);
+
+</span><span class="style1">/* save that image as another type */
+</span><span class="style5">int </span><span class="style11">save_result </span><span class="style10">= </span><span class="style11">SOIL_save_image
+ </span><span class="style10">(
+ </span><span class="style6">"new_terrain.dds"</span><span class="style10">,
+ </span><span class="style11">SOIL_SAVE_TYPE_DDS</span><span class="style10">,
+ </span><span class="style11">width</span><span class="style10">, </span><span class="style11">height</span><span class="style10">, </span><span class="style11">channels</span><span class="style10">,
+ </span><span class="style11">ht_map
+ </span><span class="style10">);
+
+</span><span class="style1">/* save a screenshot of your awesome OpenGL game engine, running at 1024x768 */
+</span><span class="style11">save_result </span><span class="style10">= </span><span class="style11">SOIL_save_screenshot
+ </span><span class="style10">(
+ </span><span class="style6">"awesomenessity.bmp"</span><span class="style10">,
+ </span><span class="style11">SOIL_SAVE_TYPE_BMP</span><span class="style10">,
+ </span><span class="style4">0</span><span class="style10">, </span><span class="style4">0</span><span class="style10">, </span><span class="style4">1024</span><span class="style10">, </span><span class="style4">768
+ </span><span class="style10">);
+
+</span><span class="style1">/* loaded a file via PhysicsFS, need to decompress the image from RAM, */
+</span><span class="style1">/* where it's in a buffer: unsigned char *image_in_RAM */
+</span><span class="style11">GLuint tex_2d_from_RAM </span><span class="style10">= </span><span class="style11">SOIL_load_OGL_texture_from_memory
+ </span><span class="style10">(
+ </span><span class="style11">image_in_RAM</span><span class="style10">,
+ </span><span class="style11">image_in_RAM_bytes</span><span class="style10">,
+ </span><span class="style11">SOIL_LOAD_AUTO</span><span class="style10">,
+ </span><span class="style11">SOIL_CREATE_NEW_ID</span><span class="style10">,
+ </span><span class="style11">SOIL_FLAG_MIPMAPS </span><span class="style10">| </span><span class="style11">SOIL_FLAG_INVERT_Y </span><span class="style10">| </span><span class="style11">SOIL_FLAG_COMPRESS_TO_DXT
+ </span><span class="style10">);
+
+</span><span class="style1">/* done with the heightmap, free up the RAM */
+</span><span class="style11">SOIL_free_image_data</span><span class="style10">( </span><span class="style11">ht_map </span><span class="style10">);</span></span>
+</code></pre>
+<BR>
+<BR>
+<B>Change Log:</B>
+<UL>
+<LI>July 7, 2008
+<UL>
+ <LI>upgraded to stb_image 1.16 (threadsafe! loads PSD and HDR formats)
+ <LI>removed <B>inline</B> keyword from native SOIL functions (thanks Sherief, Boder, Amnesiac5!)
+ <LI>added SOIL_load_OGL_HDR_texture (loads a Radience HDR file into RGBE, RGB/a, RGB/A^2)
+ <LI>fixed a potential bug loading DDS files with a filename
+ <LI>added a VC9 project file (thanks Sherief!)
+</UL>
+<LI>November 10, 2007: added SOIL_FLAG_TEXTURE_RECTANGLE (pixel addressed non POT, useful for GUI, splash screens, etc.). Not useful with cubemaps, and disables repeating and MIPmaps.
+<LI>November 8, 2007
+<UL>
+ <LI>upgraded to stb_image 1.07
+ <LI>fixed some includes and defines for compiling on OS X (thanks Mogui and swiftcoder!)
+</UL>
+<LI>October 30, 2007
+<UL>
+ <LI>upgraded to stb_image 1.04, some tiny bug fixes
+ <LI>there is now a makefile (under projects) for ease of building under Linux (thanks D J Peters!)
+ <LI>Visual Studio 6/2003/2005 projects are working again
+ <LI>patched SOIL for better pointer handling of the glCompressedTexImage2D extension (thanks Peter Sperl!)
+ <LI>fixed DDS loading when force_channels=4 but there was no alpha; it was returning 3 channels. (Thanks LaurentGom!)
+ <LI>fixed a bunch of channel issues in general. (Thanks Sean Barrett!)
+</UL>
+<LI>October 27, 2007
+<UL>
+ <LI>correctly reports when there is no OpenGL context (thanks Merick Zero!)
+ <LI>upgraded to stb_image 1.03 with support for loading the HDR image format
+ <LI>fixed loading JPEG images while forcing the number of channels (e.g. to RGBA)
+ <LI>changed SOIL_DDS_CUBEMAP_FACE_ORDER to a #define (thanks Dancho!)
+ <LI>reorganized my additions to stb_image (you can define STBI_NO_DDS to compile SOIL without DDS support)
+ <LI>added SOIL_FLAG_CoCg_Y, will convert RGB or RGBA to YCoCg color space (<a href="http://developer.nvidia.com/object/real-time-ycocg-dxt-compression.html">link</a>)
+</UL>
+<LI>October 5, 2007
+<UL>
+ <LI>added SOIL_FLAG_NTSC_SAFE_RGB
+ <LI>bugfixed & optimized up_scale_image (used with SOIL_FLAG_POWER_OF_TWO and SOIL_FLAG_MIPMAPS)
+</UL>
+<LI>September 20, 2007
+<UL>
+ <LI>upgraded to stb_image 1.0
+ <LI>added the DXT source files to the MSVS projects
+ <LI>removed sqrtf() calls (VS2k3 could not handle them)
+ <LI>distributing only 1 library file (libSOIL.a, compiled with MinGW 4.2.1 tech preview!) for all windows compilers
+ <LI>added an example of the *_from_memory() functions to the Usage section
+</UL>
+<LI>September 6, 2007
+<UL>
+ <LI>added a slew of SOIL_load_*_from_memory() functions for people using PhysicsFS or similar
+ <LI>more robust loading of non-compliant DDS files (thanks Dan!)
+</UL>
+<LI>September 1, 2007 - fixed bugs from the last update [8^)
+<LI>August 31, 2007
+<UL>
+ <LI>can load uncompressed and cubemap DDS files
+ <LI>can create a cubemap texture from a single (stitched) image file of any type
+ <LI>sped up the image resizing code
+</UL>
+<LI>August 24, 2007 - updated the documentation examples (at the bottom of this page)
+<LI>August 22, 2007
+<UL>
+ <LI>can load cube maps (needs serious testing)
+ <LI>can compress 1- or 2-channel images to DXT1/5
+ <LI>fixed some malloc() casts
+ <LI>fixed C++ style comments
+ <LI>fixed includes to compile under *nix or Mac (hopefully, needs testing...any volunteers?)
+</UL>
+<LI>August 16, 2007
+<UL>
+ <LI>Will now downsize the image if necessary to fit GL_MAX_TEXTURE_SIZE
+ <LI>added SOIL_create_OGL_texture() to upload raw image data that isn't from an image file
+</UL>
+<LI>August 14, 2007 (PM) - Can now load indexed TGA
+<LI>August 14, 2007 (AM)
+<UL>
+ <LI>Updated to stb_image 0.97
+ <LI>added result messages
+ <LI>can now decompress DDS files (DXT1/2/3/4/5)
+</UL>
+<LI>August 11, 2007 - MIPmaps can now handle non-square textures
+<LI>August 7, 2007
+<UL>
+ <LI>Can directly upload DXT1/3/5 DDS files (with or w/o MIPmaps)
+ <LI>can compress any image to DXT1/5 (using a new &amp; fast &amp; simple compression scheme) and upload
+ <LI>can save as DDS
+</UL>
+<LI>July 31, 2007 - added compressing to DXT and flipping about Y
+<LI>July 30, 2007 - initial release
+</UL>
+<BR>
+<BR>
+<PRE STYLE="text-align: center">back to
+<A HREF="http://www.lonesock.net/">www.lonesock.net</A></PRE>
+</BODY>
+</HTML>
2,024 src/SOIL.c
@@ -0,0 +1,2024 @@
+/*
+ Jonathan Dummer
+ 2007-07-26-10.36
+
+ Simple OpenGL Image Library
+
+ Public Domain
+ using Sean Barret's stb_image as a base
+
+ Thanks to:
+ * Sean Barret - for the awesome stb_image
+ * Dan Venkitachalam - for finding some non-compliant DDS files, and patching some explicit casts
+ * everybody at gamedev.net
+*/
+
+#define SOIL_CHECK_FOR_GL_ERRORS 0
+
+#ifdef WIN32
+ #define WIN32_LEAN_AND_MEAN
+ #include <windows.h>
+ #include <wingdi.h>
+ #include <GL/gl.h>
+#elif defined(__APPLE__) || defined(__APPLE_CC__)
+ /* I can't test this Apple stuff! */
+ #include <OpenGL/gl.h>
+ #include <Carbon/Carbon.h>
+ #define APIENTRY
+#else
+ #include <GL/gl.h>
+ #include <GL/glx.h>
+#endif
+
+#include "SOIL.h"
+#include "stb_image_aug.h"
+#include "image_helper.h"
+#include "image_DXT.h"
+
+#include <stdlib.h>
+#include <string.h>
+
+/* error reporting */
+char *result_string_pointer = "SOIL initialized";
+
+/* for loading cube maps */
+enum{
+ SOIL_CAPABILITY_UNKNOWN = -1,
+ SOIL_CAPABILITY_NONE = 0,
+ SOIL_CAPABILITY_PRESENT = 1
+};
+static int has_cubemap_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_cubemap_capability( void );
+#define SOIL_TEXTURE_WRAP_R 0x8072
+#define SOIL_CLAMP_TO_EDGE 0x812F
+#define SOIL_NORMAL_MAP 0x8511
+#define SOIL_REFLECTION_MAP 0x8512
+#define SOIL_TEXTURE_CUBE_MAP 0x8513
+#define SOIL_TEXTURE_BINDING_CUBE_MAP 0x8514
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_X 0x8515
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X 0x8516
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y 0x8517
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y 0x8518
+#define SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z 0x8519
+#define SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z 0x851A
+#define SOIL_PROXY_TEXTURE_CUBE_MAP 0x851B
+#define SOIL_MAX_CUBE_MAP_TEXTURE_SIZE 0x851C
+/* for non-power-of-two texture */
+static int has_NPOT_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_NPOT_capability( void );
+/* for texture rectangles */
+static int has_tex_rectangle_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_tex_rectangle_capability( void );
+#define SOIL_TEXTURE_RECTANGLE_ARB 0x84F5
+#define SOIL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8
+/* for using DXT compression */
+static int has_DXT_capability = SOIL_CAPABILITY_UNKNOWN;
+int query_DXT_capability( void );
+#define SOIL_RGB_S3TC_DXT1 0x83F0
+#define SOIL_RGBA_S3TC_DXT1 0x83F1
+#define SOIL_RGBA_S3TC_DXT3 0x83F2
+#define SOIL_RGBA_S3TC_DXT5 0x83F3
+typedef void (APIENTRY * P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC) (GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const GLvoid * data);
+P_SOIL_GLCOMPRESSEDTEXIMAGE2DPROC soilGlCompressedTexImage2D = NULL;
+unsigned int SOIL_direct_load_DDS(
+ const char *filename,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
+unsigned int SOIL_direct_load_DDS_from_memory(
+ const unsigned char *const buffer,
+ int buffer_length,
+ unsigned int reuse_texture_ID,
+ int flags,
+ int loading_as_cubemap );
+/* other functions */
+unsigned int
+ SOIL_internal_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags,
+ unsigned int opengl_texture_type,
+ unsigned int opengl_texture_target,
+ unsigned int texture_check_size_enum
+ );
+
+/* and the code magic begins here [8^) */
+unsigned int
+ SOIL_load_OGL_texture
+ (
+ const char *filename,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 0 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* try to load the image */
+ img = SOIL_load_image( filename, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_HDR_texture
+ (
+ const char *filename,
+ int fake_HDR_format,
+ int rescale_to_max,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* no direct uploading of the image as a DDS file */
+ /* error check */
+ if( (fake_HDR_format != SOIL_HDR_RGBE) &&
+ (fake_HDR_format != SOIL_HDR_RGBdivA) &&
+ (fake_HDR_format != SOIL_HDR_RGBdivA2) )
+ {
+ result_string_pointer = "Invalid fake HDR format specified";
+ return 0;
+ }
+ /* try to load the image (only the HDR type) */
+ img = stbi_hdr_load_rgbe( filename, &width, &height, &channels, 4 );
+ /* channels holds the original number of channels, which may have been forced */
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* the load worked, do I need to convert it? */
+ if( fake_HDR_format == SOIL_HDR_RGBdivA )
+ {
+ RGBE_to_RGBdivA( img, width, height, rescale_to_max );
+ } else if( fake_HDR_format == SOIL_HDR_RGBdivA2 )
+ {
+ RGBE_to_RGBdivA2( img, width, height, rescale_to_max );
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_texture_from_memory
+ (
+ const unsigned char *const buffer,
+ int buffer_length,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS_from_memory(
+ buffer, buffer_length,
+ reuse_texture_ID, flags, 0 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* try to load the image */
+ img = SOIL_load_image_from_memory(
+ buffer, buffer_length,
+ &width, &height, &channels,
+ force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* OK, make it a texture! */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_cubemap
+ (
+ const char *x_pos_file,
+ const char *x_neg_file,
+ const char *y_pos_file,
+ const char *y_neg_file,
+ const char *z_pos_file,
+ const char *z_neg_file,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* error checking */
+ if( (x_pos_file == NULL) ||
+ (x_neg_file == NULL) ||
+ (y_pos_file == NULL) ||
+ (y_neg_file == NULL) ||
+ (z_pos_file == NULL) ||
+ (z_neg_file == NULL) )
+ {
+ result_string_pointer = "Invalid cube map files list";
+ return 0;
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( x_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, and create a texture ID if necessary */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( x_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( y_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( y_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( z_pos_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image( z_neg_file, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_cubemap_from_memory
+ (
+ const unsigned char *const x_pos_buffer,
+ int x_pos_buffer_length,
+ const unsigned char *const x_neg_buffer,
+ int x_neg_buffer_length,
+ const unsigned char *const y_pos_buffer,
+ int y_pos_buffer_length,
+ const unsigned char *const y_neg_buffer,
+ int y_neg_buffer_length,
+ const unsigned char *const z_pos_buffer,
+ int z_pos_buffer_length,
+ const unsigned char *const z_neg_buffer,
+ int z_neg_buffer_length,
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels;
+ unsigned int tex_id;
+ /* error checking */
+ if( (x_pos_buffer == NULL) ||
+ (x_neg_buffer == NULL) ||
+ (y_pos_buffer == NULL) ||
+ (y_neg_buffer == NULL) ||
+ (z_pos_buffer == NULL) ||
+ (z_neg_buffer == NULL) )
+ {
+ result_string_pointer = "Invalid cube map buffers list";
+ return 0;
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ x_pos_buffer, x_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, and create a texture ID if necessary */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ reuse_texture_ID, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ x_neg_buffer, x_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ y_pos_buffer, y_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ y_neg_buffer, y_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ z_pos_buffer, z_pos_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* continue? */
+ if( tex_id != 0 )
+ {
+ /* 1st face: try to load the image */
+ img = SOIL_load_image_from_memory(
+ z_neg_buffer, z_neg_buffer_length,
+ &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* upload the texture, but reuse the assigned texture ID */
+ tex_id = SOIL_internal_create_OGL_texture(
+ img, width, height, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP, SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ /* and nuke the image data */
+ SOIL_free_image_data( img );
+ }
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_single_cubemap
+ (
+ const char *filename,
+ const char face_order[6],
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels, i;
+ unsigned int tex_id = 0;
+ /* error checking */
+ if( filename == NULL )
+ {
+ result_string_pointer = "Invalid single cube map file name";
+ return 0;
+ }
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS( filename, reuse_texture_ID, flags, 1 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st off, try to load the full image */
+ img = SOIL_load_image( filename, &width, &height, &channels, force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ SOIL_free_image_data( img );
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* try the image split and create */
+ tex_id = SOIL_create_OGL_single_cubemap(
+ img, width, height, channels,
+ face_order, reuse_texture_ID, flags
+ );
+ /* nuke the temporary image data and return the texture handle */
+ SOIL_free_image_data( img );
+ return tex_id;
+}
+
+unsigned int
+ SOIL_load_OGL_single_cubemap_from_memory
+ (
+ const unsigned char *const buffer,
+ int buffer_length,
+ const char face_order[6],
+ int force_channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* img;
+ int width, height, channels, i;
+ unsigned int tex_id = 0;
+ /* error checking */
+ if( buffer == NULL )
+ {
+ result_string_pointer = "Invalid single cube map buffer";
+ return 0;
+ }
+ /* does the user want direct uploading of the image as a DDS file? */
+ if( flags & SOIL_FLAG_DDS_LOAD_DIRECT )
+ {
+ /* 1st try direct loading of the image as a DDS file
+ note: direct uploading will only load what is in the
+ DDS file, no MIPmaps will be generated, the image will
+ not be flipped, etc. */
+ tex_id = SOIL_direct_load_DDS_from_memory(
+ buffer, buffer_length,
+ reuse_texture_ID, flags, 1 );
+ if( tex_id )
+ {
+ /* hey, it worked!! */
+ return tex_id;
+ }
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* 1st off, try to load the full image */
+ img = SOIL_load_image_from_memory(
+ buffer, buffer_length,
+ &width, &height, &channels,
+ force_channels );
+ /* channels holds the original number of channels, which may have been forced */
+ if( (force_channels >= 1) && (force_channels <= 4) )
+ {
+ channels = force_channels;
+ }
+ if( NULL == img )
+ {
+ /* image loading failed */
+ result_string_pointer = stbi_failure_reason();
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ SOIL_free_image_data( img );
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* try the image split and create */
+ tex_id = SOIL_create_OGL_single_cubemap(
+ img, width, height, channels,
+ face_order, reuse_texture_ID, flags
+ );
+ /* nuke the temporary image data and return the texture handle */
+ SOIL_free_image_data( img );
+ return tex_id;
+}
+
+unsigned int
+ SOIL_create_OGL_single_cubemap
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ const char face_order[6],
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* variables */
+ unsigned char* sub_img;
+ int dw, dh, sz, i;
+ unsigned int tex_id;
+ /* error checking */
+ if( data == NULL )
+ {
+ result_string_pointer = "Invalid single cube map image data";
+ return 0;
+ }
+ /* face order checking */
+ for( i = 0; i < 6; ++i )
+ {
+ if( (face_order[i] != 'N') &&
+ (face_order[i] != 'S') &&
+ (face_order[i] != 'W') &&
+ (face_order[i] != 'E') &&
+ (face_order[i] != 'U') &&
+ (face_order[i] != 'D') )
+ {
+ result_string_pointer = "Invalid single cube map face order";
+ return 0;
+ };
+ }
+ /* capability checking */
+ if( query_cubemap_capability() != SOIL_CAPABILITY_PRESENT )
+ {
+ result_string_pointer = "No cube map capability present";
+ return 0;
+ }
+ /* now, does this image have the right dimensions? */
+ if( (width != 6*height) &&
+ (6*width != height) )
+ {
+ result_string_pointer = "Single cubemap image must have a 6:1 ratio";
+ return 0;
+ }
+ /* which way am I stepping? */
+ if( width > height )
+ {
+ dw = height;
+ dh = 0;
+ } else
+ {
+ dw = 0;
+ dh = width;
+ }
+ sz = dw+dh;
+ sub_img = (unsigned char *)malloc( sz*sz*channels );
+ /* do the splitting and uploading */
+ tex_id = reuse_texture_ID;
+ for( i = 0; i < 6; ++i )
+ {
+ int x, y, idx = 0;
+ unsigned int cubemap_target = 0;
+ /* copy in the sub-image */
+ for( y = i*dh; y < i*dh+sz; ++y )
+ {
+ for( x = i*dw*channels; x < (i*dw+sz)*channels; ++x )
+ {
+ sub_img[idx++] = data[y*width*channels+x];
+ }
+ }
+ /* what is my texture target?
+ remember, this coordinate system is
+ LHS if viewed from inside the cube! */
+ switch( face_order[i] )
+ {
+ case 'N':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Z;
+ break;
+ case 'S':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
+ break;
+ case 'W':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_X;
+ break;
+ case 'E':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ break;
+ case 'U':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_POSITIVE_Y;
+ break;
+ case 'D':
+ cubemap_target = SOIL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
+ break;
+ }
+ /* upload it as a texture */
+ tex_id = SOIL_internal_create_OGL_texture(
+ sub_img, sz, sz, channels,
+ tex_id, flags,
+ SOIL_TEXTURE_CUBE_MAP,
+ cubemap_target,
+ SOIL_MAX_CUBE_MAP_TEXTURE_SIZE );
+ }
+ /* and nuke the image and sub-image data */
+ SOIL_free_image_data( sub_img );
+ /* and return the handle, such as it is */
+ return tex_id;
+}
+
+unsigned int
+ SOIL_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags
+ )
+{
+ /* wrapper function for 2D textures */
+ return SOIL_internal_create_OGL_texture(
+ data, width, height, channels,
+ reuse_texture_ID, flags,
+ GL_TEXTURE_2D, GL_TEXTURE_2D,
+ GL_MAX_TEXTURE_SIZE );
+}
+
+#if SOIL_CHECK_FOR_GL_ERRORS
+void check_for_GL_errors( const char *calling_location )
+{
+ /* check for errors */
+ GLenum err_code = glGetError();
+ while( GL_NO_ERROR != err_code )
+ {
+ printf( "OpenGL Error @ %s: %i", calling_location, err_code );
+ err_code = glGetError();
+ }
+}
+#else
+void check_for_GL_errors( const char *calling_location )
+{
+ /* no check for errors */
+}
+#endif
+
+unsigned int
+ SOIL_internal_create_OGL_texture
+ (
+ const unsigned char *const data,
+ int width, int height, int channels,
+ unsigned int reuse_texture_ID,
+ unsigned int flags,
+ unsigned int opengl_texture_type,
+ unsigned int opengl_texture_target,
+ unsigned int texture_check_size_enum
+ )
+{
+ /* variables */
+ unsigned char* img;
+ unsigned int tex_id;
+ unsigned int internal_texture_format = 0, original_texture_format = 0;
+ int DXT_mode = SOIL_CAPABILITY_UNKNOWN;
+ int max_supported_size;
+ /* If the user wants to use the texture rectangle I kill a few flags */
+ if( flags & SOIL_FLAG_TEXTURE_RECTANGLE )
+ {
+ /* well, the user asked for it, can we do that? */
+ if( query_tex_rectangle_capability() == SOIL_CAPABILITY_PRESENT )
+ {
+ /* only allow this if the user in _NOT_ trying to do a cubemap! */
+ if( opengl_texture_type == GL_TEXTURE_2D )
+ {
+ /* clean out the flags that cannot be used with texture rectangles */
+ flags &= ~(
+ SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS |
+ SOIL_FLAG_TEXTURE_REPEATS
+ );
+ /* and change my target */
+ opengl_texture_target = SOIL_TEXTURE_RECTANGLE_ARB;
+ opengl_texture_type = SOIL_TEXTURE_RECTANGLE_ARB;
+ } else
+ {
+ /* not allowed for any other uses (yes, I'm looking at you, cubemaps!) */
+ flags &= ~SOIL_FLAG_TEXTURE_RECTANGLE;
+ }
+
+ } else
+ {
+ /* can't do it, and that is a breakable offense (uv coords use pixels instead of [0,1]!) */
+ result_string_pointer = "Texture Rectangle extension unsupported";
+ return 0;
+ }
+ }
+ /* create a copy the image data */
+ img = (unsigned char*)malloc( width*height*channels );
+ memcpy( img, data, width*height*channels );
+ /* does the user want me to invert the image? */
+ if( flags & SOIL_FLAG_INVERT_Y )
+ {
+ int i, j;
+ for( j = 0; j*2 < height; ++j )
+ {
+ int index1 = j * width * channels;
+ int index2 = (height - 1 - j) * width * channels;
+ for( i = width * channels; i > 0; --i )
+ {
+ unsigned char temp = img[index1];
+ img[index1] = img[index2];
+ img[index2] = temp;
+ ++index1;
+ ++index2;
+ }
+ }
+ }
+ /* does the user want me to scale the colors into the NTSC safe RGB range? */
+ if( flags & SOIL_FLAG_NTSC_SAFE_RGB )
+ {
+ scale_image_RGB_to_NTSC_safe( img, width, height, channels );
+ }
+ /* does the user want me to convert from straight to pre-multiplied alpha?
+ (and do we even _have_ alpha?) */
+ if( flags & SOIL_FLAG_MULTIPLY_ALPHA )
+ {
+ int i;
+ switch( channels )
+ {
+ case 2:
+ for( i = 0; i < 2*width*height; i += 2 )
+ {
+ img[i] = (img[i] * img[i+1] + 128) >> 8;
+ }
+ break;
+ case 4:
+ for( i = 0; i < 4*width*height; i += 4 )
+ {
+ img[i+0] = (img[i+0] * img[i+3] + 128) >> 8;
+ img[i+1] = (img[i+1] * img[i+3] + 128) >> 8;
+ img[i+2] = (img[i+2] * img[i+3] + 128) >> 8;
+ }
+ break;
+ default:
+ /* no other number of channels contains alpha data */
+ break;
+ }
+ }
+ /* if the user can't support NPOT textures, make sure we force the POT option */
+ if( (query_NPOT_capability() == SOIL_CAPABILITY_NONE) &&
+ !(flags & SOIL_FLAG_TEXTURE_RECTANGLE) )
+ {
+ /* add in the POT flag */
+ flags |= SOIL_FLAG_POWER_OF_TWO;
+ }
+ /* how large of a texture can this OpenGL implementation handle? */
+ /* texture_check_size_enum will be GL_MAX_TEXTURE_SIZE or SOIL_MAX_CUBE_MAP_TEXTURE_SIZE */
+ glGetIntegerv( texture_check_size_enum, &max_supported_size );
+ /* do I need to make it a power of 2? */
+ if(
+ (flags & SOIL_FLAG_POWER_OF_TWO) || /* user asked for it */
+ (flags & SOIL_FLAG_MIPMAPS) || /* need it for the MIP-maps */
+ (width > max_supported_size) || /* it's too big, (make sure it's */
+ (height > max_supported_size) ) /* 2^n for later down-sampling) */
+ {
+ int new_width = 1;
+ int new_height = 1;
+ while( new_width < width )
+ {
+ new_width *= 2;
+ }
+ while( new_height < height )
+ {
+ new_height *= 2;
+ }
+ /* still? */
+ if( (new_width != width) || (new_height != height) )
+ {
+ /* yep, resize */
+ unsigned char *resampled = (unsigned char*)malloc( channels*new_width*new_height );
+ up_scale_image(
+ img, width, height, channels,
+ resampled, new_width, new_height );
+ /* OJO this is for debug only! */
+ /*
+ SOIL_save_image( "\\showme.bmp", SOIL_SAVE_TYPE_BMP,
+ new_width, new_height, channels,
+ resampled );
+ */
+ /* nuke the old guy, then point it at the new guy */
+ SOIL_free_image_data( img );
+ img = resampled;
+ width = new_width;
+ height = new_height;
+ }
+ }
+ /* now, if it is too large... */
+ if( (width > max_supported_size) || (height > max_supported_size) )
+ {
+ /* I've already made it a power of two, so simply use the MIPmapping
+ code to reduce its size to the allowable maximum. */
+ unsigned char *resampled;
+ int reduce_block_x = 1, reduce_block_y = 1;
+ int new_width, new_height;
+ if( width > max_supported_size )
+ {
+ reduce_block_x = width / max_supported_size;
+ }
+ if( height > max_supported_size )
+ {
+ reduce_block_y = height / max_supported_size;
+ }
+ new_width = width / reduce_block_x;
+ new_height = height / reduce_block_y;
+ resampled = (unsigned char*)malloc( channels*new_width*new_height );
+ /* perform the actual reduction */
+ mipmap_image( img, width, height, channels,
+ resampled, reduce_block_x, reduce_block_y );
+ /* nuke the old guy, then point it at the new guy */
+ SOIL_free_image_data( img );
+ img = resampled;
+ width = new_width;
+ height = new_height;
+ }
+ /* does the user want us to use YCoCg color space? */
+ if( flags & SOIL_FLAG_CoCg_Y )
+ {
+ /* this will only work with RGB and RGBA images */
+ convert_RGB_to_YCoCg( img, width, height, channels );
+ /*
+ save_image_as_DDS( "CoCg_Y.dds", width, height, channels, img );
+ */
+ }
+ /* create the OpenGL texture ID handle
+ (note: allowing a forced texture ID lets me reload a texture) */
+ tex_id = reuse_texture_ID;
+ if( tex_id == 0 )
+ {
+ glGenTextures( 1, &tex_id );
+ }
+ check_for_GL_errors( "glGenTextures" );
+ /* Note: sometimes glGenTextures fails (usually no OpenGL context) */
+ if( tex_id )
+ {
+ /* and what type am I using as the internal texture format? */
+ switch( channels )
+ {
+ case 1:
+ original_texture_format = GL_LUMINANCE;
+ break;
+ case 2:
+ original_texture_format = GL_LUMINANCE_ALPHA;
+ break;
+ case 3:
+ original_texture_format = GL_RGB;
+ break;
+ case 4:
+ original_texture_format = GL_RGBA;
+ break;
+ }
+ internal_texture_format = original_texture_format;
+ /* does the user want me to, and can I, save as DXT? */
+ if( flags & SOIL_FLAG_COMPRESS_TO_DXT )
+ {
+ DXT_mode = query_DXT_capability();
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* I can use DXT, whether I compress it or OpenGL does */
+ if( (channels & 1) == 1 )
+ {
+ /* 1 or 3 channels = DXT1 */
+ internal_texture_format = SOIL_RGB_S3TC_DXT1;
+ } else
+ {
+ /* 2 or 4 channels = DXT5 */
+ internal_texture_format = SOIL_RGBA_S3TC_DXT5;
+ }
+ }
+ }
+ /* bind an OpenGL texture ID */
+ glBindTexture( opengl_texture_type, tex_id );
+ check_for_GL_errors( "glBindTexture" );
+ /* upload the main image */
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* user wants me to do the DXT conversion! */
+ int DDS_size;
+ unsigned char *DDS_data = NULL;
+ if( (channels & 1) == 1 )
+ {
+ /* RGB, use DXT1 */
+ DDS_data = convert_image_to_DXT1( img, width, height, channels, &DDS_size );
+ } else
+ {
+ /* RGBA, use DXT5 */
+ DDS_data = convert_image_to_DXT5( img, width, height, channels, &DDS_size );
+ }
+ if( DDS_data )
+ {
+ soilGlCompressedTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ DDS_size, DDS_data );
+ check_for_GL_errors( "glCompressedTexImage2D" );
+ SOIL_free_image_data( DDS_data );
+ /* printf( "Internal DXT compressor\n" ); */
+ } else
+ {
+ /* my compression failed, try the OpenGL driver's version */
+ glTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, img );
+ check_for_GL_errors( "glTexImage2D" );
+ /* printf( "OpenGL DXT compressor\n" ); */
+ }
+ } else
+ {
+ /* user want OpenGL to do all the work! */
+ glTexImage2D(
+ opengl_texture_target, 0,
+ internal_texture_format, width, height, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, img );
+ check_for_GL_errors( "glTexImage2D" );
+ /*printf( "OpenGL DXT compressor\n" ); */
+ }
+ /* are any MIPmaps desired? */
+ if( flags & SOIL_FLAG_MIPMAPS )
+ {
+ int MIPlevel = 1;
+ int MIPwidth = (width+1) / 2;
+ int MIPheight = (height+1) / 2;
+ unsigned char *resampled = (unsigned char*)malloc( channels*MIPwidth*MIPheight );
+ while( ((1<<MIPlevel) <= width) || ((1<<MIPlevel) <= height) )
+ {
+ /* do this MIPmap level */
+ mipmap_image(
+ img, width, height, channels,
+ resampled,
+ (1 << MIPlevel), (1 << MIPlevel) );
+ /* upload the MIPmaps */
+ if( DXT_mode == SOIL_CAPABILITY_PRESENT )
+ {
+ /* user wants me to do the DXT conversion! */
+ int DDS_size;
+ unsigned char *DDS_data = NULL;
+ if( (channels & 1) == 1 )
+ {
+ /* RGB, use DXT1 */
+ DDS_data = convert_image_to_DXT1(
+ resampled, MIPwidth, MIPheight, channels, &DDS_size );
+ } else
+ {
+ /* RGBA, use DXT5 */
+ DDS_data = convert_image_to_DXT5(
+ resampled, MIPwidth, MIPheight, channels, &DDS_size );
+ }
+ if( DDS_data )
+ {
+ soilGlCompressedTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ DDS_size, DDS_data );
+ check_for_GL_errors( "glCompressedTexImage2D" );
+ SOIL_free_image_data( DDS_data );
+ } else
+ {
+ /* my compression failed, try the OpenGL driver's version */
+ glTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, resampled );
+ check_for_GL_errors( "glTexImage2D" );
+ }
+ } else
+ {
+ /* user want OpenGL to do all the work! */
+ glTexImage2D(
+ opengl_texture_target, MIPlevel,
+ internal_texture_format, MIPwidth, MIPheight, 0,
+ original_texture_format, GL_UNSIGNED_BYTE, resampled );
+ check_for_GL_errors( "glTexImage2D" );
+ }
+ /* prep for the next level */
+ ++MIPlevel;
+ MIPwidth = (MIPwidth + 1) / 2;
+ MIPheight = (MIPheight + 1) / 2;
+ }
+ SOIL_free_image_data( resampled );
+ /* instruct OpenGL to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR );
+ check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
+ } else
+ {
+ /* instruct OpenGL _NOT_ to use the MIPmaps */
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri( opengl_texture_type, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ check_for_GL_errors( "GL_TEXTURE_MIN/MAG_FILTER" );
+ }
+ /* does the user want clamping, or wrapping? */