Help with textures, TMUs, and glDrawArrays in Torque
by Max Robinson · in Torque Game Engine · 08/31/2003 (11:48 am) · 7 replies
This is one of the last things stopping me from releasing my mesh effects. I pretty much have it working, except I'm not 100% sure the color coordinates are right, and for some reasons textures don't render. For simplicity's sake, I am doing only 1 ARB with 1 texture, just to see if I can get that working. The main problem is that NO texture renders. I get the shape, color fading (which I said seemed a tad off, it doesnt seem to fade enough), but there is not texture. Anyway, here's the code:
Now for the code that sets up the vertex array:
From other code I have seen, this SHOULD work, but it doesn't. Also, I have re-organized the different calls for setting up the TMU (for instance, doing blend func first, or doing it last, etc), and it hasn't changed ANYTHING.
I've set everything up to be very clear, but I still can't see why its not doing my textures.
setupVertices(); // EXTRA glDisable(GL_CULL_FACE); glDepthMask(GL_FALSE); //------------------------------------ // ACTIVATE TMU #0 //------------------------------------ glActiveTextureARB(GL_TEXTURE0_ARB); glClientActiveTextureARB(GL_TEXTURE0_ARB); glEnableClientState(GL_VERTEX_ARRAY); glVertexPointer(3, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].point)); glEnable(GL_BLEND); glEnable(GL_TEXTURE_2D); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].texCoord)); glEnableClientState(GL_COLOR_ARRAY); glColorPointer(4, GL_FLOAT, sizeof(vertex), &(m_rVerts[0].color)); glBindTexture(GL_TEXTURE_2D, mDataBlock->textureHandle[0].getGLName()); if(mDataBlock->texInvAlpha[0]) glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA ); else glBlendFunc( GL_SRC_ALPHA, GL_ONE); if (dglDoesSupportCompiledVertexArray()) glLockArraysEXT(0, m_numVerts); glDrawArrays( GL_QUAD_STRIP,0,m_numVerts); if (dglDoesSupportCompiledVertexArray()) glUnlockArraysEXT(); //------------------------------------ // DEACTIVE TMU #0 //------------------------------------ glActiveTextureARB(GL_TEXTURE0_ARB); glClientActiveTextureARB(GL_TEXTURE0_ARB); glDisable(GL_TEXTURE_2D); glDisable(GL_BLEND); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glDisableClientState(GL_COLOR_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); // EXTRA glDepthMask(GL_TRUE);
Now for the code that sets up the vertex array:
void Shockflash::setupVertices()
{
m_numVerts = 0;
for( U32 i=0; i < outerRing.points.size(); i++ )
{
F32 ang = F32(i) / F32(outerRing.points.size());
m_rVerts[m_numVerts].point = outerRing.points[i].position;
m_rVerts[m_numVerts].color = mRingColor;
m_rVerts[m_numVerts].texCoord.set(ang,1);
m_numVerts++;
m_rVerts[m_numVerts].point = innerRing.points[i].position;
m_rVerts[m_numVerts].color = mColor;
m_rVerts[m_numVerts].texCoord.set(ang,0);
m_numVerts++;
}
//m_rVerts[m_numVerts] = m_rVerts[0];
m_rVerts[m_numVerts].point = outerRing.points[0].position;
m_rVerts[m_numVerts].color = mRingColor;
m_rVerts[m_numVerts].texCoord.set(1,1);
m_numVerts++;
//m_rVerts[m_numVerts] = m_rVerts[1];
m_rVerts[m_numVerts].point = innerRing.points[0].position;
m_rVerts[m_numVerts].color = mColor;
m_rVerts[m_numVerts].texCoord.set(1,0);
m_numVerts++;
}From other code I have seen, this SHOULD work, but it doesn't. Also, I have re-organized the different calls for setting up the TMU (for instance, doing blend func first, or doing it last, etc), and it hasn't changed ANYTHING.
I've set everything up to be very clear, but I still can't see why its not doing my textures.
#2
But I have an old method:
Is there something special you have to do with glBindTexture when using arrays?
09/01/2003 (7:18 am)
Yeah it does show up white...But I have an old method:
glDisable(GL_CULL_FACE);
glDepthMask(GL_FALSE);
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
for(int t = 0; t < mDataBlock->NUM_TEX; t++)
{
if(bool(mDataBlock->textureHandle[t]) || t == 0)
{
if(mDataBlock->texInvAlpha[t])
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
else
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
//Con::warnf(ConsoleLogEntry::General,"%d",mDataBlock->textureHandle[t]);
glBindTexture( GL_TEXTURE_2D, mDataBlock->textureHandle[t].getGLName() );
renderSegment(t);
}
}
glDisable(GL_TEXTURE_2D);
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);This one works perfectly, I tested it by rendering 2 horizontal line textures with different wrap, so you could tell it was working because you could see the 2 differently scaled textures on top of eachother. But like I said it doesnt work with the ARBs.Is there something special you have to do with glBindTexture when using arrays?
#3
I'll have a little time tonight so if you want to send the code (that doesn't work) to me then I can find the problem for you.
It's probably easier than snooping at little pieces of code.
- Melv.
09/01/2003 (7:24 am)
Max,I'll have a little time tonight so if you want to send the code (that doesn't work) to me then I can find the problem for you.
It's probably easier than snooping at little pieces of code.
- Melv.
#4
Melv, do you have a messenger program of some sort? If you want to look at the code itd be a lot easier that way. Just mail me your info.
09/01/2003 (7:28 am)
I just debugged it, and it appears to grab the texture ok also. I think I am missing something, but I can't figure out what I am missing.Melv, do you have a messenger program of some sort? If you want to look at the code itd be a lot easier that way. Just mail me your info.
#6
09/01/2003 (9:08 am)
Hah, this is kind of funny. Somewhere along the way, I got it working, and for the last couple days I've been laboring under the delusion that it was broken. One texture was a horizontal white strip and a black stip on top, so it would render 1/2. I just realized that on the multitexture version it was half as tall as the non multitexture version. Anyway...
Associate Melv May
On the face of it, everything seems like it should work. You mentioned that you're getting shapes rendering with colours but they are 'off' a little. Have you checked that your glBindTexture command is getting a valid object? If not, you might find that it's rendering your texture but it's appearing as white and with the modulation setting you've got, that could potentially make your colours seem 'off'.
Check that you're passing the texture name in your pack/unpack sequence correctly. I would certainly debug this routine to see if the texture object is valid.
A quick check would be to change the initial setting of GL_MODULATE to GL_REPLACE. Is it white?
- Melv.