Jump to content
  • Advertisement
Sign in to follow this  
juanmanuelsanchez

OpenGL Multitexturing question

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

hi all ! Im trying to get my hands into multi texturing so I can implement shaders, this is my implementation
void ASE::draw()
 {
   outs("ASE::draw",0);

   //cg.BumpMap();
   glDisable(GL_LIGHTING);
   if (loaded) {
     if (currentScale != desiredScale)
       setScale(desiredScale);

     // Since we know how many objects our model has, go through each of them.
	 
     for (int i=0; i < ASEModel.numOfObjects; i++) {
 
       // Make sure we have valid objects just in case. (size() is in the vector class)
       if (ASEModel.pObject.size() <= 0) break;
 
       // Get the current object that we are displaying
       tASEObject *pObject = &ASEModel.pObject;
 
       // Check to see if this object has a texture map, if so bind the texture to it.
       if (pObject->bHasTexture) {

         // Turn on texture mapping and turn off color
         
 
      // Reset the color to normal again
     glColor3ub(255, 255, 255);

    // The first texture unit contains the detail texture
     glActiveTextureARB(GL_TEXTURE0_ARB);
	 glClientActiveTextureARB(GL_TEXTURE0_ARB);
     glEnable(GL_TEXTURE_2D);
	 glBindTexture(GL_TEXTURE_2D, ASEModel.pMaterials[pObject->materialID].texureId);

    // The second texture unit contains the normalmap texture
    glActiveTextureARB(GL_TEXTURE1_ARB);
	glClientActiveTextureARB(GL_TEXTURE1_ARB);
    glEnable(GL_TEXTURE_2D);
	glBindTexture(GL_TEXTURE_2D,ASEModel.pMaterials[pObject->materialID+1].texureId);

//    CGparameter ambientColorParameter = cgGetNamedParameter(program, "ambientColor");
//    cgGLSetParameter3f(ambientColorParameter, 0.8980f,	0.1373f,	0.1373f);

         // Bind the texture map to the object by it's materialID
         // bindTexture2D(ASEModel.pMaterials[pObject->materialID].texureId);
     }
      else {
         // Turn off texture mapping and turn on color
         glDisable(GL_TEXTURE_2D);
         glEnable(GL_COLOR);
         glEnable(GL_COLOR_MATERIAL);
 
         // Reset the color to normal again

         glColor3ub(255, 255, 255);
       }
      // glTranslatef(10.0, -1.0, -80.0f);
       glBegin(GL_TRIANGLES);    // Begin drawing with our selected mode (triangles or lines)
    
       // Go through all of the faces (polygons) of the object and draw them
       for (int j=0; j < pObject->numOfFaces; j++) {
		 
         // Go through each corner of the triangle and draw it.
         for (int whichVertex=0; whichVertex < 3; whichVertex++) {
           // Get the vertex index for each point of the face
           int vertIndex = pObject->pFaces[j].vertIndex[whichVertex];
          
           // Give OpenGL the normal for this vertex.
           glNormal3f(pObject->pNormals[ vertIndex ].x, pObject->pNormals[ vertIndex ].y, pObject->pNormals[ vertIndex ].z);

           // If the object has a texture associated with it, give it a texture coordinate.
           if (pObject->bHasTexture) {
            // Make sure there was a UVW map applied to the object or else it won't have tex coords.
             if (pObject->pTexVerts) {
               // Get the texture coordinate index
              int coordIndex = pObject->pFaces[j].coordIndex[whichVertex];
              // glColor3f(10, 10, 10);

               // Assign the UV coordinates to the current vertex being rendered
               //glTexCoord2f(pObject->pTexVerts[ coordIndex ].x, pObject->pTexVerts[ coordIndex ].y);

			   // Bind the texture coordinates to TEXTURE0 and
               // interpolate them across the edge
               glMultiTexCoord2fARB(GL_TEXTURE0_ARB,pObject->pTexVerts[ coordIndex ].x, pObject->pTexVerts[ coordIndex ].y);

			   GLfloat cubeColor[] = { 0.6f, 0.7f, 1.0f, 1.0f };
			   GLfloat cubeSpecular[] = { 1.0f, 1.0f, 1.0f, 1.0f };
			   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, cubeColor);
			   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, cubeSpecular);
               glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 10.0f);

               // Bind the normalmap coordinates to TEXTURE1 and
               // interpolate them across the edge
               glMultiTexCoord2fARB(GL_TEXTURE1_ARB,pObject->pTexVerts[ coordIndex ].x, pObject->pTexVerts[ coordIndex ].y);

			   
		
			 
             }
           }
          else {
             // Make sure there is a valid material/color assigned to this object
             if (ASEModel.pMaterials.size() && pObject->materialID >= 0) {
               // Get and set the color that the object is, since it must not have a texture
               float *pColor = ASEModel.pMaterials[pObject->materialID].fColor;
               // Assign the current color to this model
               glColor3f(pColor[0], pColor[1], pColor[2]);
             }
           }
 
           // Pass in the current vertex of the object (Corner of current face)
           glVertex3f(pObject->pVerts[ vertIndex ].x, pObject->pVerts[ vertIndex ].y, pObject->pVerts[ vertIndex ].z);
         }
       }
   
	glEnd();   
	
    glActiveTextureARB(GL_TEXTURE0_ARB);
	glDisable(GL_TEXTURE_2D);
	glActiveTextureARB(GL_TEXTURE1_ARB);
	glDisable(GL_TEXTURE_2D);

    // End the drawing
    glColor3f(0,0,0);
    // glDisable(GL_TEXTURE_2D);
    glDisable(GL_COLOR_MATERIAL);
    glEnable(GL_LIGHTING);

     }
   }
   outs("OUT OF ASE::draw",0);
 }


The problem is that If I use multitexturing then other objects that are being rendered get affected, for example I have sun in a dome but I cant see it, I just see the gometry. If I comment the ARB texturing and enable the "default" texturing method wich is commented in this source everything works... Here is a image Example Please any help is appreciated. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Just a though from glancing at your code, but perhapes its that you end your multi-texture in Texture Unit 1 instead of 0, the problem is going to be that your Code alters the state, and does not restore the state that is required for the other objects in your scene. make sure that what you got going in is what you got going out. pushs/pops are very helpful for this, hope that helps some

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!