Results 1 to 3 of 3

Thread: iOS Rendering a object to a texture

  1. #1
    Newbie Newbie
    Join Date
    Jul 2016
    Posts
    2

    iOS Rendering a object to a texture

    I'm currently using OpenGL ES 2.0 and trying to draw a triangle into a texture and then paste that texture onto the face of another triangle. I was wondering what the steps might be to do this? The process I have right now is to configure shaders and setup my main framebuffer/renderbuffer, then setup my texture, and then try to draw that all together at the end. I cleared my texture-framebuffer to a green color and tried to draw on it, but at the final result I only have a green surface to my object and not a green surface plus another smaller triangle in the face of the larger triangle that I'm applying the texture to. Any possible leads?

  2. #2
    Senior Member Regular Contributor
    Join Date
    May 2016
    Posts
    477
    Quote Originally Posted by poppinmc View Post
    I'm currently using OpenGL ES 2.0 and trying to draw a triangle into a texture and then paste that texture onto the face of another triangle. I was wondering what the steps might be to do this?
    i think you cant simply use the texture framebuffer to read from and at the same time write into
    i would use 2 framebuffers, both with 1 texture
    first render anything into framebuffer 1
    then bind framebuffer 2, bind the texture from framebuffer 1 so that you can sample from it in you fragment shader
    then render your triangle into framebuffer 2
    finally, bind framebuffer 0 (default framebuffer) and copy the content from your 2nd framebuffer into the default framebuffer

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);// specify the framebuffer to draw into
    glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer2);// specify the framebuffer to read from
    glReadBuffer(GL_COLOR_ATTACHMENT0);// specify the color buffer to read from
    glBlitFramebuffer(...);// copy framebuffer content

  3. #3
    Newbie Newbie
    Join Date
    Jul 2016
    Posts
    2
    Quote Originally Posted by john_connor View Post
    i think you cant simply use the texture framebuffer to read from and at the same time write into
    i would use 2 framebuffers, both with 1 texture
    first render anything into framebuffer 1
    then bind framebuffer 2, bind the texture from framebuffer 1 so that you can sample from it in you fragment shader
    then render your triangle into framebuffer 2
    finally, bind framebuffer 0 (default framebuffer) and copy the content from your 2nd framebuffer into the default framebuffer

    glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);// specify the framebuffer to draw into
    glBindFramebuffer(GL_READ_FRAMEBUFFER, framebuffer2);// specify the framebuffer to read from
    glReadBuffer(GL_COLOR_ATTACHMENT0);// specify the color buffer to read from
    glBlitFramebuffer(...);// copy framebuffer content
    Hmm sorry I think I might've misworded my approach. So currently I'm using two different framebuffers, one for rendering to a texture, and one for rendering to a renderbuffer (which I'll refer to from here on as texture-framebuffer and render-framebuffer respectively). So what I'm trying to do is draw a triangle into the texture-framebuffer, and also draw a another different triangle into the render-framebuffer. I want to use the texture as an application onto the render-framebuffer, but I haven't been able to get anything to appear on that framebuffer except for a green color which I used to clear the texture-framebuffer with. Also in OpenGL ES 2.0, I don't have access to glBlitFramebuffer(), so I'm not really sure what other approaches there might be to do this. Ultimately I'm trying to divide the rendering process so that I can draw my object of interest into the texture-framebuffer on a thread, and then render that texture onto some surface in another thread to make drawing a less hefty process (as a personal project).

Similar Threads

  1. Object not rendering after rotation
    By Crosswar in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-24-2015, 08:32 AM
  2. How to specify the size of an object [VBO] [Rendering]
    By garrygl in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 03-21-2014, 05:39 AM
  3. no rendering of object on screen????
    By abhi1988 in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 07-01-2011, 11:56 PM
  4. Framebuffer object not rendering?
    By Adrian Hooper in forum OpenGL: Advanced Coding
    Replies: 1
    Last Post: 03-25-2009, 09:20 AM
  5. Rendering an object in more than one place
    By King Fuzzy in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 08-25-2001, 10:47 AM

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