Hrm, there’s something funky going on. Would it be possible to post the relevant sections of your code so we can see what’s going on?
/**
* Draw the actor
*/
public void draw() {
if (alive) {
if (lightingEnabled) {
gl.enable(GL.LIGHTING);
}
// set the texture
if (currentTextureIndex >= 0) {
gl.enable(GL.TEXTURE_2D);
gl.bindTexture(GL.TEXTURE_2D, texPool.getTexBuf(textureIDs[currentTextureIndex]).get(0));
}
// set color
if (alpha >= 0) {
gl.color4ub((byte) red, (byte) green, (byte) blue, (byte) alpha);
} else {
gl.color4ub((byte) 255, (byte) 255, (byte) 255, (byte) 255);
}
// Blending Function For Translucency Based On Source Alpha Value
if (translucent) {
gl.blendFunc(blendSrc, blendTgt);
gl.enable(GL.BLEND);
} else if (masked) {
//System.out.println("masked");
gl.enable(GL.BLEND);
gl.blendFunc(GL.SRC_ALPHA, GL.ONE_MINUS_SRC_ALPHA);
gl.texEnvf(GL.TEXTURE_ENV, GL.TEXTURE_ENV_MODE, GL.MODULATE);
gl.color4ub((byte)255, (byte)255, (byte)255, (byte)255); // You can fade something out in its entirety by altering alpha here too
}
// translate to location
gl.translatef(x, y, z);
// rotate
gl.rotatef(rot, rx, ry, rz);
drawMesh();
// rotate back
gl.rotatef(-rot, rx, ry, rz);
// translate back to origin
gl.translatef(-x, -y, -z);
if (translucent || masked) {
gl.disable(GL.BLEND);
}
if (currentTextureIndex >= 0) {
gl.disable(GL.TEXTURE_2D);
}
if (lightingEnabled){
gl.disable(GL.LIGHTING);
}
}
}
protected void drawMesh() {
// draw the quad
// TO DO: non-square sprites
float ts = this.textureSizeLocked ? scale : 1f;
ts /= textureScale;
gl.begin(GL.QUADS);
gl.normal3f(0,0,1);
gl.texCoord2f(0.0f + this.textureXOffset, 0.0f + this.textureYOffset);
gl.vertex3f(-0.5f * scale, -0.5f * scale, 0f);
gl.texCoord2f(ts + this.textureXOffset, 0.0f + this.textureYOffset);
gl.vertex3f(+0.5f * scale, -0.5f * scale, 0f);
gl.texCoord2f(ts + this.textureXOffset, ts + this.textureYOffset);
gl.vertex3f(+0.5f * scale, +0.5f * scale, 0f);
gl.texCoord2f(0.0f + this.textureXOffset, ts + this.textureYOffset);
gl.vertex3f(-0.5f * scale, +0.5f * scale, 0f);
gl.end();
}
What I did was a gl.disable(GL.DEPTH_TEST) before drawMesh() and gl.enable(GL.DEPTH_TEST) after drawMesh() in case of transparency or masking.
When I did that, everything became transparent even the player.
Greetings,
Erik
[quote]When I disable depth testing for blended objects (as also suggested in the nehe tutorials), the strange thing is that everything becomes transparent. ???
[/quote]
Oh, hang on, that’s wrong isn’t it?
If you’re doing the easy blending hack, you want to render all the opaque objects as normal, then disable depth buffer writing (using gl.depthMask), but leave depth buffer testing on, while rendering all the transparent objects. Give that a try.
Ah, just found what’s wrong.
It was a very stupid mistake (I’m good at that. I managed to overlook that stupid mistake for at least a hundred times).
In the draw ordering code, I didn’t regard masked objects as using blending, so masked object were always drawn before translucent objects. (I do a depth sort on all objects, then 1st draw opaque objects, then blended ones).
But thanks anyway for the explanation about depth testing cfmdobbie, I think I understand now
Greetings,
Erik
Ah, heh, I do that a lot as well. My current problem is an app that works fine with the release library, but OpenGL seems to be throwing an “invalid operation” on a gl.end() call with the debug library… Arrrgh! There’s gotta be something silly I’ve screwed up somewhere, but I can’t for the life of me work out where… Between the gl.begin() and gl.end() I’ve only got gl.vertex3f() and gl.color4fv() calls… >:( >:( >:(
oooops, that sounds like our problem to me.
I bet the CHECK_ERROR macro has sneaked into one of those calls (you can’t check GL errors between begin and end)…
2 mins later: Whoops, you’re dead right, it was buried in some of the glColor calls. Fixed in CVS; expect a new release out maybe… Monday? Elias? Brian?
Cas
Hurrah! Not my problem! ;D
Phew, I’ll stop fiddling with it for tonight then. I’ve got an interview tomorrow but just couldn’t go to bed while this problem persisted… I’ll go now…
[quote] 2 mins later: Whoops, you’re dead right, it was buried in some of the glColor calls. Fixed in CVS; expect a new release out maybe… Monday? Elias? Brian?
[/quote]
That all depends on some of the many recent checkins. However it will be soon. There are some things- feature wise - we need to clarify first though.