java - OpenGL Drawing to multiple textures -
i'm trying draw scene's data multiple textures. textures hold diffuse, normal, , position in color form. when scene rendered 1 of textures drawn to. gl_fragdata[0] ends in texture attachment gl_color_attachment2. if switch gl_fragdata[0] diffuse, normal. or position gl_color_attachment2 texture has data correct know data correct in shader first 2 textures end blank.
int fbo = glgenframebuffer(); glbindframebuffer(gl_framebuffer, fbo); addtextureattachment(gl_color_attachment0); addtextureattachment(gl_color_attachment1); addtextureattachment(gl_color_attachment2); material.unbindalltextures(); public void addtextureattachment(int attachment) { int id = glgentextures(); glbindtexture(gl_texture_2d, id); glteximage2d(gl_texture_2d, 0, gl_rgba, width, height, 0, gl_rgba, gl_unsigned_byte, (bytebuffer)null); gltexparameteri(gl_texture_2d, gl_texture_mag_filter, gl_linear); gltexparameteri(gl_texture_2d, gl_texture_min_filter, gl_linear); glframebuffertexture2d(gl_framebuffer, attachment, gl_texture_2d, id, 0); textures.add(new texture(id, width, height)); }
i call before rendering
public void bindasrendertarget() { glbindtexture(gl_texture_2d, 0); glbindframebuffer(gl_framebuffer, fbo); glviewport(0, 0, width, height); gldrawbuffers(gl_color_attachment0); gldrawbuffers(gl_color_attachment1); gldrawbuffers(gl_color_attachment2); }
i have solved issue. when calling gldrawbuffers 3 times needed call different gldrawbuffers takes in bytebuffer containing int gl_color_attachment 0, 1, , 2 this:
bytebuffer buffer = bufferutils.createbytebuffer(3 * 4); buffer.putint(gl_color_attachment0); buffer.putint(gl_color_attachment1); buffer.putint(gl_color_attachment2); buffer.flip(); gldrawbuffers(3, buffer);
Comments
Post a Comment