Jump to content
  • Advertisement
Sign in to follow this  
arbuckle911

multiple tex coords with VBOs

This topic is 4488 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

how can I send multiple tex coord sets to a GLSL shader via vertex buffer objects? (I know how to do one with vertex and normal data)

Share this post


Link to post
Share on other sites
Advertisement
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.maxX, chunks.maxY, chunks.maxZ) ||
frustum->pointInFrustum(chunks.minX, chunks.maxY, chunks.minZ) ||
frustum->pointInFrustum(chunks.minX, chunks.maxY, chunks.maxZ) ||
frustum->pointInFrustum(chunks.maxX, chunks.maxY, chunks.minZ) ||
frustum->pointInFrustum(chunks.maxX, chunks.minY, chunks.maxZ) ||
frustum->pointInFrustum(chunks.minX, chunks.minY, chunks.minZ) ||
frustum->pointInFrustum(chunks.minX, chunks.minY, chunks.maxZ) ||
frustum->pointInFrustum(chunks.maxX, chunks.minY, chunks.minZ))
{
glBindBuffer(GL_ARRAY_BUFFER, vertBuffers);
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!