TerrRender.cc multitexture problem
by Tcangussu · in Torque Game Engine · 12/22/2006 (12:30 pm) · 6 replies
Hi,
I'm trying to use a new texture on top of the terrain textures(base, lightmap, etc...) to add some effects.
When I use any of the OpenGL textures below GL_TEXTURE4_ARB it works fine.
These textures appears to already been used by the terrain:
GL_TEXTURE0_ARB - Base texture
GL_TEXTURE1_ARB - Lightmap
GL_TEXTURE2_ARB - Fog
GL_TEXTURE3_ARB - Not sure
So I'm trying to use the GL_TEXTURE4_ARB but when I use this one nothing happens.
Any ideas???
Below is my code:
Thanks!! =)
I'm trying to use a new texture on top of the terrain textures(base, lightmap, etc...) to add some effects.
When I use any of the OpenGL textures below GL_TEXTURE4_ARB it works fine.
These textures appears to already been used by the terrain:
GL_TEXTURE0_ARB - Base texture
GL_TEXTURE1_ARB - Lightmap
GL_TEXTURE2_ARB - Fog
GL_TEXTURE3_ARB - Not sure
So I'm trying to use the GL_TEXTURE4_ARB but when I use this one nothing happens.
Any ideas???
Below is my code:
if(mXFIndexCount)
{
if(blendedlighting)
{
glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, mCurrentBlock->lightMapTexture.getGLName());
...
}
PROFILE_START(TerrainRenderBind);
glBindTexture(GL_TEXTURE_2D, walk->handle.getGLName());
doTexGens(sgTexGenS, sgTexGenT);
PROFILE_END();
// -----------------------------------------------------------------------------
PROFILE_START(TerrainRenderCaustics);
//
// WORKS VERY WELL WITH GL_TEXTURE1_ARB
//
glActiveTextureARB(GL_TEXTURE4_ARB);
glClientActiveTextureARB(GL_TEXTURE4_ARB);
glEnable(GL_TEXTURE_2D);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE);
glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
F32 offset = 10.0 / (F32(mCurrentBlock->getSquareSize() * mCurrentBlock->mCausticsSize) * TerrainBlock::BlockSize);
glTexGenfv(GL_S, GL_OBJECT_PLANE, Point4F(offset, 0, 0, 0));
glTexGenfv(GL_T, GL_OBJECT_PLANE, Point4F(0, offset, 0, 0));
// Timer
static U32 lastTime = Platform::getRealMilliseconds();
static U32 elapsedTime = 0;
static int currentFrame = 0;
U32 currentTime = Platform::getRealMilliseconds();
elapsedTime = currentTime - lastTime;
if (mCurrentBlock->mCausticsTextureHandle[currentFrame])
glBindTexture(GL_TEXTURE_2D, mCurrentBlock->mCausticsTextureHandle[currentFrame].getGLName());
// Update frame
if (elapsedTime > 100 * (1.0/mCurrentBlock->mCausticsSpeed) )
{
currentFrame++;
if (currentFrame == TerrainBlock::NumCausticsTextures ||
!mCurrentBlock->mCausticsTextureHandle[currentFrame])
currentFrame = 0;
lastTime = currentTime;
elapsedTime = 0;
}
PROFILE_END();
// -----------------------------------------------------------------------------
PROFILE_START(TerrainRenderSetVertexBuffer);
if(vertexBuffer)
glSetVertexBufferEXT(block->mVertexBuffer);
if(lockArrays)
glLockArraysEXT(0, mXFPointCount);
// lock the array
PROFILE_END();
PROFILE_START(TerrainRenderXFRender);
renderXFCache();
PROFILE_END();
// Redo
glDisable(GL_TEXTURE_2D);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
//glClientActiveTextureARB(GL_TEXTURE0_ARB);
glActiveTextureARB(GL_TEXTURE0_ARB);
...
...
}Thanks!! =)
#2
12/22/2006 (1:24 pm)
I tested this code on a GeForce 6800 XT, so I think this is not the problem.
#3
12/22/2006 (3:28 pm)
Yep, exactly your problem. No nVidia card allows more than four textures through the fixed function pipeline. To use more than four textures on an nVidia card, you must use shaders.
#4
I used the OpenGL Extesions Viewer and my videocard only support 4 simultaneous textures...
I found this really strange because the directx (according to dxcaps) support 8 textures.
Anyway, thanks for the help! =)
12/22/2006 (6:53 pm)
Alex you was right.I used the OpenGL Extesions Viewer and my videocard only support 4 simultaneous textures...
I found this really strange because the directx (according to dxcaps) support 8 textures.
Anyway, thanks for the help! =)
#5
Disabling blended lighting also frees up GL_TEXTURE2_ARB (in case you need an extra texture unit).
12/22/2006 (7:39 pm)
GL_TEXTURE3_ARB is available in the main terrain rendering pass.Disabling blended lighting also frees up GL_TEXTURE2_ARB (in case you need an extra texture unit).
#6
It seens to be working now.
Thanks!!!
12/22/2006 (9:47 pm)
I putted the fog texture in the GL_TEXTURE3_ARB texture, and then I used the GL_TEXTURE2_ARB.It seens to be working now.
Thanks!!!
Associate Alex Scarborough