diff --git a/Makefile b/Makefile index 7ee244b..6fe71d8 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,16 @@ CC=g++ CFLAGS=-Wall INCLUDES=-Isrc/libs/ -LIBS=-Llib -lglfw3 -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo +LIBS=-Llib -lglfw3 -lSOIL -framework Cocoa -framework OpenGL -framework IOKit -framework CoreVideo + +all: hello_triangle hello_sprite hello_triangle: $(CC) $(INCLUDES) $(CFLAGS) src/examples/01-hello_triangle/main.cpp src/examples/common/util.cpp src/examples/common/shader.cpp -o bin/01-hello_triangle.out $(LIBS) +hello_sprite: + $(CC) $(INCLUDES) $(CFLAGS) src/examples/02-hello_sprite/main.cpp src/examples/common/util.cpp src/examples/common/shader.cpp -o bin/02-hello_sprite.out $(LIBS) + cp src/examples/02-hello_sprite/image.png bin/image.png + clean: rm bin/* diff --git a/README.md b/README.md index f8e0054..a5114b5 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ that compiles and runs on your machine. These examples have some dependencies: * [GLFW 3.1.1](http://www.glfw.org) +* [SOIL](http://www.lonesock.net/soil.html) ## Compiling @@ -26,6 +27,12 @@ Make sure that you have compiled the GLFW dependency for your system as a static library. You should now have a file called `libglfw3.a`. Place this in a subdirectory `lib` of the root folder (on the same level as this `README.md` file). +Download the latest release of SOIL. You can try putting the binary in the `lib` folder, but this +will most likely fail if your computer is from the last few years. You're best off using the supplied +makefile in the `projects/makefile` folder. Note that you need to alter a line if your machine is 64 bit: +change the line that says `CXX = gcc` to `CXX = gcc -arch x86_64`. Run `make` and you will find the new +`libSOIL.a` file in the `lib` subdirectory of the directory where you downloaded SOIL to. + Now you can use the command `make EXAMPLE_NAME` to compile an example. The resulting binaries will be placed in the `build` folder. @@ -37,13 +44,27 @@ domain is not recognized in every country. For more information, read ## Examples +To compile all examples, you can run `make` or `make all`. + ### 01: Hello Triangle **Compile**: `make hello_triangle` -**Run**: `bin/01-hello-triangle.out` +**Run**: `cd bin; 01-hello-triangle.out` This example shows the minimal code needed to render a simple colored triangle. [Code](src/examples/01-hello_triangle) ![hello triangle](img/01-hello_triangle.tiff) + +### 02: Hello Sprite + +**Compile**: `make hello_sprite` +**Run**: `cd bin; 02-hello_sprite.out` + +This example shows the minimal code needed to render a textured quad. It also uses +`glDrawElements` to reduce duplication of vertices. + +[Code](src/examples/02-hello_sprite) + +![hello sprite](img/02-hello_sprite.tiff) diff --git a/bin/image.png b/bin/image.png new file mode 100644 index 0000000..b76f2ab Binary files /dev/null and b/bin/image.png differ diff --git a/img/02-hello_sprite.tiff b/img/02-hello_sprite.tiff new file mode 100644 index 0000000..351ab43 Binary files /dev/null and b/img/02-hello_sprite.tiff differ diff --git a/src/examples/02-hello_sprite/image.png b/src/examples/02-hello_sprite/image.png new file mode 100644 index 0000000..b76f2ab Binary files /dev/null and b/src/examples/02-hello_sprite/image.png differ diff --git a/src/examples/02-hello_sprite/main.cpp b/src/examples/02-hello_sprite/main.cpp new file mode 100644 index 0000000..5a8b45a --- /dev/null +++ b/src/examples/02-hello_sprite/main.cpp @@ -0,0 +1,162 @@ +#include "../common/util.h" +#include "../common/shader.h" + +const char* VERTEX_SRC = "#version 330 core\n" + "layout(location=0) in vec2 position;" // Vertex position (x, y) + "layout(location=1) in vec3 color;" // Vertex color (r, g, b) + "layout(location=2) in vec2 texcoord;" // Texture coordinate (u, v) + "out vec3 fColor;" // Vertex shader has to pass color to fragment shader + "out vec2 fTexcoord;" // Pass to fragment shader + "void main()" + "{" + " fColor = color;" // Pass color to fragment shader + " fTexcoord = texcoord;" // Pass texcoord to fragment shader + " gl_Position=vec4(position, 0.0, 1.0);" // Place vertex at (x, y, 0, 1) + "}"; + +const char* FRAGMENT_SRC = "#version 330 core\n" + "in vec3 fColor;" // From the vertex shader + "in vec2 fTexcoord;" // From the vertex shader + "uniform sampler2D tex;" // The texture + "out vec4 outputColor;" // The color of the resulting fragment + "void main()" + "{" + " outputColor = texture(tex, fTexcoord)" // Color using the color and texutre + " * vec4(fColor, 1.0);" + "}"; + +int main(void) +{ + GLFWwindow* window; + + // The OpenGL context creation code is in + // ../common/util.cpp + window = init("Hello Sprite", 640, 480); + if(!window) + { + return -1; + } + + // We start by creating a vertex and fragment shader + // from the above strings + GLuint vertex = createShader(VERTEX_SRC, GL_VERTEX_SHADER); + if(!vertex) + { + return -1; + } + GLuint fragment = createShader(FRAGMENT_SRC, GL_FRAGMENT_SHADER); + if(!fragment) + { + return -1; + } + // Now we must make a shader program: this program + // contains both the vertex and the fragment shader + GLuint program = createShaderProgram(vertex, fragment); + if(!program) + { + return -1; + } + // We link the program, just like your C compiler links + // .o files + bool result = linkShader(program); + if(!result) + { + return -1; + } + // We make sure the shader is validated + result = validateShader(program); + if(!result) + { + return -1; + } + // Detach and delete the shaders, because we no longer need them + glDetachShader(program, vertex); + glDeleteShader(vertex); + glDetachShader(program, fragment); + glDeleteShader(fragment); + + glUseProgram(program); // Set this as the current shader program + + // We now create the data to send to the GPU + GLuint vao; + glGenVertexArrays(1, &vao); + glBindVertexArray(vao); + + GLuint vbo; + glGenBuffers(1, &vbo); + + float vertices[] = + { + // x y r g b u v + -0.5f, 0.5f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, + 0.5f, 0.5f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, + 0.5f, -0.5f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, + -0.5f, -0.5f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f + }; + + // Upload the vertices to the buffer + glBindBuffer(GL_ARRAY_BUFFER, vbo); + glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW); + + GLuint ebo; + glGenBuffers(1, &ebo); + + GLuint indices[] = + { + 0, 1, 2, + 2, 3, 0 + }; + + // Upload the indices (elements) to the buffer + glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ebo); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(indices), indices, GL_STATIC_DRAW); + + // Enable the vertex attributes and upload their data (see: layout(location=x)) + glEnableVertexAttribArray(0); // position + // 2 floats: x and y, but 7 floats in total per row + glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), 0); + glEnableVertexAttribArray(1); // color + // 3 floats: r, g and b, but 7 floats in total per row and start at the third one + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(2 * sizeof(GLfloat))); + glEnableVertexAttribArray(2); // texture coordinates + // 2 floats: u and v, but 7 floats in total per row and start at the sixth one + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 7 * sizeof(GLfloat), (void*)(5 * sizeof(GLfloat))); + + // We have now successfully created a drawable Vertex Array Object + + // Load the texture and bind it to the uniform + int w, h; + GLuint texture = loadImage("image.png", &w, &h, 0); // GL_TEXTURE0 + if(!texture) + { + return -1; + } + glUniform1i(glGetUniformLocation(program, "tex"), 0); // GL_TEXTURE0 + + // Set the clear color to a light grey + glClearColor(0.75f, 0.75f, 0.75f, 1.0f); + + while(!glfwWindowShouldClose(window)) + { + // Clear + glClear(GL_COLOR_BUFFER_BIT); + + // The VAO is still bound so just draw the 6 vertices + glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0); + + // Tip: if nothing is drawn, check the return value of glGetError and google it + + // Swap buffers to show current image on screen (for more information google 'backbuffer') + glfwSwapBuffers(window); + glfwPollEvents(); + } + + // Clean up + glDeleteBuffers(1, &vbo); + glDeleteBuffers(1, &ebo); + glDeleteVertexArrays(1, &vao); + glDeleteTextures(1, &texture); + + glfwTerminate(); + return 0; +} diff --git a/src/examples/common/util.cpp b/src/examples/common/util.cpp index 389c14d..b9c98b8 100644 --- a/src/examples/common/util.cpp +++ b/src/examples/common/util.cpp @@ -32,5 +32,30 @@ GLFWwindow* init(const char* exampleName, int width, int height) std::cout << "Using OpenGL version " << glGetString(GL_VERSION) << std::endl; + glEnable(GL_TEXTURE_2D); + return window; } + +GLuint loadImage(const char* fileName, int* w, int* h, int index) +{ + GLuint tex; + unsigned char* img = SOIL_load_image(fileName, w, h, NULL, SOIL_LOAD_RGB); + if(!img) + { + std::cerr << "Error loading image " << fileName << ": " << SOIL_last_result() << std::endl; + return 0; + } + + glGenTextures(1, &tex); + glActiveTexture(GL_TEXTURE0 + index); + glBindTexture(GL_TEXTURE_2D, tex); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, *w, *h, 0, GL_RGB, GL_UNSIGNED_BYTE, img); + SOIL_free_image_data(img); + + return tex; +} diff --git a/src/examples/common/util.h b/src/examples/common/util.h index 27cfe15..3bbd7af 100644 --- a/src/examples/common/util.h +++ b/src/examples/common/util.h @@ -4,9 +4,12 @@ #define GLFW_INCLUDE_GLCOREARB // Needed for OpenGL 3.3 on OS X #include +#include + #include #include GLFWwindow* init(const char* exampleName, int width, int height); +GLuint loadImage(const char* fileName, int* w, int* h, int index); #endif diff --git a/src/libs/SOIL/SOIL.h b/src/libs/SOIL/SOIL.h new file mode 100755 index 0000000..57f375b --- /dev/null +++ b/src/libs/SOIL/SOIL.h @@ -0,0 +1,433 @@ +/** + @mainpage SOIL + + Jonathan Dummer + 2007-07-26-10.36 + + Simple OpenGL Image Library + + A tiny c library for uploading images as + textures into OpenGL. Also saving and + loading of images is supported. + + I'm using Sean's Tool Box image loader as a base: + http://www.nothings.org/ + + I'm upgrading it to load TGA and DDS files, and a direct + path for loading DDS files straight into OpenGL textures, + when applicable. + + Image Formats: + - BMP load & save + - TGA load & save + - DDS load & save + - PNG load + - JPG load + + OpenGL Texture Features: + - resample to power-of-two sizes + - MIPmap generation + - compressed texture S3TC formats (if supported) + - can pre-multiply alpha for you, for better compositing + - can flip image about the y-axis (except pre-compressed DDS files) + + 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 +**/ + +#ifndef HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY +#define HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY + +#ifdef __cplusplus +extern "C" { +#endif + +/** + The format of images that may be loaded (force_channels). + SOIL_LOAD_AUTO leaves the image in whatever format it was found. + SOIL_LOAD_L forces the image to load as Luminous (greyscale) + SOIL_LOAD_LA forces the image to load as Luminous with Alpha + SOIL_LOAD_RGB forces the image to load as Red Green Blue + SOIL_LOAD_RGBA forces the image to load as Red Green Blue Alpha +**/ +enum +{ + SOIL_LOAD_AUTO = 0, + SOIL_LOAD_L = 1, + SOIL_LOAD_LA = 2, + SOIL_LOAD_RGB = 3, + SOIL_LOAD_RGBA = 4 +}; + +/** + Passed in as reuse_texture_ID, will cause SOIL to + register a new texture ID using glGenTextures(). + If the value passed into reuse_texture_ID > 0 then + SOIL will just re-use that texture ID (great for + reloading image assets in-game!) +**/ +enum +{ + SOIL_CREATE_NEW_ID = 0 +}; + +/** + flags you can pass into SOIL_load_OGL_texture() + and SOIL_create_OGL_texture(). + (note that if SOIL_FLAG_DDS_LOAD_DIRECT is used + the rest of the flags with the exception of + SOIL_FLAG_TEXTURE_REPEATS will be ignored while + loading already-compressed DDS files.) + + SOIL_FLAG_POWER_OF_TWO: force the image to be POT + SOIL_FLAG_MIPMAPS: generate mipmaps for the texture + SOIL_FLAG_TEXTURE_REPEATS: otherwise will clamp + SOIL_FLAG_MULTIPLY_ALPHA: for using (GL_ONE,GL_ONE_MINUS_SRC_ALPHA) blending + SOIL_FLAG_INVERT_Y: flip the image vertically + SOIL_FLAG_COMPRESS_TO_DXT: if the card can display them, will convert RGB to DXT1, RGBA to DXT5 + SOIL_FLAG_DDS_LOAD_DIRECT: will load DDS files directly without _ANY_ additional processing + SOIL_FLAG_NTSC_SAFE_RGB: clamps RGB components to the range [16,235] + SOIL_FLAG_CoCg_Y: Google YCoCg; RGB=>CoYCg, RGBA=>CoCgAY + SOIL_FLAG_TEXTURE_RECTANGE: uses ARB_texture_rectangle ; pixel indexed & no repeat or MIPmaps or cubemaps +**/ +enum +{ + SOIL_FLAG_POWER_OF_TWO = 1, + SOIL_FLAG_MIPMAPS = 2, + SOIL_FLAG_TEXTURE_REPEATS = 4, + SOIL_FLAG_MULTIPLY_ALPHA = 8, + SOIL_FLAG_INVERT_Y = 16, + SOIL_FLAG_COMPRESS_TO_DXT = 32, + SOIL_FLAG_DDS_LOAD_DIRECT = 64, + SOIL_FLAG_NTSC_SAFE_RGB = 128, + SOIL_FLAG_CoCg_Y = 256, + SOIL_FLAG_TEXTURE_RECTANGLE = 512 +}; + +/** + The types of images that may be saved. + (TGA supports uncompressed RGB / RGBA) + (BMP supports uncompressed RGB) + (DDS supports DXT1 and DXT5) +**/ +enum +{ + SOIL_SAVE_TYPE_TGA = 0, + SOIL_SAVE_TYPE_BMP = 1, + SOIL_SAVE_TYPE_DDS = 2 +}; + +/** + Defines the order of faces in a DDS cubemap. + I recommend that you use the same order in single + image cubemap files, so they will be interchangeable + with DDS cubemaps when using SOIL. +**/ +#define SOIL_DDS_CUBEMAP_FACE_ORDER "EWUDNS" + +/** + The types of internal fake HDR representations + + SOIL_HDR_RGBE: RGB * pow( 2.0, A - 128.0 ) + SOIL_HDR_RGBdivA: RGB / A + SOIL_HDR_RGBdivA2: RGB / (A*A) +**/ +enum +{ + SOIL_HDR_RGBE = 0, + SOIL_HDR_RGBdivA = 1, + SOIL_HDR_RGBdivA2 = 2 +}; + +/** + Loads an image from disk into an OpenGL texture. + \param filename the name of the file to upload as a texture + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +unsigned int + SOIL_load_OGL_texture + ( + const char *filename, + int force_channels, + unsigned int reuse_texture_ID, + unsigned int flags + ); + +/** + Loads 6 images from disk into an OpenGL cubemap texture. + \param x_pos_file the name of the file to upload as the +x cube face + \param x_neg_file the name of the file to upload as the -x cube face + \param y_pos_file the name of the file to upload as the +y cube face + \param y_neg_file the name of the file to upload as the -y cube face + \param z_pos_file the name of the file to upload as the +z cube face + \param z_neg_file the name of the file to upload as the -z cube face + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Loads 1 image from disk and splits it into an OpenGL cubemap texture. + \param filename the name of the file to upload as a texture + \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc. + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Loads an HDR image from disk into an OpenGL texture. + \param filename the name of the file to upload as a texture + \param fake_HDR_format SOIL_HDR_RGBE, SOIL_HDR_RGBdivA, SOIL_HDR_RGBdivA2 + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Loads an image from RAM into an OpenGL texture. + \param buffer the image data in RAM just as if it were still in a file + \param buffer_length the size of the buffer in bytes + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Loads 6 images from memory into an OpenGL cubemap texture. + \param x_pos_buffer the image data in RAM to upload as the +x cube face + \param x_pos_buffer_length the size of the above buffer + \param x_neg_buffer the image data in RAM to upload as the +x cube face + \param x_neg_buffer_length the size of the above buffer + \param y_pos_buffer the image data in RAM to upload as the +x cube face + \param y_pos_buffer_length the size of the above buffer + \param y_neg_buffer the image data in RAM to upload as the +x cube face + \param y_neg_buffer_length the size of the above buffer + \param z_pos_buffer the image data in RAM to upload as the +x cube face + \param z_pos_buffer_length the size of the above buffer + \param z_neg_buffer the image data in RAM to upload as the +x cube face + \param z_neg_buffer_length the size of the above buffer + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Loads 1 image from RAM and splits it into an OpenGL cubemap texture. + \param buffer the image data in RAM just as if it were still in a file + \param buffer_length the size of the buffer in bytes + \param face_order the order of the faces in the file, any combination of NSWEUD, for North, South, Up, etc. + \param force_channels 0-image format, 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Creates a 2D OpenGL texture from raw image data. Note that the raw data is + _NOT_ freed after the upload (so the user can load various versions). + \param data the raw data to be uploaded as an OpenGL texture + \param width the width of the image in pixels + \param height the height of the image in pixels + \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Creates an OpenGL cubemap texture by splitting up 1 image into 6 parts. + \param data the raw data to be uploaded as an OpenGL texture + \param width the width of the image in pixels + \param height the height of the image in pixels + \param channels the number of channels: 1-luminous, 2-luminous/alpha, 3-RGB, 4-RGBA + \param face_order the order of the faces in the file, and combination of NSWEUD, for North, South, Up, etc. + \param reuse_texture_ID 0-generate a new texture ID, otherwise reuse the texture ID (overwriting the old texture) + \param flags can be any of SOIL_FLAG_POWER_OF_TWO | SOIL_FLAG_MIPMAPS | SOIL_FLAG_TEXTURE_REPEATS | SOIL_FLAG_MULTIPLY_ALPHA | SOIL_FLAG_INVERT_Y | SOIL_FLAG_COMPRESS_TO_DXT | SOIL_FLAG_DDS_LOAD_DIRECT + \return 0-failed, otherwise returns the OpenGL texture handle +**/ +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 + ); + +/** + Captures the OpenGL window (RGB) and saves it to disk + \return 0 if it failed, otherwise returns 1 +**/ +int + SOIL_save_screenshot + ( + const char *filename, + int image_type, + int x, int y, + int width, int height + ); + +/** + Loads an image from disk into an array of unsigned chars. + Note that *channels return the original channel count of the + image. If force_channels was other than SOIL_LOAD_AUTO, + the resulting image has force_channels, but *channels may be + different (if the original image had a different channel + count). + \return 0 if failed, otherwise returns 1 +**/ +unsigned char* + SOIL_load_image + ( + const char *filename, + int *width, int *height, int *channels, + int force_channels + ); + +/** + Loads an image from memory into an array of unsigned chars. + Note that *channels return the original channel count of the + image. If force_channels was other than SOIL_LOAD_AUTO, + the resulting image has force_channels, but *channels may be + different (if the original image had a different channel + count). + \return 0 if failed, otherwise returns 1 +**/ +unsigned char* + SOIL_load_image_from_memory + ( + const unsigned char *const buffer, + int buffer_length, + int *width, int *height, int *channels, + int force_channels + ); + +/** + Saves an image from an array of unsigned chars (RGBA) to disk + \return 0 if failed, otherwise returns 1 +**/ +int + SOIL_save_image + ( + const char *filename, + int image_type, + int width, int height, int channels, + const unsigned char *const data + ); + +/** + Frees the image data (note, this is just C's "free()"...this function is + present mostly so C++ programmers don't forget to use "free()" and call + "delete []" instead [8^) +**/ +void + SOIL_free_image_data + ( + unsigned char *img_data + ); + +/** + This function resturn a pointer to a string describing the last thing + that happened inside SOIL. It can be used to determine why an image + failed to load. +**/ +const char* + SOIL_last_result + ( + void + ); + + +#ifdef __cplusplus +} +#endif + +#endif /* HEADER_SIMPLE_OPENGL_IMAGE_LIBRARY */