我一直在試圖實施陰影貼圖很長一段時間,我正在使用蘭斯威廉斯的技術(渲染場景兩次,一次在光線空間和一次在視圖空間中)。但是,當我撥打glCheckFramebufferStatus
在GL_FRAMEBUFFER
,我得到GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
,後我已經撥打了glFramebufferTexture2D
就可以了。我很困惑,因爲當沒有紋理或渲染緩衝區附加到幀緩衝區時拋出錯誤,但我認爲做了附加了紋理。獲取具有深度紋理的GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
下面是運行在init
我的代碼:
gl.glEnable(GL2.GL_TEXTURE_2D);
// generate stuff
IntBuffer ib = IntBuffer.allocate(1);
gl.glGenFramebuffers(1, ib);
frameBuffer = ib.get(0);
gl.glBindFramebuffer(GL2.GL_FRAMEBUFFER, frameBuffer);
ib = IntBuffer.allocate(1);
gl.glGenTextures(1, ib);
depthTexture = ib.get(0);
gl.glBindTexture(GL2.GL_TEXTURE, depthTexture);
// prevents 'shadow acne'
gl.glPolygonOffset(2.5f, 0);
// prevents multiple shadows
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);
// prevents (or expects!!!) pixel-y textures
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);
// store one value in all four components of pixel
gl.glTexParameteri(GL2.GL_TEXTURE_2D, GL2.GL_DEPTH_TEXTURE_MODE, GL2.GL_INTENSITY);
gl.glFramebufferTexture2D(GL2.GL_FRAMEBUFFER, GL2.GL_DEPTH_ATTACHMENT, GL2.GL_TEXTURE_2D, depthTexture, 0);
gl.glTexImage2D(GL2.GL_TEXTURE_2D, 0, GL2.GL_DEPTH_COMPONENT16, 1024, 1024, 0, GL2.GL_DEPTH_COMPONENT, GL2.GL_FLOAT, null);
gl.glDrawBuffer(GL2.GL_NONE);
gl.glReadBuffer(GL2.GL_NONE);
int FBOStatus = gl.glCheckFramebufferStatus(GL2.GL_FRAMEBUFFER);
// FBOStatus == GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT
編輯:我在一個幾乎空的項目遇到這種方法太(引發錯誤)
'(GL2.GL_TEXTURE_2D,GL2.GL_DEPTH_TEXTURE_MODE,GL2.GL_INTENSITY)'是什麼意思?你如何使用'INTENSITY'作爲模式? –
它應該將輸出矢量的所有四個分量設置爲一個值。 – clabe45