const char *readPBuffer_text =
"!!ARBfp1.0
"
"TEMP pt, dproduct;
"
"TEX pt, fragment.texcoord[0], texture[0], RECT;
"
"DP4 dproduct, color.primary, pt;
"
"ADD result.depth, dproduct, color.secondary ;
"
"END
";
…
glColor4f(rf,gf,bf,af);//rf,gf,bf,af are float variants value in [0…1]
glSecondaryColor3f(sf,sf,sf);//sf is a float variant value in [0…1]
glDrawPixels(0,0,WIDTH,HEIGHT,GL_DEPTH_COMPONENT,GL_FLOAT,pData);//the values in pData are 1;
glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, readPBuffer);
glEnable(GL_FRAGMENT_PROGRAM_ARB);
glEnable(GL_STENCIL_TEST);
glStencilFunc(GL_ALWAYS,0,0);//Stencil test always passes
glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);//when stencil test fall, keep;
//when stencil test pass, depth test fail, keep;
//when all pass, increase;
glEnable(GL_DEPTH_TEST);
glDepthFunc(GL_LESS);
glBindTexture(GL_TEXTURE_RECTANGLE_NV, _tID);
glEnable(GL_TEXTURE_RECTANGLE_NV);
// draw quad with texture coordinates in the [0…texturewidth, 0…textureheight] range
glBegin(GL_QUADS);
glTexCoord2f(0, 0); glVertex2f(-1,-1);
glTexCoord2f(WIDTH, 0); glVertex2f( 1,-1);
glTexCoord2f(WIDTH, HEIGHT); glVertex2f( 1, 1);
glTexCoord2f(0, HEIGHT); glVertex2f(-1, 1);
glEnd();
I write this fragment program, to dot poduct every texel in texture with the primary color, then add the secondary color, and copy the result into the depth buffer. But I alway got 1 in depth buffer, Is there any problem of my code?
another question is if the depth test is pass, the value in depth buffer will be replaced?