Sign in to follow this  

multiple tex coords with VBOs

This topic is 4279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok I've tried it out with the commands given but it dosn't work.
This code is based off a couple of chapers from More OGL game programming.
basically the problem is with sending the textures to the GLSL shader, the tex coords seem to be ok.
All the code here should be self explainatory and if you give it a read you'll quikly see what I'm tring to do.

It's a culled terrain with a decal(colour?) map and a detail map rendered with GLSL and VBOs.

void TerrainLOD::Draw(CFrustum *frustum)
{

shader->use();

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TerrainLOD::decal);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, TerrainLOD::detail);

shader->sendUniform("tex", TerrainLOD::decal);
shader->sendUniform("detailTex", TerrainLOD::detail);

glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);

for(int i = 0;i<numChunks;i++)
{
//Check to make sure that the terrain section is in the frustum
if (frustum->pointInFrustum(chunks[i].maxX, chunks[i].maxY, chunks[i].maxZ) ||
frustum->pointInFrustum(chunks[i].minX, chunks[i].maxY, chunks[i].minZ) ||
frustum->pointInFrustum(chunks[i].minX, chunks[i].maxY, chunks[i].maxZ) ||
frustum->pointInFrustum(chunks[i].maxX, chunks[i].maxY, chunks[i].minZ) ||
frustum->pointInFrustum(chunks[i].maxX, chunks[i].minY, chunks[i].maxZ) ||
frustum->pointInFrustum(chunks[i].minX, chunks[i].minY, chunks[i].minZ) ||
frustum->pointInFrustum(chunks[i].minX, chunks[i].minY, chunks[i].maxZ) ||
frustum->pointInFrustum(chunks[i].maxX, chunks[i].minY, chunks[i].minZ))
{
glBindBuffer(GL_ARRAY_BUFFER, vertBuffers[i]);
glVertexPointer(3, GL_FLOAT, 0, (void*)0);
glClientActiveTexture(GL_TEXTURE0);
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(chunkSize*chunkSize*4*3*sizeof(float));
glClientActiveTexture(GL_TEXTURE1);
glTexCoordPointer(2, GL_FLOAT, 0, BUFFER_OFFSET(chunkSize*chunkSize*4*3*sizeof(float)+chunkSize*chunkSize*4*2*sizeof(float));
glDrawArrays(GL_QUADS, 0, chunkSize*chunkSize*4);
}
}
shader->disable();

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
};

P.S. how can I do the code box thing?

Share this post


Link to post
Share on other sites
Quote:
Original post by arbuckle911
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, TerrainLOD::decal);
glActiveTexture(GL_TEXTURE1);
glBindTexture(GL_TEXTURE_2D, TerrainLOD::detail);

shader->sendUniform("tex", TerrainLOD::decal);
shader->sendUniform("detailTex", TerrainLOD::detail);

When setting the uniform for a sampler in a shader, you must set the value as the *texture unit*, not the texture object ID. So your code above should be:

shader->sendUniform("tex", 0);
shader->sendUniform("detailTex", 1);


Quote:
P.S. how can I do the code box thing?

Use [ source] and [/source ] tags around your source code.

Share this post


Link to post
Share on other sites
Cool, this works. But it has now created another problem. I want to set my openGL state back to what it originally was. The textures I have bound here carry over to other objects. How can I go back to the normal glBindTexture() and have ogl ingore all the others?

Share this post


Link to post
Share on other sites
after rendering your terrain where you are disabling the client state's try:


glActiveTextureARB(GL_TEXTURE1);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0);
glDisable(GL_TEXTURE_2D);

Share this post


Link to post
Share on other sites

This topic is 4279 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this