Sign in to follow this  

Texture coords in Cg

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

I am doing some simple Cg stuff. Mostly it is working but I am having some problems. The source code below is working when I #define USE_OPENGL_ACTIVATION. The textures are appearing and the texcoords are correct. But if I skip the glClientActiveTexture(...) and glActiveTexture(...) calls, although I get correct textures on the meshes, the texcoords does not seem to be used. The meshes are only drawn with one color. As you can see, I am calling cgGLSetTextureParameter(...) and cgGLEnableTextureParameter(...) in correct order. I call the appropiate glEnableClientState(GL_TEXTURE_COORD_ARRAY), glEnableClientState(GL_COLOR_ARRAY) etc in my setup routine. I THINK I have done everything correctly. I have tried to call glEnableClientState(GL_TEXTURE_COORD_ARRAY) when doing cgGLSetTextureParameter(...) and cgGLEnableTextureParameter(...) The thing is, I want to be able to use NVidia's 16 texture units and not only OpenGL's 4 texture units. By using OpenGL activation I am forced to work with only 4 texture units. What am I doing wrong? Am I missing some call to Cg that state NOT to use OpenGL activation? I hope some expert out there can help me :)

NGraphics3.cpp
...
// Base passes
  for (int i = 0; i < drawObject->_basePasses.size(); i++)
  {
    pass = drawObject->_basePasses[i];

    changeBlend(pass->_blendSource, pass->_blendDestination);
#ifdef USE_OPENGL_ACTIVATION
    glClientActiveTexture(GL_TEXTURE0 + i);
    glActiveTexture(GL_TEXTURE0 + i);
#endif
    if (i == 0)
    {
      texParam = cgParametersTexture0[numberOfLights];
    }
    else if (i == 1)
    {
      texParam = cgParametersTexture1[numberOfLights];
    }

    setPass(pass, texParam);
  }
...

void NGraphics3D::setPass(shared_ptr<NDrawPass> pass, CGparameter texParam)
{//@CODE_2950

  if (false)//drawObject->_preDraw)
  {
    glBindBuffer(GL_ARRAY_BUFFER, pass->_vboIdTexCoords);
    glTexCoordPointer(2, GL_FLOAT, 0, NULL);
    glBindBuffer(GL_ARRAY_BUFFER, pass->_vboIdColors);
    glColorPointer(4, GL_FLOAT, 0, NULL);
  }
  else
  {
    glTexCoordPointer(2, GL_FLOAT, 0, pass->_texCoords.get());
    glColorPointer(4, GL_FLOAT, 0, pass->_colors.get());
  }

  if (pass->_texture != NULL)
  {
    cgGLSetTextureParameter(texParam, pass->_texture->_id);
    cgGLEnableTextureParameter(texParam);
  }
  else
  {
    cgGLSetTextureParameter(texParam, 0);
    cgGLEnableTextureParameter(texParam);
  }

  if (pass->_repeat)
  {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
  }
  else
  {
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
  }


pp_lighting_f.cg
...
float4 computeFinalColor(float4 color, float4 diffuseAndSpecular, float fogExponent : TEXCOORD5, float3 fogColor,
                          uniform sampler2D tex0, uniform sampler2D tex1, uniform sampler2D lightmap, uniform sampler2D blendmap,
                          float2 texCoord0 : TEXCOORD0, float2 texCoord1 : TEXCOORD1, float2 texCoordLightmap : TEXCOORD2, float2 texCoordBlendmap : TEXCOORD3)
{
  float4 lightColor  = color + diffuseAndSpecular;
  float4 texColor0 = tex2D(tex0, texCoord0);
  float4 texColor1 = tex2D(tex1, texCoord1);
...


Share this post


Link to post
Share on other sites

This topic is 3865 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this