Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 3 of 3

Thread: Rendering to frame buffer

  1. #1
    Intern Newbie
    Join Date
    Apr 2011
    Posts
    42

    Rendering to frame buffer

    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:

    Code :
    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_EXT);
    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);
    [img]file:///home/jstorey/images/img-1303794128081.png[/img]
    Any help is appreciated here. Thanks.

    Jeff


  2. #2
    Senior Member OpenGL Pro BionicBytes's Avatar
    Join Date
    Mar 2009
    Location
    UK, London
    Posts
    1,171

    Re: Rendering to frame buffer

    What happens when you disable glBlend?

  3. #3
    Intern Newbie
    Join Date
    Apr 2011
    Posts
    42

    Re: Rendering to frame buffer

    Edit: I forgot to disable a shader I was using. Now the writing of the pixels to that buffer works perfectly, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •