PDA

View Full Version : 2 textures(diferent coords) in one polygon



lsdi
02-20-2002, 10:43 AM
How do I render 2 textures with diferent coords in one polygon?

example:

1 very large texture for a terrain, whe I get closer, render the large terrain and a small texture to make the ground more realistic.

256x256 tile (quad)
256x256 texture covering all the quad
256x256 texture repeating X times to make a more detailed terrain


I was reading about ARB extension in nehe, but its not a good tutorial about this subject.

sorry for bad english.

Leyder Dylan
02-21-2002, 09:16 AM
Hi,

Use multitexturing.

Here's a example :

// 1. Première unité de texture
glActiveTextureARB(GL_TEXTURE0_ARB);
glBindTexture(GL_TEXTURE_2D, Texture_BMP[0]);
glEnable(GL_TEXTURE_2D);

// 2. Deuxième unité de texture
glActiveTextureARB(GL_TEXTURE1_ARB);
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
/*
GL_MODULATE ==> Mélange les 2 textures
GL_REPLACE ==> Remplace la texture existante
*/
glBindTexture(GL_TEXTURE_2D, Texture_BMP[1]);
glEnable(GL_TEXTURE_2D);

glBegin(GL_QUADS);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 1.0f); // Coord. 1ère texture
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 1.0f); // Coord. 2ème texture
glVertex3f( 0.75f, 0.75f, 0); // Coin supérieur droit

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f); // Coord. 1ère texture
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f); // Coord. 2ème texture
glVertex3f( 0.75f, -0.75f, 0); // Coin inférieur droit

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f); // Coord. 1ère texture
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f); // Coord. 2ème texture
glVertex3f(-0.75f, -0.75f, 0); // Coin inférieur gauche

glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 1.0f); // Coord. 1ère texture
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 1.0f); // Coord. 2ème texture
glVertex3f(-0.75f, 0.75f, 0); // Coin supérieur gauche
glEnd();