Results 1 to 2 of 2

Thread: FBO Render to texture

  1. #1
    Junior Member Newbie
    Join Date
    Jan 2012
    Posts
    1

    FBO Render to texture

    Hi,

    I have some problems with the render to texture. But first, let me explain a bit the context.

    In my project, I have an input image which is a CIImage (Core Image = Apple) that I want to modify in OpenCL.
    However, it seems that it is not possible to convert directly a CIImage into a OpenCL image2d.
    The only way to do it (as far as i know) is the following:

    CIImage -> OpenGL texture attached to a FBO -> OpenCL image2d

    I think I understand now the concept of FBO, but I'm clearly not an expert in OpenGL.
    In this context, OpenGL is just a gateway between Core Image and OpenCL...
    I paste some code bellow.

    Code :
    // Create the FBO object
    glGenFramebuffersEXT(1, &FBOid);
     
    // Create the texture
    glGenTextures(1, &FBOTextureId);
     
    // Bind to FBO
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, FBOid);
     
    // Initialize FBO Texture
    glBindTexture(  GL_TEXTURE_RECTANGLE_ARB, FBOTextureId);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S,     GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T,     GL_CLAMP_TO_EDGE);
    glTexImage2D(   GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, width, height, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, NULL);
     
    // Attach texture to the FBO
    glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_RECTANGLE_ARB, FBOTextureId, 0);	
     
    // Make sure the FBO was created succesfully.
    if (GL_FRAMEBUFFER_COMPLETE_EXT != glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT))
    {
        printf("ERROR\n");
    }
     
    // Unbind FBO 
    glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

    Then I render my CIImage in the FBO which should fill the OpenGL texture.
    When I render the FBO, I see my image correctly.
    But when I read my OpenGL texture in OpenCL, the values are random.

    One may say that I haven't transferred correctly the OpenGL texture to the OpenCL image2d.
    But if I specify a buffer containing the image pixels in glTexImage2D (last parameter), then everything works perfectly.
    So how can the rendering be good and the texture empty?
    My guess: I read the texture before it has actually been filled.

    How to be sure that my texture has been filled at some point?

    Thank you for your help,

    Vincent

  2. #2
    Senior Member Regular Contributor
    Join Date
    Jun 2009
    Location
    FL , USA
    Posts
    192

    Re: FBO Render to texture

    One may say that I haven't transferred correctly the OpenGL texture to the OpenCL image2d.
    But if I specify a buffer containing the image pixels in glTexImage2D (last parameter), then everything works perfectly.
    So how can the rendering be good and the texture empty?
    My guess: I read the texture before it has actually been filled.
    The last parameter in glTexImage2D() when set yo null just allocates the memory. After this it is your responsibility to load the texture.

    If your texture is going to be read only, I would prefer passing data to the function and then attach to FBO.

    If you want to later upload a texture use sub texture command version of glTexImage2D.

Similar Threads

  1. FBO render as Texture : Color does not render correctly
    By imported_unknown123 in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 03-20-2018, 11:46 PM
  2. Replies: 2
    Last Post: 03-04-2018, 12:26 PM
  3. Replies: 0
    Last Post: 12-02-2015, 09:03 AM
  4. Replies: 3
    Last Post: 04-01-2015, 02:05 AM
  5. Replies: 0
    Last Post: 03-20-2014, 10:59 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean