PLEASE NOTE: ALL THE PREVIOUS CODE IS GARBAGE
Please look at this post instead of the previous one.
I got my multitexturing to work, and here is the result. If you look for the gluLookAt() associated with the first texture, you will see that the call is “looking at” the origin (0,0,0). For the second texture, the call is “looking at” the point (0, 0.65, 0), which means that the texture should appear above the previous one, and yes, that is the case!
For more resources, please check out
Multitexture API Overview
OpenGL Sample Code
Siggraph 1999 EXTREMELY USEFUL SITE
http://www.codesampler.com/ (Bottom Tutorial + Code)
WglWindowOpenGLContextClass* windowContext = new WglWindowOpenGLContextClass();
windowContext->getOpenGLContext( 256, 256, 256, true );
// Set background clearing color to 50% gray
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
glClear(GL_COLOR_BUFFER_BIT);
GLdouble fovy, aspect, zNear, zFar;
fovy = 10.4;
aspect = 1.0;
zNear = 1.0;
zFar = 10.1;
glMatrixMode(GL_PROJECTION);
//setFrustum(fovy, aspect, zNear, zFar, false, false);
gluPerspective(fovy*2, aspect, zNear, zFar);
//Copy the modelview matrix to an array to put into viewtexture pieces
GLfloat totalPerspective[16];
glGetFloatv(GL_PROJECTION_MATRIX, totalPerspective);
for(int x=0; x<16; x++)
cout << totalPerspective[x] << " ";
cout << endl;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//Pull out modelview matrix. This won't change between texture pieces
GLfloat* viewModelview = new GLfloat[16];
glGetFloatv(GL_MODELVIEW_MATRIX, viewModelview);
//Make sample texture (6x6 pixels, black cross on white)
int imageWidth, imageHeight;
imageWidth = 6;
imageHeight = 6;
//The Left image is all blue, the Right image is all green
//They should appear next to each other but instead are blended
GLfloat* imageBlue = new GLfloat[3*imageHeight*imageWidth];
GLfloat* imageGreen = new GLfloat[3*imageHeight*imageWidth];
for(int x=0; x<imageHeight; x++)
{
for(int y=0; y<imageWidth; y++)
{
int bit = 3*(x*imageWidth + y);
imageBlue[bit] = 0.0f;
imageBlue[bit+1] = 0.0f;
imageBlue[bit+2] = 1.0f;
imageGreen[bit] = 0.0f;
imageGreen[bit+1] = 1.0f;
imageGreen[bit+2] = 0.0f;
}
}
//Allocate space for our projection matrices
GLfloat* viewProjection = new GLfloat[16];
GLfloat borderColor[] = {1.0f, 1.0f, 1.0f, 1.0f};
/////////////////////
//Set up texture 1
/////////////////////
GLuint textureNumber[2];
glGenTextures(2, textureNumber);
glActiveTexture(GL_TEXTURE0);
glEnable(GL_TEXTURE_2D);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBindTexture(GL_TEXTURE_2D, textureNumber[0]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGB,
imageWidth, imageHeight,
0
GL_RGB,
GL_FLOAT,
imageBlue);
//Set texture matrix
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f,0.5f,0.0f); //Bias
glScalef(0.5f,0.5f,1.0f); //Scale
glFrustum(-0.25, 0.25, -0.25, 0.25, 9.9, 10.1); //MV for light map
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//copy the matrix to OpenGL
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);
glEnable(GL_TEXTURE_GEN_Q);
GLfloat eyePlaneS[] = {1.0f, 0.0f, 0.0f, 0.0f};
GLfloat eyePlaneT[] = {0.0f, 1.0f, 0.0f, 0.0f};
GLfloat eyePlaneR[] = {0.0f, 0.0f, 1.0f, 0.0f};
GLfloat eyePlaneQ[] = {0.0f, 0.0f, 0.0f, 1.0f};
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_S,GL_EYE_PLANE,eyePlaneS);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_T,GL_EYE_PLANE,eyePlaneT);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_R,GL_EYE_PLANE,eyePlaneR);
glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_Q,GL_EYE_PLANE,eyePlaneQ);
/////////////////////
//Set up texture 2
/////////////////////
glActiveTexture(GL_TEXTURE1);
glEnable(GL_TEXTURE_2D);
glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
glBindTexture(GL_TEXTURE_2D, textureNumber[1]);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor);
glTexImage2D( GL_TEXTURE_2D,
0,
GL_RGB,
imageWidth, imageHeight,
0,
GL_RGB,
GL_FLOAT,
imageGreen);
//Set texture matrix
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslatef(0.5f,0.5f,0.0f); //Bias
glScalef(0.5f,0.5f,1.0f); //Scale
glFrustum(-0.25, 0.25, -0.25, 0.25, 9.9, 10.1); //MV for light map
glEnable(GL_TEXTURE_GEN_Q);
glTexGeni(GL_S,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_S,GL_EYE_PLANE,eyePlaneS);
glTexGeni(GL_T,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_T,GL_EYE_PLANE,eyePlaneT);
glTexGeni(GL_R,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_R,GL_EYE_PLANE,eyePlaneR);
glTexGeni(GL_Q,GL_TEXTURE_GEN_MODE,GL_EYE_LINEAR);
glTexGenfv(GL_Q,GL_EYE_PLANE,eyePlaneQ);
/////////////////////
//DRAW QUAD
/////////////////////
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
//red quad for reference
glColor3f(1.0f, 1.0f, 1.0f);
glBegin(GL_QUADS);
glVertex3f(-0.95f, 0.95f, 0.0f);
glVertex3f(0.95f, 0.95f, 0.0f);
glVertex3f(0.95f, -0.95f, 0.0f);
glVertex3f(-0.95f, -0.95f, 0.0f);
glEnd();
//present the quad to the screen
windowContext->swapBuffers();