今天我正在使用FrameBuffers,以及类似的东西。我确实做到了,而且它正在发挥作用。但是一个小问题:GL_COLOR_ATTACHMENT0有效,但GL_DEPTH_ATTACHMENT没有。代码是一样的,我只是改变附件模式。我有深度缓冲区作为渲染缓冲区,如果它不在帧缓冲区中(渲染到没有深度缓冲区的纹理,只是图像)。但是有了Depth att。我禁用它。代码:
public void setAsFramebuffer(int num,int att, boolean b) {
if (frameBuffer == 0) frameBuffer = GL30.glGenFramebuffers();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, frameBuffer);
GL30.glFramebufferTexture2D(GL30.GL_FRAMEBUFFER, att, GL11.GL_TEXTURE_2D, id[num], 0);
if (att == GL30.GL_DEPTH_ATTACHMENT) { //TODO: add pen mode
GL20.glDrawBuffers(GL11.GL_NONE);
} else {
GL20.glDrawBuffers(att);
}
if (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER) != GL30.GL_FRAMEBUFFER_COMPLETE) {
String msg;
boolean crash = true;
switch (GL30.glCheckFramebufferStatus(GL30.GL_FRAMEBUFFER)) {
case GL30.GL_FRAMEBUFFER_UNDEFINED : msg = "The default framebuffer does not exist.";
case GL30.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT : msg = "Some of framebuffers attachment points are framebuffer incomplete.";
case GL30.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT : msg = "Framebuffer dosent have any attached images.";
case GL30.GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER : msg = "Value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for any color attachment point(s) named by GL_DRAW_BUFFERi.";
case GL30.GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER : msg = "Value of GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE is GL_NONE for the color attachment point named by GL_READ_BUFFER";
case GL30.GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE : msg = "GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE";
case GL30.GL_RENDERBUFFER_SAMPLES : msg = "GL_RENDERBUFFER_SAMPLES ";
case GL32.GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS : msg = "GL_FRAMEBUFFER_INCOMPLETE_LAYER_TARGETS";
case GL30.GL_FRAMEBUFFER_UNSUPPORTED : msg = "Framebuffers not supported by Grahpics card."; crash = false;
default: msg = "unknown! Maybe GL error? "; crash = true; CoreEngine.checkForGLErrors();
}
System.out.println("Framebuffer error! Someting is bad happened here...Error: "+msg);
if (crash) System.exit(0);
}
if(b) this.setupDepthRenderBuffer();
GL30.glBindFramebuffer(GL30.GL_FRAMEBUFFER, 0);
}
public void setupDepthRenderBuffer() {
renderBuffer = GL30.glGenRenderbuffers();
GL30.glBindRenderbuffer(GL30.GL_RENDERBUFFER, renderBuffer);
GL30.glRenderbufferStorage(GL30.GL_RENDERBUFFER, GL11.GL_DEPTH_COMPONENT, width[0], height[0]);
GL30.glFramebufferRenderbuffer(GL30.GL_FRAMEBUFFER, GL30.GL_DEPTH_ATTACHMENT, GL30.GL_RENDERBUFFER, renderBuffer);
}
Dept att。还需要颜色。或者我搞砸了什么?
哦,它说的是它未知的错误。我没有在文档中看到任何其他内容,只是错误。
纹理初始化:
public void loadTexture(int glRepeat, int filter, int glTexture2d,
int width, int height, ByteBuffer buffer) {
this.width[0] = width;
this.height[0] = height;
if(buffer == EMPTRY_PICTURE) buffer = Util.createByteBuffer(width*height*4);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, glRepeat);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, glRepeat);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexImage2D(glTexture2d, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
if (filter == GL_NEAREST_MIPMAP_NEAREST ||
filter == GL_NEAREST_MIPMAP_LINEAR ||
filter == GL_LINEAR_MIPMAP_NEAREST ||
filter == GL_LINEAR_MIPMAP_LINEAR)
{
GL30.glGenerateMipmap(GL_TEXTURE_2D);
float ani;
ani = glGetFloat(GL_MAX_TEXTURE_MAX_ANISOTROPY_EXT);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT,Math.min(ani,8f));
}
}