Clipping based on depth texture -- Urgent
This is the piece of code I am using. In display I think it should do the clipping. But it is not working.
// DOING VOLUME RENDERING
void genr()
{
for (int i = 0; i <144; i++)
{
glBegin(GL_POLYGON);
glTexCoord3f(0.0, 0.0, 0.0076 * i);
glVertex3f(-0.5,-0.5,-0.5 + 0.0076 * i);
glTexCoord3f(0.0, 1.0, 0.0076 * i);
glVertex3f(-0.5,0.5,-0.5 + 0.0076 * i);
glTexCoord3f(1.0, 1.0, 0.0076 * i);
glVertex3f(0.5, 0.5,-0.5 + 0.0076 * i);
glTexCoord3f(1.0, 0.0, 0.0076 * i);
glVertex3f(0.5,-0.5,-0.5 + 0.0076 * i);
glEnd();
}
}
//CREATING A CLIPPING OBJECT
void drawscene()
{
// Draw the top and bottom faces
glBegin(GL_QUADS);
glColor3f(0.5f,0.0f,0.0f); // Red
glVertex3f(-0.5f, 0.5f, 0.25f);
glVertex3f( 0.5f, 0.5f, 0.25f);
glVertex3f( 0.5f, 0.5f,-0.25f);
glVertex3f(-0.5f, 0.5f,-0.25f);
glColor3f(0.0f,0.0f,0.5f); // Blue
glVertex3f(-0.5f,-0.5f, 0.25f);
glVertex3f(-0.5f,-0.5f,-0.25f);
glVertex3f( 0.5f,-0.5f,-0.25f);
glVertex3f( 0.5f,-0.5f, 0.25f);
glEnd();
// Draw the side faces
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.5f,0.5f,0.5f); // White
glVertex3f(-0.5f, 0.5f, 0.25f);
glVertex3f(-0.5f,-0.5f, 0.25f);
glVertex3f( 0.5f, 0.5f, 0.25f);
glColor3f(0.0f,0.5f,0.0f); // Green
glVertex3f( 0.5f,-0.5f, 0.25f);
glColor3f(0.5f,0.5f,0.0f); // Yellow
glVertex3f( 0.5f, 0.5f,-0.25f);
glColor3f(0.0f,0.5f,0.5f); // Aqua?
glVertex3f( 0.5f,-0.5f,-0.25f);
glColor3f(0.6f,0.6f,0.6f); // Gray
glVertex3f(-0.5f, 0.5f,-0.25f);
glColor3f(0.1f,0.1f,0.1f); // Dark Gray
glVertex3f(-0.5f,-0.5f,-0.25f);
glColor3f(0.0f,0.0f,0.5f); // Blue
glVertex3f(-0.5f, 0.5f, 0.25f);
glColor3f(0.5f,0.0f,0.5f); // Red
glVertex3f(-0.5f,-0.5f, 0.25f);
glEnd();
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.5f,0.5f,0.5f); // White
glVertex3f(-0.5f, 0.5f, 0.25f);
glVertex3f(-0.5f,-0.5f, 0.25f);
glVertex3f( 0.5f, 0.5f, 0.25f);
glColor3f(0.0f,0.5f,0.0f); // Green
glVertex3f( 0.5f,-0.5f, 0.25f);
glColor3f(0.5f,0.5f,0.0f); // Yellow
glVertex3f( 0.5f, 0.5f,-0.25f);
glColor3f(0.0f,0.5f,0.5f); // Aqua?
glVertex3f( 0.5f,-0.5f,-0.25f);
glColor3f(0.6f,0.6f,0.6f); // Gray
glVertex3f(-0.5f, 0.5f,-0.25f);
glColor3f(0.1f,0.1f,0.1f); // Dark Gray
glVertex3f(-0.5f,-0.5f,-0.25f);
glColor3f(0.0f,0.0f,0.5f); // Blue
glVertex3f(-0.5f, 0.5f, 0.25f);
glColor3f(0.5f,0.0f,0.5f); // Red
glVertex3f(-0.5f,-0.5f, 0.25f);
glEnd();
}
// CALLING GENR() FUNCTION
void draw()
{
int i, j, k = 0;
if ( wi == 1 && hi == 1)
k = 0; // dataset varies from 0 to 3
for(i = 0; i <hi ; i++)
{
for(j = 0; j <wi; j++)
{
glViewport (j * g_w/wi, i * g_h/hi, g_w/wi, g_h/hi);
glBindTexture(GL_TEXTURE_3D, texName[k++]);
//glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
//glEnable (GL_BLEND);
genr();
//glDisable(GL_BLEND);
// glPushMatrix();
// glutWireCube(1.1);
// glPopMatrix();
}
}
}
void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity ();
glRotatef(angle,1.0,1.0,1.0);
glTranslatef (0.0, 0.0, -2.0);
glMultMatrixf (state->rot_matrix);
// CULL FRONT FACE AND DRAW A DEPTH TEXTURE AND THEN DO DEPTH TEST WITH GREATER
// if (counter == 0)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_FRONT);
glColorMask(0, 0, 0, 0);
drawscene();
glColorMask(1, 1, 1, 1);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glClear (GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture[0]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 512, 512,0);
glBindTexture(GL_TEXTURE_2D,0);
glDisable(GL_TEXTURE_2D);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDepthMask(GL_TRUE);
glEnable(GL_CULL_FACE);
glEnable(GL_DEPTH_TEST);
glCullFace(GL_BACK);
glColorMask(0, 0, 0, 0);
drawscene();
glColorMask(1, 1, 1, 1);
glDisable(GL_DEPTH_TEST);
glDisable(GL_CULL_FACE);
glClear (GL_COLOR_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture[1]);
glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 512, 512,0);
glBindTexture(GL_TEXTURE_2D,1);
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_FALSE);
}
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDepthMask(GL_TRUE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture[0]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.5,-1.5,0.25);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.5,1.5,0.25);
glTexCoord2f(1.0, 1.0);
glVertex3f(1.5, 1.5,0.25);
glTexCoord2f(1.0, 0.0);
glVertex3f(1.5,-1.5,0.25);
glEnd();
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_FALSE);
glDepthFunc(GL_GREATER);
glEnable(GL_TEXTURE_3D);
draw();
glDisable(GL_TEXTURE_3D);
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D,0);
// CULL BACK FACE AND DRAW A DEPTH TEXTURE AND THEN DO DEPTH TEST WITH LESS
//glMultMatrixf (state->rot_matrix);
glClear (GL_DEPTH_BUFFER_BIT);
glDisable(GL_TEXTURE_GEN_S);
glDisable(GL_TEXTURE_GEN_T);
glDepthMask(GL_TRUE);
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D, shadowMapTexture[1]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0);
glVertex3f(-1.5,-1.5,-0.25);
glTexCoord2f(0.0, 1.0);
glVertex3f(-1.5,1.5,-0.25);
glTexCoord2f(1.0, 1.0);
glVertex3f(1.5, 1.5,-0.25);
glTexCoord2f(1.0, 0.0);
glVertex3f(1.5,-1.5,-0.25);
glEnd();
glDisable(GL_TEXTURE_2D);
glDepthMask(GL_FALSE);
glDepthFunc(GL_LESS);
glEnable(GL_TEXTURE_3D);
draw();
glDisable(GL_TEXTURE_3D);
glDisable(GL_DEPTH_TEST);
glBindTexture(GL_TEXTURE_2D,1);
// glDeleteTextures(2, shadowMapTexture);
// glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
// drawscene();
/* glEnable(GL_TEXTURE_3D);
draw();
glDisable(GL_TEXTURE_3D);
*/
counter++;
glutSwapBuffers();
glutPostRedisplay();
}
Can you please clarify your question?
I'm not sure what you mean by clipping.
Cliping the polygons with planes?
Or cliping the view with stencil buffer (define witch pixels are enable or not to be drawn)
I'm not sure what you mean by clipping.
Cliping the polygons with planes?
Or cliping the view with stencil buffer (define witch pixels are enable or not to be drawn)
Hi,
I am trying to do clipping using depth buffer. I have a 3D texture of a volume (being mapped using genr() function) which need to be clipped. I have a clipping object which ideally can be of any shape and is drawn using drawscene().
In the first pass I want to CULL the front faces of the clipping object and draw the 3D texture with depth text enabled and depthfunc(greater). This will draw the volume behind the cliiping object.
In the second pass I want to CULL the back faces of the clipping object and draw the 3D texture with depth text enabled and depthfunc(less). This will draw the volume in front of the cliiping object.
But I am having implementation issues with it. The display() func should be supposedly doing the first pass and the second pass.
Thank you
GK
I am trying to do clipping using depth buffer. I have a 3D texture of a volume (being mapped using genr() function) which need to be clipped. I have a clipping object which ideally can be of any shape and is drawn using drawscene().
In the first pass I want to CULL the front faces of the clipping object and draw the 3D texture with depth text enabled and depthfunc(greater). This will draw the volume behind the cliiping object.
In the second pass I want to CULL the back faces of the clipping object and draw the 3D texture with depth text enabled and depthfunc(less). This will draw the volume in front of the cliiping object.
But I am having implementation issues with it. The display() func should be supposedly doing the first pass and the second pass.
Thank you
GK
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement