PDA

View Full Version : Rendering to frame buffer



jas511
04-25-2011, 10:15 PM
Hi,

I'm trying to render to a frame buffer, and the shapes I'm drawing are circles that have a gradient fill from black to white (center to outer ring). I am using the following code to draw to the buffer. I then read the pixels from the buffer, and while my image shows the circles in the correct location, they are all completely transparent. The code is as follows:



int[] fb_a = new int[1];
IntBuffer fb = IntBuffer.wrap(fb_a);
gl.glGenFramebuffersEXT(1, fb);
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, fb_a[0]);
ifbo = fb_a[0];

int[] rbo_a = new int[1];
IntBuffer rbo = IntBuffer.wrap(rbo_a);
gl.glGenRenderbuffersEXT(1, rbo);
gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, rbo_a[0]);

gl.glRenderbufferStorageEXT(GL.GL_RENDERBUFFER_EXT , GL.GL_RGBA, width, height);
gl.glFramebufferRenderbufferEXT(GL.GL_FRAMEBUFFER_ EXT, GL.GL_COLOR_ATTACHMENT0_EXT, GL.GL_RENDERBUFFER_EXT, rbo_a[0]);

int status = gl.glCheckFramebufferStatusEXT(GL.GL_FRAMEBUFFER_E XT);
if (status != GL.GL_FRAMEBUFFER_COMPLETE_EXT) {
System.out.println("error creating FBO");
}
gl.glClearColor(1,1,1,1);
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
gl.glViewport(0, 0, width, height);
int slices = 18;
gl.glEnable(GL.GL_BLEND);

// draw circles for each of the points
for each point {
gl.glBegin(GL.GL_TRIANGLE_FAN);
gl.glSetColor4d(0,0,0,1);
gl.glVertex3d(center.x,center.y,center.z);
gl.setColor4d(1,1,1,1);
float incr = (float) (2 * Math.PI / slices);
for (int i = 0; i <= slices; i++) {
float angle = incr * i;
Vec4 pt = computePointLocation(); // this just computes the point
gl.glVertex3d(pt.x, pt.y, pt.z);
}
gl.glEnd();
}
gl.glBindFramebufferEXT(GL.GL_FRAMEBUFFER_EXT, 0);
gl.glBindRenderbufferEXT(GL.GL_RENDERBUFFER_EXT, 0);

file:///home/jstorey/images/img-1303794128081.png
Any help is appreciated here. Thanks.

Jeff

BionicBytes
04-26-2011, 12:11 AM
What happens when you disable glBlend?

jas511
04-26-2011, 08:03 AM
Edit: I forgot to disable a shader I was using. Now the writing of the pixels to that buffer works perfectly, thanks!