Original Post
I recently attempted to include detail texturing in my 3d engine using OpenGL, but after having done all the necessary steps, I noticed that it did not quite work. Here is the detail texture I attempted to use:
But, when I run the game, it looks like this (I have no idea where that texture in the screenshot is coming from):
Here is my code: in function :: init() Necessary functions in function :: Render() (pseudocode) I know it loads the correct texture for this, but it does not display it. And, the whole thing is running much slower with detail texturing turned on. Any ideas, suggestions or similar?
But, when I run the game, it looks like this (I have no idea where that texture in the screenshot is coming from):
Here is my code: in function :: init()
glActiveTextureARB = (PFNGLACTIVETEXTUREARBPROC) wglGetProcAddress("glActiveTextureARB");
glMultiTexCoord2fARB = (PFNGLMULTITEXCOORD2FARBPROC) wglGetProcAddress("glMultiTexCoord2fARB");
if (!glActiveTextureARB || !glMultiTexCoord2fARB) {
MessageBox(g_hWnd, "Multitexturing is not supported!", "Error", MB_OK);
PostQuitMessage(0);
}
void SetTextureCoord(float u, float v)
{
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u, v);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, u, v);
}
void SetupDetailTexturing(int texture, int detail)
{
// Set up the original texture.
glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, texture);
// Set up the detail texture.
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_EXT);
glTexEnvi(GL_TEXTURE_ENV, GL_RGB_SCALE_EXT, 2);
glBindTexture(GL_TEXTURE_2D, detail);
// Set up the detail scale matrix.
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glScalef((float)g_DetailScale, (float)g_DetailScale, 1);
glMatrixMode(GL_MODELVIEW);
}
void DisableDetailTexturing()
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
glDisable(GL_TEXTURE_2D);
}
for each object
SetupDetailTexturing(TXregular, TXdetail);
for each polygon face
for each vertex
SetupTextureCoord(TexVerts.x, TexVerts.y);
end
end
end
DisableDetailTexturing();