Java-Gaming.org Java4K winners: [ by our judges | by the community ]         
Featured games (67)
games approved by the League of Dukes
Games in Showcase (∞)
games submitted by our members



News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  Print  
  3D texture problem  (Read 804 times)
0 Members and 2 Guests are viewing this topic.
Offline magiccat

JGO n00b
*

Posts: 21



« on: 2007-02-08 10:49:15 »

I have a Nvidia GeForce 6800 GS graphics card with 256 MB.   My 3D application uses the following code to set up 3D texture units and uniform variables for use in the Cg fragment shader.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
// texture setup in the application
gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glGenTextures(1, temp1, 0);
    TextureID = temp1[0];
    gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);

// Generate normals
    gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1);
    gl.glGenTextures(1, temp16, 0);
    normal_ID = temp16[0];
    gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
    // gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_MODULATE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_WRAP_R, GL.GL_CLAMP_TO_EDGE);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
    gl.glTexParameteri(GL.GL_TEXTURE_3D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);

   // setup Cg parameters
    Texture_Param = CgGL.cgGetNamedParameter(fProgram, "Texture");
    normal_Param = CgGL.cgGetNamedParameter(fProgram,"normals");
    CgGL.cgGLSetTextureParameter(Texture_Param, TextureID);
    CgGL.cgGLSetTextureParameter(normal_Param, normal_ID);
    CgGL.cgGLEnableTextureParameter(Texture_Param);
    CgGL.cgGLEnableTextureParameter(normal_Param);

--------------------------------------------------------------------------------------------------------------------------------------------------------
   // in Display()
 FloatBuffer volumeBuf = FloatBuffer.wrap(volumeBuffer);
      volumeBuf.rewind();
      gl.glActiveTexture(GL.GL_TEXTURE0);
      gl.glEnable(GL.GL_TEXTURE_3D);
      gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
      gl.glBindTexture(GL.GL_TEXTURE_3D, TextureID);
      gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGBA, iWidth, iHeight, iDepth,
                      0, GL.GL_RGBA, GL.GL_FLOAT, volumeBuf);


     FloatBuffer normal_buf = FloatBuffer.wrap(normals);
     normal_buf.rewind();
     gl.glActiveTexture(GL.GL_TEXTURE1);
     gl.glEnable(GL.GL_TEXTURE_3D);
     gl.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_OBJECT_LINEAR);
     gl.glBindTexture(GL.GL_TEXTURE_3D, normal_ID);
     gl.glTexImage3D(GL.GL_TEXTURE_3D, 0, GL.GL_RGB, iWidth, iHeight, iDepth,
                     0, GL.GL_RGB, GL.GL_FLOAT, normal_buf);

-------------------------------------------------------------------------------------------------------------------------------------------------

void FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
                                            uniform sampler3D Texture,
                                  uniform sampler3D normals) {

  //get normal
  float3 normal;
  normal.rgb = tex3Dproj(normals, inTex).rgb;
 
 // Color look up
  float4 result;
  result.rgba =  tex3Dproj(USTexture, inTex).rgba;
             
 ..... ...... // calculate the lighting.

  oColor = result * light;

}

If I switch the order of normal and texture calculation in fragment program, i.e.

oid FragmentProgram(in float4 inTex : TEXCOORD0, out float4 oColor : COLOR0,
                                            uniform sampler3D Texture,
                                  uniform sampler3D normals) {

 // Color look up
  float4 result;
  result.rgba =  tex3Dproj(USTexture, inTex).rgba;
             
  //get normal
  float3 normal;
  normal.rgb = tex3Dproj(normals, inTex).rgb;
 
 ..... ...... // calculate th light.

  oColor = result * light;

}

The final volume image color changed quite a lot.   It turns to be an error.    Does anyone have the slightest clue about what could be the reason for such behavior?       Can Jogl correctly handle 3D texture sampler?   Or this due to my card issue? Or my OpenGL code doesn't setup 3D texture appropriately?

Thanks.   
Offline Ken Russell

JGO Kernel
*****

Posts: 3446
Medals: 3


Java games rock!


« Reply #1 on: 2007-02-08 11:05:07 »

Do you have a complete test case available?

You may get better answers by posting on NVidia's developer forums since this is a Cg-specific question.
Offline magiccat

JGO n00b
*

Posts: 21



« Reply #2 on: 2007-02-08 11:53:17 »

Ken,

I do have the whole application.  However, I can't give it to public.

I suspect the gl.glActiveTexture() primitive.   In general, do you think my Jogl part setup is correct? 
Pages: [1]
  Print  
 
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.074 seconds with 20 queries.