PDA

View Full Version : Transparency doesn't work? - Depth test disabled & blend enabled.



joehot200
02-15-2014, 11:11 AM
Hi, I disabled the depth test and enabled the blending like said in other threads, however the map is not transparent.
Here is my current code,


glBegin(GL_TRIANGLE_STRIP);
boolean water = false;
for (int x = 0; x < data[z].length; x++) {
// Take a vertex from the current strip
if (((blue[z][x] / 255) < 0.4)){
glColor3f((red[z][x] / 255) / 2
+ (float) (Math.random() / 10), (green[z][x] / 255)
/ 2 + (float) (Math.random() / 10),
(blue[z][x] / 255) / 2
+ (float) (Math.random() / 10));
glVertex3f(x, data[z][x], z);
glVertex3f(x, data[z + 1][x], z + 1);
}else {
glEnable(GL_DEPTH_TEST);
glEnable (GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glAlphaFunc(GL_ALWAYS, 1);
water = true;
//glEnd();
//glBegin(GL_TRIANGLE_STRIP);
/*glColor4d((red[z][x] / 255) / 2
+ (float) (Math.random() / 20), (green[z][x] / 255)
/ 2 + (float) (Math.random() / 20),
(blue[z][x] / 255) / 2
+ (float) (Math.random() / 20), 0.5f);*/

glColor4f(1.0f,1.0f,1.0f,0.5f);
glVertex3f(x, data[z][x], z);
glVertex3f(x, data[z + 1][x], z + 1);
}


If it makes any difference, it is rendered using a Display List.

mhagain
02-15-2014, 03:14 PM
You're calling glEnable (and making other calls) between a glBegin/glEnd pair, and that's illegal. See http://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml


GL_INVALID_OPERATION is generated if a command other than glVertex, glColor, glSecondaryColor, glIndex, glNormal, glFogCoord, glTexCoord, glMultiTexCoord, glVertexAttrib, glEvalCoord, glEvalPoint, glArrayElement, glMaterial, glEdgeFlag, glCallList, or glCallLists is executed between the execution of glBegin and the corresponding execution glEnd.