PDA

View Full Version : Back face of texture not showing?



KraftDinner
10-04-2004, 08:01 AM
I've defined two polygons, one for the front face and one for the back face (textured).. However only the front face of the polygon seems to be drawn.. ie if I rotate around I loose the back face.
I am doing blending and wonder if the drawing order is what the problem might be or is it the way I've defined the texture mapping?


glEnable(GL_BLEND);
glBlendEquation(GL_MAX);
for (slice=0; slice < iDepth; ++slice)
{
z = (1.0/((float) (iDepth-1))) * (float) slice;

glBegin(GL_QUADS);

// front face.
glTexCoord3f(0.0, 0.0, z); glVertex3f(-1.0, -1.0, z-half);
glTexCoord3f(1.0, 0.0, z); glVertex3f(-1.0, 1.0, z-half);
glTexCoord3f(1.0, 1.0, z); glVertex3f( 1.0, 1.0, z-half);
glTexCoord3f(0.0, 1.0, z); glVertex3f( 1.0, -1.0, z-half);

// back face.
glTexCoord3f(0.0, 0.0, z); glVertex3f(-1.0, -1.0, z-half);
glTexCoord3f(0.0, 1.0, z); glVertex3f(-1.0, 1.0, z-half);
glTexCoord3f(1.0, 1.0, z); glVertex3f( 1.0, 1.0, z-half);
glTexCoord3f(1.0, 0.0, z); glVertex3f( 1.0, -1.0, z-half);

glEnd();
}:confused:

dorbie
10-04-2004, 08:29 AM
You must sort your slices, however you should not be rotating the slizes, look at the example in the other thread I keep pointing you to.

In that example the slices don't rotate but the texture volume does. Your slices should be fixed in eye space and the texgen rotates the texture volume through the slices.

KraftDinner
10-04-2004, 09:00 AM
I have been reading and trying to piece together code from the example you gave me dorbie.. however as I've mentioned I do not have the ability to use that code in its present form due to its use of EXT.. (Which I have not yet figured out how to load on my MAC G5 yet). However when I do try that code I just get a white screen... (I have removed the EXT stuff in the hopes it will just 'work')


void init(void)
{
glClearColor (0.0, 0.0, 0.0, 0.0);
glShadeModel(GL_FLAT);
glEnable(GL_DEPTH_TEST);

ThreeDTexture * text = readRawSlice("morerawct/ct.raw", iWidth, iHeight, iDepth);

glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

glGenTextures(1, &amp;texName);
glBindTexture(GL_TEXTURE_3D, texName);

glTexImage3D(GL_TEXTURE_3D, 0, GL_INTENSITY16, iWidth, iHeight, iDepth, 0, GL_LUMINANCE, GL_UNSIGNED_SHORT, (GLvoid *) text->image);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);

glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);

glEnable(GL_TEXTURE_GEN_S);
glEnable(GL_TEXTURE_GEN_T);
glEnable(GL_TEXTURE_GEN_R);

glEnable(GL_TEXTURE_3D);
}

void display(void)
{
static float r=0.0;
bool clipping = true;

static double eqnxy1[] = { 0.0, 0.0, 1.0, 0};
static double eqnxy2[] = { 0.0, 0.0, -1.0, 1};
static double eqnxz1[] = { 0.0, 1.0, 0.0, 0};
static double eqnxz2[] = { 0.0, -1.0, 0.0, 1};
static double eqnzy1[] = { 1.0, 0.0, 0.0, 0};
static double eqnzy2[] = {-1.0, 0.0, 0.0, 1};

static float planeS[] = {1,0,0,1};
static float planeT[] = {0,1,0,1};
static float planeR[] = {0,0,1,1};

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

//Rotations
glTranslatef(.5, .5, .5);
glRotatef(r, 1,0,0);
glRotatef(r, 0,1,0);
glTranslatef(-.5, -.5, -.5);

//Store the MODELVIEW matrix into memory
static float modelMatrix[16];
glGetFloatv(GL_MODELVIEW_MATRIX, modelMatrix);

glMatrixMode(GL_TEXTURE);
glLoadMatrixf(modelMatrix);

glTranslatef(-1.0f, -1.0f, -1.0f);

//Set clipping planes
glClipPlane(GL_CLIP_PLANE0, &amp;eqnxy1[0]);
glClipPlane(GL_CLIP_PLANE1, &amp;eqnxy2[0]);
glClipPlane(GL_CLIP_PLANE2, &amp;eqnxz1[0]);
glClipPlane(GL_CLIP_PLANE3, &amp;eqnxz2[0]);
glClipPlane(GL_CLIP_PLANE4, &amp;eqnzy1[0]);
glClipPlane(GL_CLIP_PLANE5, &amp;eqnzy2[0]);

//Enable to the clipping planes
if (clipping)
{
glEnable(GL_CLIP_PLANE0);
glEnable(GL_CLIP_PLANE1);
glEnable(GL_CLIP_PLANE2);
glEnable(GL_CLIP_PLANE3);
glEnable(GL_CLIP_PLANE4);
glEnable(GL_CLIP_PLANE5);
}

glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);
glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR);

glMatrixMode(GL_MODELVIEW);

glPushMatrix();
glLoadIdentity();

//Generate the texture coordinates
glTexGenfv(GL_S, GL_EYE_PLANE, planeS);
glTexGenfv(GL_T, GL_EYE_PLANE, planeT);
glTexGenfv(GL_R, GL_EYE_PLANE, planeR);

//Start drawing the QUADs
glBegin(GL_QUADS);

for (float a = -2.0; a < 2.0; a += 1.0/(iDepth-1))
{
glVertex3f(-2, -2, a);
glVertex3f(-2, 2, a);
glVertex3f( 2, 2, a);
glVertex3f( 2, -2, a);
}

glEnd();

glPopMatrix();

r = r + 0.5f;

}

void reshape(int w, int h)
{
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 30.0);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0, 0.0, -2.5);
}

int main(int argc, char** argv)
{
glutInit(&amp;argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
glutInitWindowSize(250, 250);
glutInitWindowPosition(100, 100);
glutCreateWindow(argv[0]);
init();
glutReshapeFunc(reshape);
glutDisplayFunc(display);
//glutIdleFunc(idle);
//glutKeyboardFunc (keyboard);
glutMainLoop();
return 0;
}

dorbie
10-04-2004, 12:05 PM
It's OK to delete the EXT from the texture_3D token, if this didn't work you would never have been able to compile. It SHOULD just work.

Extensions get promoted to be part of subsequent core specs and EXTs can disappear.

I don't see how your quads can be rotating since you load identity before you draw them, and you draw a single set of them back to front as far as a I can tell.

There's some cut & paste in your code that suggests you're not clear exactly what's happening w.r.t. various transformation matrices but you'll get the hang of that.

One thing to try is get rid of all clipping etc and just get the texgen & blend working then add texture matrix then add clipping.

I don't see what's up based on what you've posted unless it's simple zbuffer alpha issues which has been discussed on the boards here many times.

KraftDinner
10-05-2004, 07:42 AM
I'm not sure I know what is you are reffering to for the cut and paste errors... I simply cut and pasted the code from the thread as you suggested.. Other than splitting it into init and display, no modifications were made to the transform matricies. Perhaps it in the last for loop where the quads are being defined?

KraftDinner
10-06-2004, 06:55 AM
:confused: