This post was updated on .
Hi!
I'm trying to create a shadow mapping effect in JOGL and GLSL. I'm having problems storing the z-buffer into the shadow map texture. I didn't find a lot of tutorials for this and I can't make it work :( My shadow texture is always a solid white color :( Here's how I initialize the texture: gl.glGenTextures(1, tmp, 0); shadowMapTexture = tmp[0]; gl.glBindTexture(GL2.GL_TEXTURE_2D, shadowMapTexture); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MIN_FILTER, GL2.GL_NEAREST); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_MAG_FILTER, GL2.GL_NEAREST); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_S, GL2.GL_CLAMP_TO_EDGE); gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_TEXTURE_WRAP_T, GL2.GL_CLAMP_TO_EDGE); gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_DEPTH_COMPONENT, shadowMapSize, shadowMapSize, 0, GL2.GL_DEPTH_COMPONENT, GL2.GL_UNSIGNED_BYTE, null); gl.glGenFramebuffers(1, frmBuff, 0); frameBufferId = frmBuff[0]; gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferId); gl.glDrawBuffer(GL2.GL_NONE); gl.glReadBuffer(GL2.GL_NONE); gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT, GL2.GL_TEXTURE_2D, shadowMapTexture, 0); if (gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER) != GL2.GL_FRAMEBUFFER_COMPLETE) { System.err.println("Can not use FBO!"); } gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0); Here's how I draw to the texture in the display method: if (usingShadowMapping) { SGL.setExternalShading(gl, false); gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBufferId); State.setLightTransformation(glu, 0); gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT); gl.glClearColor(0.f, 0.f, 0.f, 1.f); gl.glColorMask(false, false, false, false); gl.glCullFace(GL2.GL_FRONT); gl.glShadeModel(GL2.GL_FLAT); displayObjects(gl); gl.glLoadIdentity(); SGL.setTextureMatrix(gl, 0); gl.glActiveTexture(GL2.GL_TEXTURE2); gl.glBindTexture(GL2.GL_TEXTURE_2D, shadowMapTexture); SGL.sglBindShadowTexture(gl, 0, shadowMapTexture); // restore states gl.glCullFace(GL2.GL_BACK); gl.glShadeModel(GL2.GL_SMOOTH); gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, 0); gl.glColorMask(true, true, true, true); SGL.setExternalShading(gl, true); } Can somebody please help me? thanks! |
Free forum by Nabble | Edit this page |