Advertisement

Texturing and Multitexturing

Started by December 20, 2002 09:31 AM
11 comments, last by wolf_2002 22 years, 2 months ago
Hi, is it possible, to use in one class, say for a render triangles with one texture glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture); glBegin(GL_QUADS); // Front Face glNormal3f( 0.0f, 0.0f, 1.0f); glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth); glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth); glTexCoord2f(1.0f, 1.0f); glVertex3f . . . . and in another class, a quadric as example (use multitexturing): glActiveTextureARB(GL_TEXTURE0_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture[0]); glActiveTextureARB(GL_TEXTURE1_ARB); glEnable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, m_texture[1]); glBegin(GL_TRIANGLES); glNormal3f( 0.0f, 0.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.5f, 1.0f); glVertex3f( 0.0f, m_height, 0.0f); . . . and render this together ????? Wolf
If you mean that, for instance, you want to render a house where walls have one texture and floor has two textures, then yes you can.
If you want the same wall to have both single-texture and multi-texture, then no you can''t (except you render your wall twice).
Advertisement
Thanks for helping,

the Problem is when i render the Quadric (no Multitexture)
the Texture from this looks very strange, but Triangles(with multitextures) looks o.k. .

Are you using GLU quadrics ? If so, you should call gluQuadricTexture.
my quadric looks like this:

glBegin(GL_QUADS);
// Front Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, m_depth);
// Back Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, -m_depth);
// Top Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
// Bottom Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, -m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
// Right face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 1.0f,0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
// Left Face
glColor3f(m_red,m_green,m_blue);
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, m_height, m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glEnd();
my quadric looks like this:

glBegin(GL_QUADS);
// Front Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, m_depth);
// Back Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 0.0f,-1.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, -m_depth);
// Top Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f, 1.0f, 0.0f);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
// Bottom Face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 0.0f,-1.0f, 0.0f);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, -m_height, -m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
// Right face
glColor3f(m_red,m_green,m_blue);
glNormal3f( 1.0f,0.0f, 0.0f);
glTexCoord2f(1.0f, 0.0f); glVertex3f( m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f( m_width, m_height, -m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f( m_width, m_height, m_depth);
glTexCoord2f(0.0f, 0.0f); glVertex3f( m_width, -m_height, m_depth);
// Left Face
glColor3f(m_red,m_green,m_blue);
glNormal3f(-1.0f, 0.0f, 0.0f);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-m_width, -m_height, -m_depth);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-m_width, -m_height, m_depth);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-m_width, m_height, m_depth);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-m_width, m_height, -m_depth);
glEnd();
Advertisement
what do you mean by "looks very strange" ? The quadric is single-textured, right ? Have you disabled the unused texture unit before rendering your quadric.
oh no,
how??
sorry i''am very new with OpenGL
no what ? no you didn''t disable the second texture unit ?

Is that''s it, call this to enable a texture unit :
glActiveTextureARB(GL_TEXTURE0_ARB); // could also be GL_TEXTURE1_ARB
glEnable(GL_TEXTURE_2D);

And in a very similar fashion, disable a texture unit like that :
glActiveTextureARB(GL_TEXTURE0_ARB); // could also be GL_TEXTURE1_ARB
glDisable(GL_TEXTURE_2D);

In your case, I think that you should disable the second texture unit and make sure that the first texture unit is the one that is activated. So you would call that :
glActiveTextureARB(GL_TEXTURE1_ARB);
glDisable(GL_TEXTURE_2D);
glActiveTextureARB(GL_TEXTURE0_ARB);
shame ;-), now it''s look much better

glActiveTextureARB(GL_TEXTURE0_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture[0]);

glActiveTextureARB(GL_TEXTURE1_ARB);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, m_texture[1]);

glBegin(GL_TRIANGLES);

glNormal3f( 0.0f, 0.0f, 1.0f);
glColor3f(m_red1,m_green1,m_blue1);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.5f, 1.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.5f, 1.0f);
glVertex3f( 0.0f, m_height, 0.0f);
// Top

glColor3f(m_red2,m_green2,m_blue2);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);
glVertex3f(-m_width,-m_height, 0.0f);
// Bottom Left

glColor3f(m_red3,m_green3,m_blue3);
glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 1.0f, 0.0f);
glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 1.0f, 0.0f);
glVertex3f( m_width,-m_height, 0.0f);
// Bottom Right
glEnd();
glPopMatrix();

glDisable(GL_TEXTURE_2D);


the last ''glDisable(GL_TEXTURE_2D);'' disable both textures??
mh,my Bitmapfont looks still strange (total black).

This topic is closed to new replies.

Advertisement