www.quadsoftware.com
FAQ  FAQ   Search  Search   Memberlist  Memberlist   Usergroups  Usergroups
Register  ::  Log in Log in to check your private messages


Post new topic  Reply to topic
 Masking & MultiTexturing « View previous topic :: View next topic » 
Author Message
Hornsj2
PostPosted: Sat Mar 29, 2008 11:27 pm    Post subject: Masking & MultiTexturing Reply with quote



Joined: 24 Mar 2008
Posts: 16

Could anyone give me some advice on how to apply Grome's color layers to a scene via multitexturing? I have been going over the OSG file to get a sense of what needs to be done but there is something I am not doing correctly because it seems like one of the masks is not being applied.

I've only been working with OpengGL for about 3 months now and this is my first attempt at multitexturing.

That being said, here is what I have so far in one of my initialization functions just after loading the textures (please forgive the ugliness).

Here, the masks are bound to texture[1] and texture[3], the tiled texture is bound to texture[0] and texture [2]. All files are in RGB bitmap format.


Code:

   glActiveTexture(GL_TEXTURE0);
   glClientActiveTexture(GL_TEXTURE0);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[0]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);
   
   
   GLfloat plane_s[] = {1, 0, 0, 50};
   GLfloat plane_t[] = {0, -1.50996e-007 , 1, 7.54979e-006};
   GLfloat plane_r[] = {0, 0, 1, 0};
   GLfloat plane_q[] = {0, 0, 0, 1};
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_S, GL_OBJECT_PLANE, plane_s);
   glTexGenfv(GL_T, GL_OBJECT_PLANE, plane_t);
   glTexGenfv(GL_R, GL_OBJECT_PLANE, plane_r);
   glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane_q);
   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glEnable(GL_TEXTURE_GEN_R);
   glEnable(GL_TEXTURE_GEN_Q);
   glMatrixMode(GL_TEXTURE);
   glPushMatrix();
      glLoadIdentity();
      glRotatef(1.570796, 0, 1, 0);
      glScalef(0.100000, 0.10000, 1);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);
   
   
   

   
   glActiveTexture(GL_TEXTURE1);
   glClientActiveTexture(GL_TEXTURE1);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[1]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);

         
   glActiveTexture(GL_TEXTURE2);
   glClientActiveTexture(GL_TEXTURE2);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[2]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);

   
   GLfloat plane2_s[] = {7.54979e-008, 1, 0, 50};
   GLfloat plane2_t[] = {-1.50996e-007 , 1.13999e-014  , 1, -7.54979e-006};
   GLfloat plane2_r[] = {0, 0, 1, 0};
   GLfloat plane2_q[] = {0, 0, 0, 1};
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_S, GL_OBJECT_PLANE, plane2_s);
   glTexGenfv(GL_T, GL_OBJECT_PLANE, plane2_t);
   glTexGenfv(GL_R, GL_OBJECT_PLANE, plane2_r);
   glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane2_q);
   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glEnable(GL_TEXTURE_GEN_R);
   glEnable(GL_TEXTURE_GEN_Q);
   glMatrixMode(GL_TEXTURE);
   glPushMatrix();
      glLoadIdentity();
      glRotatef(1.570796, 1, 1, 0);
      glScalef(0.100000, 0.100000, 1);
   glPopMatrix();
   glMatrixMode(GL_MODELVIEW);

      
   glActiveTexture(GL_TEXTURE3);
   glClientActiveTexture(GL_TEXTURE3);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[3]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);



And in my display function I have this:

Code:

glScalef(1.0, 1.0, 1.0);
   glTranslatef(0.0, -5.0, -80.0);
         
   glEnable(GL_BLEND);
   glDisable(GL_DEPTH_TEST);
   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

   glVertexPointer(3, GL_FLOAT, 0, GromeVertices);
   glEnableClientState(GL_VERTEX_ARRAY);

    glActiveTexture (GL_TEXTURE1);
    glClientActiveTexture (GL_TEXTURE1);
    glTexCoordPointer (2, GL_FLOAT, 0, testTextureCoords);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);
   
   glActiveTexture (GL_TEXTURE3);
    glClientActiveTexture (GL_TEXTURE3);
    glTexCoordPointer (2, GL_FLOAT, 0, testTextureCoords);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);

   glDrawElements(GL_TRIANGLES, GromeIndexCount, GL_UNSIGNED_INT, GromeVertexIndices);
   
   glDisable(GL_BLEND);
   glEnable(GL_DEPTH_TEST);
      
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glDisableClientState(GL_VERTEX_ARRAY);



You may notice I have nothing here for TEXTURE0 and TEXTURE2 because I assumed that the generated texture coordinates eliminate the need to specify anything here for those stages.

At this point the terrain looks like it has been mapped correctly on faces in one direction but not in all directions.

Any help would be appreciated.

Hornsj2
Crying or Very sad
Back to top
View user's profile Send private message
Hornsj2
PostPosted: Sun Mar 30, 2008 11:54 am    Post subject: Solved Reply with quote



Joined: 24 Mar 2008
Posts: 16

I was able to find a solution to my problem by breaking the code down into sub-parts. First, the textures that I was going to use for Alpha values were straight RGB files with no alpha component. I had converted them from the 8 bit targa file to a 24 bit bitmap because I didn't have a targa loader. Once I got the targa loader and invoked the draw command for each texture it worked.

Here is my display function. The code is still crude but I will streamline it now that I know what I need to do.

Code:


glScalef(1.0, 1.0, 1.0);
   glTranslatef(0.0, -5.0, -80.0);
         
   glVertexPointer(3, GL_FLOAT, 0, GromeVertices);
   glEnableClientState(GL_VERTEX_ARRAY);

   glEnable(GL_BLEND);
   
   
   drawOne();
   glDrawElements(GL_TRIANGLES, GromeIndexCount, GL_UNSIGNED_INT, GromeVertexIndices);
      
   drawFour();
   glDrawElements(GL_TRIANGLES, GromeIndexCount, GL_UNSIGNED_INT, GromeVertexIndices);
   
   
   drawTwo();
   glDrawElements(GL_TRIANGLES, GromeIndexCount, GL_UNSIGNED_INT, GromeVertexIndices);

   drawThree();
   glDrawElements(GL_TRIANGLES, GromeIndexCount, GL_UNSIGNED_INT, GromeVertexIndices);

   glDisable(GL_BLEND);
   
      
   glDisableClientState(GL_TEXTURE_COORD_ARRAY);
   glDisableClientState(GL_VERTEX_ARRAY);



Here are my setup functions for each pass.

Code:

void drawOne()
{
   static GLfloat constColor[4] = {0.0, 0.0, 0.0, 0.0};
   glActiveTexture(GL_TEXTURE0);
   glClientActiveTexture(GL_TEXTURE0);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[0]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);
   
   
   GLfloat plane_s[] = {1, 0, 0, 50};
   GLfloat plane_t[] = {0, -1.50996e-007 , 1, 7.54979e-006};
   GLfloat plane_r[] = {0, 0, 1, 0};
   GLfloat plane_q[] = {0, 0, 0, 1};
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_S, GL_OBJECT_PLANE, plane_s);
   glTexGenfv(GL_T, GL_OBJECT_PLANE, plane_t);
   glTexGenfv(GL_R, GL_OBJECT_PLANE, plane_r);
   glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane_q);
   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glEnable(GL_TEXTURE_GEN_R);
   glEnable(GL_TEXTURE_GEN_Q);
   glMatrixMode(GL_TEXTURE);
   
      glLoadIdentity();
      glRotatef(1.570796, 0, 1, 0);
      glScalef(0.100000, 0.10000, 1);
   
   glMatrixMode(GL_MODELVIEW);

   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
   //glBlendFunc(GL_SRC_ALPHA,GL_ONE);
}
void drawTwo()
{
   static GLfloat constColor[4] = {0.0, 0.0, 0.0, 0.0};
   

   glActiveTexture(GL_TEXTURE1);
   glClientActiveTexture(GL_TEXTURE1);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[1]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);

   glActiveTexture (GL_TEXTURE1);
    glClientActiveTexture (GL_TEXTURE1);
    glTexCoordPointer (2, GL_FLOAT, 0, testTextureCoords);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);
   
   //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

}
void drawThree()
{
   static GLfloat constColor[4] = {0.0, 0.0, 0.0, 0.0};
   glActiveTexture(GL_TEXTURE0);
   glClientActiveTexture(GL_TEXTURE0);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[2]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);

   GLfloat plane_s[] = {1, 0, 0, 50};
   GLfloat plane_t[] = {0, 0 , 1, 1};
   
   GLfloat plane2_s[] = {7.54979e-008, 1, 0, 50};
   GLfloat plane2_t[] = {-1.50996e-007 , 1.13999e-014  , 1, -7.54979e-006};
   GLfloat plane2_r[] = {0, 0, 1, 0};
   GLfloat plane2_q[] = {0, 0, 0, 1};
   glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGeni(GL_Q, GL_TEXTURE_GEN_MODE, GL_OBJECT_LINEAR);
   glTexGenfv(GL_S, GL_OBJECT_PLANE, plane_s);
   glTexGenfv(GL_T, GL_OBJECT_PLANE, plane_t);
   glTexGenfv(GL_R, GL_OBJECT_PLANE, plane2_r);
   glTexGenfv(GL_Q, GL_OBJECT_PLANE, plane2_q);
   glEnable(GL_TEXTURE_GEN_S);
   glEnable(GL_TEXTURE_GEN_T);
   glEnable(GL_TEXTURE_GEN_R);
   glEnable(GL_TEXTURE_GEN_Q);
   glMatrixMode(GL_TEXTURE);
      glLoadIdentity();
      glRotatef(1.570796, 1, 1, 0);
      glScalef(0.100000, 0.100000, 1);
   glMatrixMode(GL_MODELVIEW);

   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

}
void drawFour()
{

   static GLfloat constColor[4] = {0.0, 0.0, 0.0, 0.0};
   glActiveTexture(GL_TEXTURE1);
   glClientActiveTexture(GL_TEXTURE1);
   glEnable(GL_TEXTURE_2D);
   glBindTexture(GL_TEXTURE_2D, Texture[3]);
   glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, constColor);
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_PREVIOUS);
   glTexEnvf(GL_TEXTURE_ENV, GL_SRC2_ALPHA, GL_CONSTANT);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_RGB, GL_SRC_COLOR);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND0_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND1_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_OPERAND2_ALPHA, GL_SRC_ALPHA);
   glTexEnvf(GL_TEXTURE_ENV, GL_RGB_SCALE, 1);
   glTexEnvf(GL_TEXTURE_ENV, GL_ALPHA_SCALE, 1);

   glActiveTexture (GL_TEXTURE3);
    glClientActiveTexture (GL_TEXTURE3);
    glTexCoordPointer (2, GL_FLOAT, 0, testTextureCoords);
    glEnableClientState (GL_TEXTURE_COORD_ARRAY);

   glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

}




I'm so new to this and graphics programming in general that I'm sure there is something I have overlooked so if you have any suggestions I would appreciate them. If not, no worries, it might be better to learn this stuff by doing it.

Hornsj2 Very Happy
Back to top
View user's profile Send private message
ALicu
PostPosted: Mon Mar 31, 2008 8:04 am    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Hi,

Yes, the OSG exporter it is using multipass rendering for each layer. So the tile is bind to texture unit 0 and the mask is bind to texture unit 1. This is because the OSG code is made for compatibility so it can run with any card with at least 2 texture units. This being said, you can of course collapse multiple layers in the same rendering pass (you can use for example 8 texture units and render 3-4 layers). From my experience if geometry is not the bottleneck (and for terrain it usually not since you have LOD), it doesn't matter if you do multipass or multitexturing with less rendering passes. For terrain fillrate (texturing) is usually bottleneck so there you should take care for optimization (example: using a backed texture with multiple layers combined into a single image for far distance). Also for the vast majority of cards, using 4 textures per pass rather two is almost 2 times as slower so rendering multipass or multitexturing doesn't make any different (unless the card is from the latest generations).

In the first code you've posted you tried to render 2 layer but in a single pass. That's why it wasn't correct, you've tried to use the state for two rendering passes (from the OSG exporter).

For the second post, you've rendered the geometry 4 times, when it should be just 2 times. I think you should use something like drawOne(); drawTwo(); render; drawThree(); drawFour(); render. Need to test it thought.

To be noted that between rendering passes (between layers) the OSG rendering it is using alpha blending (with the colors of the previous layer found in the frame buffer). So the a layer is rendered with something like alpha, 1-alpha so it appears on top of an underlaying layer only when his mask (alpha) is opaque.

OSG is a good example to follow the exact rendering for Grome scenes. Just be aware that it is using one rendering pass (followed by alpha blend) for each layer. You should also refer to the OSG exporter source code. See _GetMaterialLayerState function in ExpOsg.cpp (found in the Grome SDK) to see how OpenGL state is setup for each type of layer Grome supports.

My opinion is to try to obtain one layer rendering per pass first. Then optimize (collapse passes) as you understand the rendering states involved.

Also, please don't hesitate to post any code here. I will try to help you as much as I can.

Regards,
Adrian L.
Back to top
View user's profile Send private message
Hornsj2
PostPosted: Mon Mar 31, 2008 2:12 pm    Post subject: Thank you Reply with quote



Joined: 24 Mar 2008
Posts: 16

That information is extremely helpful.

Thank you,

Hornsj2
Back to top
View user's profile Send private message
Starstone
PostPosted: Thu Jun 05, 2008 3:30 am    Post subject: Reply with quote



Joined: 13 Mar 2008
Posts: 3

>My opinion is to try to obtain one layer rendering per pass first.
>Then optimize (collapse passes) as you understand the rendering
> states involved.

Is there an automated way to tell OSG to collapse the passes?

Richard
Back to top
View user's profile Send private message
ALicu
PostPosted: Thu Jun 05, 2008 6:31 am    Post subject: Reply with quote



Joined: 12 Feb 2007
Posts: 1326

Hi,

The OSG exporter currently doesn't collapse passes automatically. Depending on your hardware target (mainly on the hardware number of texture units) you can create OpenGL states to render multiple layers into a single pass. We didn't include this optimizations because there are so many ways to do it (different hardware, different layers types and combinations). We've included only the most compatible mode (i.e. one layer per pass). Clients can easily modify the exporter to create more optimized cases for their custom applications. I am more than happy to help you if you provide more information about your layer structure (how you organize the layers) and your hardware target.

But collapsing passes will not be a magical solution to greatly increase your performance. One great optimization is terrain geometry LOD implementation for OSG (and this is a also very application specific).

Also another great optimization is to create a collapsed texture with all the layers baked in it. This texture will be rendered (in a single pass) only for far distances while for lower distances the multiple pass layers will be used.

Best Regards,
Adrian L.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Based on a template by Dustin Baccetti
Powered by phpBB © 2001, 2005 phpBB Group