Reputation: 4718
i am rendering a 3d surface in opengl by drawing a bunch of triangles. some of my primitives are see through. i don't simply mean that there is a blending of the color behind them, i mean that i can see completely through them. i have no idea why i am able to see through these primitives and would not like that to be the case (unless i specify alpha blending which i have not).
unfortunately i cannot link any code (there are ~1800 lines right now and i don't know where the error would be!), but any help would be great.
i hope i have given enough information, if not, please feel free to ask for me to clarify!
EDIT: more info ...
i call plotPrim(ix,iy,iz) which uses cube marching to plot a triangle (or a few) through the current cube of a rectangular grid.
myInit() is ...
void myInit()
{
// initialize vectors
update_vectors();
// set initial color to white
glClearColor(0.0, 0.0, 0.0, 0.0);
glEnable(GL_BLEND | GL_DEPTH_TEST);
}
plotMesh() is where i do my work of going through each cube and plotting the primitives
void plotMesh() //
{
if(plot_prop)
{
// do some stuff
}
else
{
glBegin(GL_TRIANGLES);
for(int ix = 0; ix < snx-1; ix++)
{
//x = surf_x[ix];
for(int iy = 0; iy < sny-1; iy++)
{
//y = surf_y[iy];
for(int iz = 0; iz < snz-1; iz++)
{
//z = surf_z[iz];
// front face
a = sv(ix+0, iy+0, iz+0);
b = sv(ix+0, iy+1, iz+0);
g = sv(ix+0, iy+0, iz+1);
d = sv(ix+0, iy+1, iz+1);
// back face
al = sv(ix+1, iy+0, iz+0);
be = sv(ix+1, iy+1, iz+0);
ga = sv(ix+1, iy+0, iz+1);
de = sv(ix+1, iy+1, iz+1);
// test to see if a primitive needs to be plotted
plotPrim(ix, iy, iz);
}
}
}
glEnd();
}
}
one example of a primitive being plotted in plotPrim() is ....
if(val>a && val<g && val<b && val<al || val<a && val>g && val>b && val>al) // "a" corner
{
tx = (val-a)/(al-a);
ty = (val-a)/(b-a);
tz = (val-a)/(g-a);
x1 = surf_x[ix] + tx*surf.dx;
y1 = surf_y[iy];
z1 = surf_z[iz];
x2 = surf_x[ix];
y2 = surf_y[iy] + ty*surf.dy;
z2 = surf_z[iz];
x3 = surf_x[ix];
y3 = surf_y[iy];
z3 = surf_z[iz] + tz*surf.dz;
getColor( (1.0-tx)*sv(ix,iy,iz) + tx*sv(ix+1,iy,iz) );
glVertex3f(x1,y1,z1);
getColor( (1.0-ty)*sv(ix,iy,iz) + ty*sv(ix,iy+1,iz) );
glVertex3f(x2,y2,z2);
getColor( (1.0-tz)*sv(ix,iy,iz) + tz*sv(ix,iy,iz+1) );
glVertex3f(x3,y3,z3);
}
Upvotes: 2
Views: 296
Reputation: 30460
glEnable(GL_BLEND | GL_DEPTH_TEST);
is wrong as glEnable
only takes a single capability to enable, not a bitmask. You might have more errors, but you want to change the above to:
glEnable(GL_BLEND);
glEnable(GL_DEPTH_TEST);
Upvotes: 5