aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/cube2hash/Makefile14
-rw-r--r--tests/cube2hash/cube2crypto.c23
-rw-r--r--tests/cube2hash/cube2crypto.h9
-rw-r--r--tests/cube2hash/hashstring.cpp28
-rw-r--r--tests/cube2hash/tiger.c175
-rw-r--r--tests/cube2hash/tiger.h12
-rw-r--r--tests/cube2hash/util.h22
-rw-r--r--tests/gl/LICENSE.TXT11
-rw-r--r--tests/gl/sdl_ogl.c202
-rw-r--r--tests/gl/tutorial2.frag11
-rw-r--r--tests/gl/tutorial2.vert19
-rw-r--r--tests/glbook/CH02_HelloTriangle.pngbin0 -> 1009 bytes
-rw-r--r--tests/glbook/Chapter_10/MultiTexture/MultiTexture.c213
-rw-r--r--tests/glbook/Chapter_10/MultiTexture/basemap.tgabin0 -> 786476 bytes
-rw-r--r--tests/glbook/Chapter_10/MultiTexture/lightmap.tgabin0 -> 196626 bytes
-rw-r--r--tests/glbook/Chapter_11/Multisample/Multisample.c302
-rw-r--r--tests/glbook/Chapter_11/Stencil_Test/Stencil_Test.c273
-rw-r--r--tests/glbook/Chapter_13/ParticleSystem/ParticleSystem.c294
-rw-r--r--tests/glbook/Chapter_13/ParticleSystem/smoke.tgabin0 -> 49170 bytes
-rw-r--r--tests/glbook/Chapter_15/Hello_Triangle_KD/Hello_Triangle_KD.c306
-rw-r--r--tests/glbook/Chapter_2/Hello_Triangle/Hello_Triangle.c200
-rw-r--r--tests/glbook/Chapter_8/Simple_VertexShader/Simple_VertexShader.c196
-rw-r--r--tests/glbook/Chapter_9/MipMap2D/MipMap2D.c348
-rw-r--r--tests/glbook/Chapter_9/Simple_Texture2D/Simple_Texture2D.c199
-rw-r--r--tests/glbook/Chapter_9/Simple_TextureCubemap/Simple_TextureCubemap.c227
-rw-r--r--tests/glbook/Chapter_9/TextureWrap/TextureWrap.c257
-rw-r--r--tests/glbook/Common/esShader.c155
-rw-r--r--tests/glbook/Common/esShapes.c280
-rw-r--r--tests/glbook/Common/esTransform.c213
-rw-r--r--tests/glbook/Common/esUtil.c420
-rw-r--r--tests/glbook/Common/esUtil.h281
-rw-r--r--tests/glbook/Makefile60
-rw-r--r--tests/glbook/README.linux32
-rw-r--r--tests/i64_precise.txt128
-rwxr-xr-xtests/runner.py577
35 files changed, 5021 insertions, 466 deletions
diff --git a/tests/cube2hash/Makefile b/tests/cube2hash/Makefile
new file mode 100644
index 00000000..5d0a7a63
--- /dev/null
+++ b/tests/cube2hash/Makefile
@@ -0,0 +1,14 @@
+all: cube2hash.bc
+
+cube2hash.bc: cube2crypto.o tiger.o hashstring.o
+ $(CXX) $^ -o $@
+
+hashstring.o: hashstring.cpp
+ $(CXX) -c $^ -o $@
+
+cube2crypto.o: cube2crypto.c cube2crypto.h
+ $(CC) -c $< -o $@
+
+tiger.o: tiger.c tiger.h
+ $(CC) -c $< -o $@
+
diff --git a/tests/cube2hash/cube2crypto.c b/tests/cube2hash/cube2crypto.c
new file mode 100644
index 00000000..52613318
--- /dev/null
+++ b/tests/cube2hash/cube2crypto.c
@@ -0,0 +1,23 @@
+#include <stdlib.h>
+#include "util.h"
+#include "tiger.h"
+#include "cube2crypto.h"
+
+char *cube2crypto_hashstring(char *string)
+{
+ char *result = (char *)malloc(49);
+ union hashval hv;
+
+ tiger_hash((uchar *)string, strlen(string), &hv);
+
+ int i;
+ for(i = 0; i < sizeof(hv.bytes); i++)
+ {
+ uchar c = hv.bytes[i];
+ *(result+(i*2)) = "0123456789ABCDEF"[c&0xF];
+ *(result+(i*2)+1) = "0123456789ABCDEF"[c>>4];
+ }
+ *(result+(i*2)+2) = '\0';
+
+ return result;
+}
diff --git a/tests/cube2hash/cube2crypto.h b/tests/cube2hash/cube2crypto.h
new file mode 100644
index 00000000..90bd06a8
--- /dev/null
+++ b/tests/cube2hash/cube2crypto.h
@@ -0,0 +1,9 @@
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+char *cube2crypto_hashstring(char *string);
+
+#ifdef __cplusplus
+} /* closing brace for extern "C" */
+#endif \ No newline at end of file
diff --git a/tests/cube2hash/hashstring.cpp b/tests/cube2hash/hashstring.cpp
new file mode 100644
index 00000000..b08d5d5e
--- /dev/null
+++ b/tests/cube2hash/hashstring.cpp
@@ -0,0 +1,28 @@
+#include "cube2crypto.h"
+#include <stdlib.h>
+#include <stdio.h>
+
+#define EXIT_FAILURE 1
+#define EXIT_SUCCESS 0
+
+void help()
+{
+ printf("Usage: hashstring <seed>\n");
+}
+
+int main(int argc, char **argv)
+{
+ if(argc != 2 || !argv[1])
+ {
+ help();
+ return EXIT_FAILURE;
+ }
+
+ char *answer = cube2crypto_hashstring(argv[1]);
+
+ printf("hash value: %s\n", answer);
+
+ free(answer);
+
+ return EXIT_SUCCESS;
+}
diff --git a/tests/cube2hash/tiger.c b/tests/cube2hash/tiger.c
new file mode 100644
index 00000000..f8707248
--- /dev/null
+++ b/tests/cube2hash/tiger.c
@@ -0,0 +1,175 @@
+///////////////////////// cryptography /////////////////////////////////
+
+/* Based off the reference implementation of Tiger, a cryptographically
+ * secure 192 bit hash function by Ross Anderson and Eli Biham. More info at:
+ * http://www.cs.technion.ac.il/~biham/Reports/Tiger/
+ */
+
+#define TIGER_PASSES 3
+
+#include "tiger.h"
+#include "util.h"
+
+chunk sboxes[4*256];
+
+#define sb1 (sboxes)
+#define sb2 (sboxes+256)
+#define sb3 (sboxes+256*2)
+#define sb4 (sboxes+256*3)
+
+#define round(a, b, c, x) \
+ c ^= x; \
+ a -= sb1[((c)>>(0*8))&0xFF] ^ sb2[((c)>>(2*8))&0xFF] ^ \
+ sb3[((c)>>(4*8))&0xFF] ^ sb4[((c)>>(6*8))&0xFF] ; \
+ b += sb4[((c)>>(1*8))&0xFF] ^ sb3[((c)>>(3*8))&0xFF] ^ \
+ sb2[((c)>>(5*8))&0xFF] ^ sb1[((c)>>(7*8))&0xFF] ; \
+ b *= mul;
+
+void tiger_compress(const chunk *str, chunk state[3])
+{
+ chunk a, b, c;
+ chunk aa, bb, cc;
+ chunk x0, x1, x2, x3, x4, x5, x6, x7;
+
+ a = state[0];
+ b = state[1];
+ c = state[2];
+
+ x0=str[0]; x1=str[1]; x2=str[2]; x3=str[3];
+ x4=str[4]; x5=str[5]; x6=str[6]; x7=str[7];
+
+ aa = a;
+ bb = b;
+ cc = c;
+
+ int pass;
+
+ for(pass = 0; pass < TIGER_PASSES; pass++)
+ {
+ if(pass)
+ {
+ x0 -= x7 ^ 0xA5A5A5A5A5A5A5A5ULL; x1 ^= x0; x2 += x1; x3 -= x2 ^ ((~x1)<<19);
+ x4 ^= x3; x5 += x4; x6 -= x5 ^ ((~x4)>>23); x7 ^= x6;
+ x0 += x7; x1 -= x0 ^ ((~x7)<<19); x2 ^= x1; x3 += x2;
+ x4 -= x3 ^ ((~x2)>>23); x5 ^= x4; x6 += x5; x7 -= x6 ^ 0x0123456789ABCDEFULL;
+ }
+
+ uint mul = !pass ? 5 : (pass==1 ? 7 : 9);
+ round(a, b, c, x0) round(b, c, a, x1) round(c, a, b, x2) round(a, b, c, x3)
+ round(b, c, a, x4) round(c, a, b, x5) round(a, b, c, x6) round(b, c, a, x7)
+
+ chunk tmp = a; a = c; c = b; b = tmp;
+
+ }
+
+ a ^= aa;
+ b -= bb;
+ c += cc;
+
+ state[0] = a;
+ state[1] = b;
+ state[2] = c;
+}
+
+void tiger_gensboxes()
+{
+ const char *str = "Tiger - A Fast New Hash Function, by Ross Anderson and Eli Biham";
+ chunk state[3] = { 0x0123456789ABCDEFULL, 0xFEDCBA9876543210ULL, 0xF096A5B4C3B2E187ULL };
+ uchar temp[64];
+ int i, j, col, sb, pass;
+
+ if(BIGENDIAN)
+ {
+ for(j = 0; j < 64; j++)
+ {
+ temp[j^7] = str[j];
+ }
+ }
+ else
+ {
+ for(j = 0; j < 64; j++)
+ {
+ temp[j] = str[j];
+ }
+ }
+
+ for(i = 0; i < 1024; i++)
+ {
+ for(col = 0; col < 8; col++)
+ {
+ ((uchar *)&sboxes[i])[col] = i&0xFF;
+ }
+ }
+
+ int abc = 2;
+ for(pass = 0; pass < 5; pass++)
+ {
+ for(i = 0; i < 256; i++)
+ {
+ for(sb = 0; sb < 1024; sb += 256)
+ {
+ abc++;
+ if(abc >= 3) { abc = 0; tiger_compress((chunk *)temp, state); }
+ for(col = 0; col < 8; col++)
+ {
+ uchar val = ((uchar *)&sboxes[sb+i])[col];
+ ((uchar *)&sboxes[sb+i])[col] = ((uchar *)&sboxes[sb + ((uchar *)&state[abc])[col]])[col];
+ ((uchar *)&sboxes[sb + ((uchar *)&state[abc])[col]])[col] = val;
+ }
+ }
+ }
+ }
+}
+
+void tiger_hash(const uchar *str, int length, union hashval *val)
+{
+ static int init = false;
+ if(!init) { tiger_gensboxes(); init = true; }
+
+ uchar temp[64];
+
+ val->chunks[0] = 0x0123456789ABCDEFULL;
+ val->chunks[1] = 0xFEDCBA9876543210ULL;
+ val->chunks[2] = 0xF096A5B4C3B2E187ULL;
+
+ int i, j;
+ for(i = length; i >= 64; i -= 64, str += 64)
+ {
+ if(BIGENDIAN)
+ {
+ for(j = 0; j < 64; j++)
+ {
+ temp[j^7] = str[j];
+ }
+
+ tiger_compress((chunk *)temp, val->chunks);
+ }
+ else
+ {
+ tiger_compress((chunk *)str, val->chunks);
+ }
+ }
+
+ if(BIGENDIAN)
+ {
+ for(j = 0; j < i; j++) temp[j^7] = str[j];
+ temp[j^7] = 0x01;
+ while(++j&7) temp[j^7] = 0;
+ }
+ else
+ {
+ for(j = 0; j < i; j++) temp[j] = str[j];
+ temp[j] = 0x01;
+ while(++j&7) temp[j] = 0;
+ }
+
+ if(j > 56)
+ {
+ while(j < 64) temp[j++] = 0;
+ tiger_compress((chunk *)temp, val->chunks);
+ j = 0;
+ }
+ while(j < 56) temp[j++] = 0;
+ *(chunk *)(temp+56) = (chunk)length<<3;
+ tiger_compress((chunk *)temp, val->chunks);
+}
diff --git a/tests/cube2hash/tiger.h b/tests/cube2hash/tiger.h
new file mode 100644
index 00000000..b0d70797
--- /dev/null
+++ b/tests/cube2hash/tiger.h
@@ -0,0 +1,12 @@
+#ifndef _TIGER_H
+#define _TIGER_H
+
+union hashval
+{
+ unsigned char bytes[3*8];
+ unsigned long long int chunks[3];
+};
+
+void tiger_hash(const unsigned char *str, int length, union hashval *val);
+
+#endif
diff --git a/tests/cube2hash/util.h b/tests/cube2hash/util.h
new file mode 100644
index 00000000..844b8ed0
--- /dev/null
+++ b/tests/cube2hash/util.h
@@ -0,0 +1,22 @@
+#ifndef _UTIL_H
+#define _UTIL_H
+
+#include <string.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+#define BIGENDIAN 0
+
+#ifndef bool
+#define bool unsigned short int
+#define true 1
+#define false 0
+#endif
+
+typedef unsigned long long int chunk;
+typedef unsigned char uchar;
+typedef unsigned short ushort;
+typedef unsigned int uint;
+
+#endif
diff --git a/tests/gl/LICENSE.TXT b/tests/gl/LICENSE.TXT
deleted file mode 100644
index 45e1d8ad..00000000
--- a/tests/gl/LICENSE.TXT
+++ /dev/null
@@ -1,11 +0,0 @@
-THIS WORK, INCLUDING THE SOURCE CODE, DOCUMENTATION
-AND RELATED MEDIA AND DATA, IS PLACED INTO THE PUBLIC DOMAIN.
-
-THE ORIGINAL AUTHOR IS KYLE FOLEY.
-
-THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY
-OF ANY KIND, NOT EVEN THE IMPLIED WARRANTY OF
-MERCHANTABILITY. THE AUTHOR OF THIS SOFTWARE,
-ASSUMES _NO_ RESPONSIBILITY FOR ANY CONSEQUENCE
-RESULTING FROM THE USE, MODIFICATION, OR
-REDISTRIBUTION OF THIS SOFTWARE.
diff --git a/tests/gl/sdl_ogl.c b/tests/gl/sdl_ogl.c
deleted file mode 100644
index 6f81c7ff..00000000
--- a/tests/gl/sdl_ogl.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*******************************************************************
- * *
- * Using SDL With OpenGL *
- * *
- * Tutorial by Kyle Foley (sdw) *
- * *
- * http://gpwiki.org/index.php/SDL:Tutorials:Using_SDL_with_OpenGL *
- * *
- *******************************************************************/
-
-/*
- Combined with opengl.org tutorial #2,
- http://www.opengl.org/wiki/Tutorial2:_VAOs,_VBOs,_Vertex_and_Fragment_Shaders_%28C_/_SDL%29
-
- Build with
-
- gcc sdl_ogl.c -lSDL -lGL
-
- g++ will fail!
-
- Or, to JS:
-
- ~/Dev/emscripten/tools/emmaken.py sdl_ogl.c -o sdl_ogl.o
- ~/Dev/emscripten/emscripten.py sdl_ogl.o > sdl_ogl.js
-*/
-
-#include "SDL/SDL.h"
-#include "SDL/SDL_opengl.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-char* filetobuf(char *file)
-{
- FILE *fptr;
- long length;
- char *buf;
-
- fptr = fopen(file, "r"); /* Open file for reading */
- if (!fptr) /* Return NULL on failure */
- return NULL;
- fseek(fptr, 0, SEEK_END); /* Seek to the end of the file */
- length = ftell(fptr); /* Find out how many bytes into the file we are */
- buf = (char*)malloc(length+1); /* Allocate a buffer for the entire length of the file and a null terminator */
- fseek(fptr, 0, SEEK_SET); /* Go back to the beginning of the file */
- fread(buf, length, 1, fptr); /* Read the contents of the file in to the buffer */
- fclose(fptr); /* Close the file */
- buf[length] = 0; /* Null terminator */
-
- return buf; /* Return the buffer */
-}
-
-void drawscene()
-{
- int i; /* Simple iterator */
- GLuint vao, vbo[2]; /* Create handles for our Vertex Array Object and two Vertex Buffer Objects */
-
- /* We're going to create a simple diamond made from lines */
- const GLfloat diamond[4][2] = {
- { 0.0, 1.0 }, /* Top point */
- { 1.0, 0.0 }, /* Right point */
- { 0.0, -1.0 }, /* Bottom point */
- { -1.0, 0.0 } }; /* Left point */
-
- const GLfloat colors[4][3] = {
- { 1.0, 0.0, 0.0 }, /* Red */
- { 0.0, 1.0, 0.0 }, /* Green */
- { 0.0, 0.0, 1.0 }, /* Blue */
- { 1.0, 1.0, 1.0 } }; /* White */
-
- /* These pointers will receive the contents of our shader source code files */
- GLchar *vertexsource, *fragmentsource;
-
- /* These are handles used to reference the shaders */
- GLuint vertexshader, fragmentshader;
-
- /* This is a handle to the shader program */
- GLuint shaderprogram;
-
- /* Allocate and assign a Vertex Array Object to our handle */
- glGenVertexArrays(1, &vao);
-
- /* Bind our Vertex Array Object as the current used object */
- glBindVertexArray(vao);
-
- /* Allocate and assign two Vertex Buffer Objects to our handle */
- glGenBuffers(2, vbo);
-
- /* Bind our first VBO as being the active buffer and storing vertex attributes (coordinates) */
- glBindBuffer(GL_ARRAY_BUFFER, vbo[0]);
-
- /* Copy the vertex data from diamond to our buffer */
- /* 8 * sizeof(GLfloat) is the size of the diamond array, since it contains 8 GLfloat values */
- glBufferData(GL_ARRAY_BUFFER, 8 * sizeof(GLfloat), diamond, GL_STATIC_DRAW);
-
- /* Specify that our coordinate data is going into attribute index 0, and contains two floats per vertex */
- glVertexAttribPointer((GLuint)0, 2, GL_FLOAT, GL_FALSE, 0, 0);
-
- /* Enable attribute index 0 as being used */
- glEnableVertexAttribArray(0);
-
- /* Bind our second VBO as being the active buffer and storing vertex attributes (colors) */
- glBindBuffer(GL_ARRAY_BUFFER, vbo[1]);
-
- /* Copy the color data from colors to our buffer */
- /* 12 * sizeof(GLfloat) is the size of the colors array, since it contains 12 GLfloat values */
- glBufferData(GL_ARRAY_BUFFER, 12 * sizeof(GLfloat), colors, GL_STATIC_DRAW);
-
- /* Specify that our color data is going into attribute index 1, and contains three floats per vertex */
- glVertexAttribPointer((GLuint)1, 3, GL_FLOAT, GL_FALSE, 0, 0);
-
- /* Enable attribute index 1 as being used */
- glEnableVertexAttribArray(1);
-
- /* Read our shaders into the appropriate buffers */
- vertexsource = filetobuf("tutorial2.vert");
- fragmentsource = filetobuf("tutorial2.frag");
-
- /* Assign our handles a "name" to new shader objects */
- vertexshader = glCreateShader(GL_VERTEX_SHADER);
- fragmentshader = glCreateShader(GL_FRAGMENT_SHADER);
-
- /* Associate the source code buffers with each handle */
- glShaderSource(vertexshader, 1, (const GLchar**)&vertexsource, 0);
- glShaderSource(fragmentshader, 1, (const GLchar**)&fragmentsource, 0);
-
- /* Compile our shader objects */
- glCompileShader(vertexshader);
- glCompileShader(fragmentshader);
-
- /* Assign our program handle a "name" */
- shaderprogram = glCreateProgram();
-
- /* Attach our shaders to our program */
- glAttachShader(shaderprogram, vertexshader);
- glAttachShader(shaderprogram, fragmentshader);
-
- /* Bind attribute index 0 (coordinates) to in_Position and attribute index 1 (color) to in_Color */
- glBindAttribLocation(shaderprogram, 0, "in_Position");
- glBindAttribLocation(shaderprogram, 1, "in_Color");
-
- /* Link our program, and set it as being actively used */
- glLinkProgram(shaderprogram);
- glUseProgram(shaderprogram);
-
- /* Loop our display increasing the number of shown vertexes each time.
- * Start with 2 vertexes (a line) and increase to 3 (a triangle) and 4 (a diamond) */
- for (i=4; i <= 4; i++)
- {
- /* Make our background black */
- glClearColor(0.0, 0.0, 0.0, 1.0);
- glClear(GL_COLOR_BUFFER_BIT);
-
- /* Invoke glDrawArrays telling that our data is a line loop and we want to draw 2-4 vertexes */
- glDrawArrays(GL_LINE_LOOP, 0, i);
-
- /* Swap our buffers to make our changes visible */
- SDL_GL_SwapBuffers();
-
- /* Sleep for 2 seconds */
- SDL_Delay(2000);
- }
-
- /* Cleanup all the things we bound and allocated */
- glUseProgram(0);
- glDisableVertexAttribArray(0);
- glDisableVertexAttribArray(1);
- glDetachShader(shaderprogram, vertexshader);
- glDetachShader(shaderprogram, fragmentshader);
- glDeleteProgram(shaderprogram);
- glDeleteShader(vertexshader);
- glDeleteShader(fragmentshader);
- glDeleteBuffers(2, vbo);
- glDeleteVertexArrays(1, &vao);
- free(vertexsource);
- free(fragmentsource);
-}
-
-int main(int argc, char *argv[])
-{
- SDL_Surface *screen;
-
- // Slightly different SDL initialization
- if ( SDL_Init(SDL_INIT_VIDEO) != 0 ) {
- printf("Unable to initialize SDL: %s\n", SDL_GetError());
- return 1;
- }
-
- SDL_GL_SetAttribute( SDL_GL_DOUBLEBUFFER, 1 ); // *new*
-
- screen = SDL_SetVideoMode( 512, 384, 32, SDL_OPENGL); // *changed*
- if ( !screen ) {
- printf("Unable to set video mode: %s\n", SDL_GetError());
- return 1;
- }
-
- drawscene();
-
- SDL_Quit();
-
- return 0;
-}
diff --git a/tests/gl/tutorial2.frag b/tests/gl/tutorial2.frag
deleted file mode 100644
index faa30eaf..00000000
--- a/tests/gl/tutorial2.frag
+++ /dev/null
@@ -1,11 +0,0 @@
-#version 150
-// It was expressed that some drivers required this next line to function properly
-precision highp float;
-
-in vec3 ex_Color;
-out vec4 gl_FragColor;
-
-void main(void) {
- // Pass through our original color with full opacity.
- gl_FragColor = vec4(ex_Color,1.0);
-}
diff --git a/tests/gl/tutorial2.vert b/tests/gl/tutorial2.vert
deleted file mode 100644
index d9de08e3..00000000
--- a/tests/gl/tutorial2.vert
+++ /dev/null
@@ -1,19 +0,0 @@
-#version 150
-// in_Position was bound to attribute index 0 and in_Color was bound to attribute index 1
-in vec2 in_Position;
-in vec3 in_Color;
-
-// We output the ex_Color variable to the next shader in the chain
-out vec3 ex_Color;
-void main(void) {
- // Since we are using flat lines, our input only had two points: x and y.
- // Set the Z coordinate to 0 and W coordinate to 1
-
- gl_Position = vec4(in_Position.x, in_Position.y, 0.0, 1.0);
-
- // GLSL allows shorthand use of vectors too, the following is also valid:
- // gl_Position = vec4(in_Position, 0.0, 1.0);
- // We're simply passing the color through unmodified
-
- ex_Color = in_Color;
-}
diff --git a/tests/glbook/CH02_HelloTriangle.png b/tests/glbook/CH02_HelloTriangle.png
new file mode 100644
index 00000000..d6351e2a
--- /dev/null
+++ b/tests/glbook/CH02_HelloTriangle.png
Binary files differ
diff --git a/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c
new file mode 100644
index 00000000..5324ad92
--- /dev/null
+++ b/tests/glbook/Chapter_10/MultiTexture/MultiTexture.c
@@ -0,0 +1,213 @@
+//
+// Book: OpenGL(R) ES 2.0 Programming Guide
+// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
+// ISBN-10: 0321502795
+// ISBN-13: 9780321502797
+// Publisher: Addison-Wesley Professional
+// URLs: http://safari.informit.com/9780321563835
+// http://www.opengles-book.com
+//
+
+// MultiTexture.c
+//
+// This is an example that draws a quad with a basemap and
+// lightmap to demonstrate multitexturing.
+//
+#include <stdlib.h>
+#include "esUtil.h"
+
+typedef struct
+{
+ // Handle to a program object
+ GLuint programObject;
+
+ // Attribute locations
+ GLint positionLoc;
+ GLint texCoordLoc;
+
+ // Sampler locations
+ GLint baseMapLoc;
+ GLint lightMapLoc;
+
+ // Texture handle
+ GLuint baseMapTexId;
+ GLuint lightMapTexId;
+
+} UserData;
+
+
+///
+// Load texture from disk
+//
+GLuint LoadTexture ( char *fileName )
+{
+ int width,
+ height;
+ char *buffer = esLoadTGA ( fileName, &width, &height );
+ GLuint texId;
+
+ if ( buffer == NULL )
+ {
+ esLogMessage ( "Error loading (%s) image.\n", fileName );
+ return 0;
+ }
+
+ glGenTextures ( 1, &texId );
+ glBindTexture ( GL_TEXTURE_2D, texId );
+
+ glTexImage2D ( GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, buffer );
+ glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
+ glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
+ glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
+ glTexParameteri ( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
+
+ free ( buffer );
+
+ return texId;
+}
+
+
+
+///
+// Initialize the shader and program object
+//
+int Init ( ESContext *esContext )
+{
+ UserData *userData = esContext->userData;
+ GLbyte vShaderStr[] =
+ "attribute vec4 a_position; \n"
+ "attribute vec2 a_texCoord; \n"
+ "varying vec2 v_texCoord; \n"
+ "void main() \n"
+ "{ \n"
+ " gl_Position = a_position; \n"
+ " v_texCoord = a_texCoord; \n"
+ "} \n";
+
+ GLbyte fShaderStr[] =
+ "precision mediump float; \n"
+ "varying vec2 v_texCoord; \n"
+ "uniform sampler2D s_baseMap; \n"
+ "uniform sampler2D s_lightMap; \n"
+ "void main() \n"
+ "{ \n"
+ " vec4 baseColor; \n"
+ " vec4 lightColor; \n"
+ " \n"
+ " baseColor = texture2D( s_baseMap, v_texCoord ); \n"
+ " lightColor = texture2D( s_lightMap, v_texCoord ); \n"
+ " gl_FragColor = baseColor * (lightColor + 0.25); \n"
+ "} \n";
+
+ // Load the shaders and get a linked program object
+ userData->programObject = esLoadProgram ( vShaderStr, fShaderStr );
+
+ // Get the attribute locations
+ userData->positionLoc = glGetAttribLocation ( userData->programObject, "a_position" );
+ userData->texCoordLoc = glGetAttribLocation ( userData->programObject, "a_texCoord" );
+
+ // Get the sampler location
+ userData->baseMapLoc = glGetUniformLocation ( userData->programObject, "s_baseMap" );
+ userData->lightMapLoc = glGetUniformLocation ( userData->programObject, "s_lightMap" );
+
+ // Load the textures
+ userData->baseMapTexId = LoadTexture ( "basemap.tga" );
+ userData->lightMapTexId = LoadTexture ( "lightmap.tga" );
+
+ if ( userData->baseMapTexId == 0 || userData->lightMapTexId == 0 )
+ return FALSE;
+
+ glClearColor ( 0.0f, 0.0f, 0.0f, 0.0f );
+ return TRUE;
+}
+
+///
+// Draw a triangle using the shader pair created in Init()
+//
+void Draw ( ESContext *esContext )
+{
+ UserData *userData = esContext->userData;
+ GLfloat vVertices[] = { -0.5f, 0.5f, 0.0f, // Position 0
+ 0.0f, 0.0f, // TexCoord 0
+ -0.5f, -0.5f, 0.0f, // Position 1
+ 0.0f, 1.0f, // TexCoord 1
+ 0.5f, -0.5f, 0.0f, // Position 2
+ 1.0f, 1.0f, // TexCoord 2
+ 0.5f, 0.5f, 0.0f, // Position 3
+ 1.0f, 0.0f // TexCoord 3
+ };
+ GLushort indices[] = { 0, 1, 2, 0, 2, 3 };
+
+ // Set the viewport
+ glViewport ( 0, 0, esContext->width, esContext->height );
+
+ // Clear the color buffer
+ glClear ( GL_COLOR_BUFFER_BIT );
+
+ // Use the program object
+ glUseProgram ( userData->programObject );
+
+ // Load the vertex position
+ glVertexAttribPointer ( userData->positionLoc, 3, GL_FLOAT,
+ GL_FALSE, 5 * sizeof(GLfloat), vVertices );
+ // Load the texture coordinate
+ glVertexAttribPointer ( userData->texCoordLoc, 2, GL_FLOAT,
+ GL_FALSE, 5 * sizeof(GLfloat), &vVertices[3] );
+
+ glEnableVertexAttribArray ( userData->positionLoc );
+ glEnableVertexAttribArray ( userData->texCoordLoc );
+
+ // Bind the base map
+ glActiveTexture ( GL_TEXTURE0 );
+ glBindTexture ( GL_TEXTURE_2D, userData->baseMapTexId );
+
+ // Set the base map sampler to texture unit to 0
+ glUniform1i ( userData->baseMapLoc, 0 );
+
+ // Bind the light map
+ glActiveTexture ( GL_TEXTURE1 );
+ glBindTexture ( GL_TEXTURE_2D, userData->lightMapTexId );
+
+ // Set the light map sampler to texture unit 1
+ glUniform1i ( userData->lightMapLoc, 1 );
+
+ glDrawElements ( GL_TRIANGLES, 6, GL_UNSIGNED_SHORT, indices );
+
+ eglSwapBuffers ( esContext->eglDisplay, esContext->eglSurface );
+}
+
+///
+// Cleanup
+//
+void ShutDown ( ESContext *esContext )
+{
+ UserData *userData = esContext->userData;
+
+ // Delete texture object
+ glDeleteTextures ( 1, &userData->baseMapTexId );
+ glDeleteTextures ( 1, &userData->lightMapTexId );
+
+ // Delete program object
+ glDeleteProgram ( userData->programObject );
+}
+
+
+int main ( int argc, char *argv[] )
+{
+ ESContext esContext;
+ UserData userData;
+
+ esInitContext ( &esContext );
+ esContext.userData = &userData;
+
+ esCreateWindow ( &esContext, "MultiTexture", 320, 240, ES_WINDOW_RGB );
+
+ if ( !Init ( &esContext ) )
+ return 0;
+
+ esRegisterDrawFunc ( &esContext, Draw );
+
+ esMainLoop ( &esContext );
+
+ ShutDown ( &esContext );
+}
diff --git a/tests/glbook/Chapter_10/MultiTexture/basemap.tga b/tests/glbook/Chapter_10/MultiTexture/basemap.tga
new file mode 100644
index 00000000..8acafae2
--- /dev/null
+++ b/tests/glbook/Chapter_10/MultiTexture/basemap.tga
Binary files differ
diff --git a/tests/glbook/Chapter_10/MultiTexture/lightmap.tga b/tests/glbook/Chapter_10/MultiTexture/lightmap.tga
new file mode 100644
index 00000000..d95b2628
--- /dev/null
+++ b/tests/glbook/Chapter_10/MultiTexture/lightmap.tga
Binary files differ
diff --git a/tests/glbook/Chapter_11/Multisample/Multisample.c b/tests/glbook/Chapter_11/Multisample/Multisample.c
new file mode 100644
index 00000000..fd064c70
--- /dev/null
+++ b/tests/glbook/Chapter_11/Multisample/Multisample.c
@@ -0,0 +1,302 @@
+//
+// Book: OpenGL(R) ES 2.0 Programming Guide
+// Authors: Aaftab Munshi, Dan Ginsburg, Dave Shreiner
+// ISBN-10: 0321502795
+// ISBN-13: 9780321502797
+// Publisher: Addison-Wesley Professional
+// URLs: http://safari.informit.com/9780321563835
+// http://www.opengles-book.com
+//
+
+// Multisample.c
+//
+// This example shows various multi-sampling
+//