Dorbie. Help? (3D Texture mapping) almost working

Dorbie… I think its almost working but there seems to be something I’m not understanding about the rotating…
I’m rotating the texture (about the origin) and then switching back to model view and passing planes through the texture…
It I rotate model view everything looks normal but I don’t get back faces of objects… However if I rotate the texture then I can’t even begin to describe the results… they are truely warped…

I’m at my wits end with this dorbie… I’ve been through the thread you have suggested… and this is still not doing what I expect…

When this works I’ll add the clipping code…

Keep in mind dorbie that my texture is not a cube in dimensions… in fact its like 512x512x32. So it seems a bit stretched when viewed… because the code looks to me like it assumes that the texture was cubed. (In your example)

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

    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
    glGenTextures(1, &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);


void display(void)
    static float planeS[] = {1.0f, 0.0f, 0.0f, 1.0f};
    static float planeT[] = {0.0f, 1.0f, 0.0f, 1.0f};
    static float planeR[] = {0.0f, 0.0f, 1.0f, 1.0f};
    int slice;
    float z;
    static float r=0.0;
    glTranslatef(-0.5f, -0.5f, -0.5f);
    glRotatef(r, 1.0f, 1.0f, 1.0f);



    glTexGenfv(GL_S, GL_EYE_PLANE, planeS);
    glTexGenfv(GL_T, GL_EYE_PLANE, planeT);
    glTexGenfv(GL_R, GL_EYE_PLANE, planeR);
    for (slice=0; slice < iDepth; ++slice)
        z = ((1.0/((float) (iDepth-1))) * (float) slice) - 0.5f;

        glVertex3f(-0.5f, -0.5f, z);
        glVertex3f(+0.5f, -0.5f, z);
        glVertex3f(+0.5f, +0.5f, z);
        glVertex3f(-0.5f, +0.5f, z);


    r = r + 0.5;

void reshape(int w, int h)
    glViewport(0, 0, (GLsizei) w, (GLsizei) h);

    gluPerspective(60.0, (GLfloat) w / (GLfloat) h, 1.0, 30.0);


    glTranslatef(0.0, 0.0, -2.5);

Hmm… your texgen in eye_linear means your plane equations and the subsequent coordinate generation is relative to the eye and additionally rotations are around the eye’s position (the origin in eye space).

The translation will move it by half a volume.

You have a couple of options, try the following:

Clamp the texture and have an an alpha = 0 border, or just zero color since you’re using a max bland equation. Eliminate all rotations and then move the volume to the desired location. This will involve some translations, this should force you to position the volume in front of the viewer with the correct texgen. You should then be able to rotate around any point but remember that this will require a translation back to the origin (the eye for texgen eye). To rotate about a point translate -point, rotate then translate +point. The -.5 -.5 -.5 is to move the center of the cube to the origin you should leave that in addition to everything else. Your viewing translation is -2.5 in z that means you have to translate your texgen out with that also, and undo that translation then redo it for the rotation, however just slipping the rotation in there before you translate the cube out on the texture stack but after the -.5 translate will also do the trick.

The (IMHO simpler) alternative is to specify the texgen in object space but before you specify the plane equations load the translation and rotation for the volume onto the modelview matrix (it’s already there it’s the -2.5 z for the viewing translate). This will transform the plane equations to the appropriate space and fix your problem. You may find this approach easier. This would be better with cleaner code that doesn’t jumble the various calls & state settings so much, but only to aid your understanding. In object space the rotation orogin will be around the local origin and the -0.5 texture matrix translate recenters the cube locally, so a simple rotate after this will suffice.

You need to start working on your understanding of what these matrices do in this rendering algorithm w.r.t. object, world and eye space and when & where these spaces exist, I think that’s what’s missing here. You’ll have trouble getting the clip planes to transform correctly(via modelview translations) if you don’t grok this stuff.

Ok thanks dorbie… Its going to take me a while to absorbIe all that… I think I understand code better than english these days…

However dorbie… I started all of this off from the red book example. In the red book texture3d example there were no texGen calls, and I like that because if you will remember i need to deform my texture and I had control over how the texture was mapped to my polygons. I gave up on this for two reasons… 1) I couldn’t get the back faces of the polygons to render 2) because you pointed me to the other code…

If I continue with the automatic texture co-ordinate generation code I’m going to be ______ because then I can’t deform my texture.

Remember here I am using glBlend with the GL_MAX equation.
To do a maxium intensity projection and I suspect that I’m not getting the back face of my polygon because of the drawing order.

One more thing I don’t understand is that if my polygon is outside the bounding box of the texture I just want it to be transparent… I think I messed that up by using GL_CLAMP but I can’t figure out what else I could use…

Sorry to take up so much of this groups time…