Results 1 to 6 of 6

Thread: Render in a texture

  1. #1
    Guest

    Render in a texture

    how can i set gl to render inside a texture object so i can texturize new objects with the previous scene?

    thanks

  2. #2
    Member Contributor
    Join Date
    Aug 2001
    Posts
    62

    Re: Render in a texture

    i have no idea but you might try rendering to a bitmap and then reapplying it to the object but this would most likely be dog slow...

  3. #3
    Junior Member Newbie
    Join Date
    Sep 2001
    Location
    Golden, Colorado, USA
    Posts
    2

    Re: Render in a texture

    I did something similar once and what I did was create a blank texture, set the viewport to the size of the texture, render the scene for the texture, use glCopyTexImage2D() to copy the scene to the texture. Then clear the buffers and render the scene using your normal settings and your new texture.

    I don't think this is the best way, but it works although I remember it being somewhat slow.
    You can do that?

  4. #4
    Senior Member Regular Contributor
    Join Date
    Feb 2001
    Location
    Australia
    Posts
    431

    Re: Render in a texture

    glReadPixels the current scene, then use that for the texture in the next scene. That way you aren't rendering the scene twice like the other two suggestions.

    Hope that helps.

  5. #5
    Senior Member Frequent Contributor
    Join Date
    Apr 2000
    Location
    Adelaide, South Australia, Australia
    Posts
    763

    Re: Render in a texture

    Howdy,

    I agree with ffish's assertion that glReadPixels will not require the scene to be re-rendered. However:

    1 glReadPixels() will soak the bus between the video card and memory
    2 the frame buffer pixels might need to be converted between formats and thus require additional overhead
    3 the screen needs to be resampled, anyway
    4 the new texture data will need to be copied back

    You can't avoid (1). If you're reading from the screen, then the pixels will need to be stored in memory. You can avoid (2) by packing the data in the same format that they're stored in the frame buffer, but this might make resampling the image more problematic depending on what you're doing with it. (3) will need to be done in most cases; screens are not necessarily powers of two in dimension, after all, and finally, (4) needs to be done so the texture can be used.

    Re-rendering the screen has the properties:

    1 there is no bus traffic between the card and memory
    2 less data is transferred between screen and texture memory
    3 the data doesn't need to be resample, because its implicilty done when the screen is rerendered
    4 the pixels are unlikely to require conversion from frame pixels to textels format


    As noted, the single disadvantage of the latter approach is that the scene needs to be rerendered. this might not be much of a problem because you can keep track of the sceen state from the first traversal. ie. you have a scene graph and traverse it once to collect rendered scene info, and you can save the graph traversal for the second time you need to draw the screen. (you thus don't have the FULL overhead of rednering a scene, since you don't need to perform frustum culling / state sorting / etc again, and its to a smaller viewport, anyway)

    glRead approach is more efficient if the overhead of reading and converting pixels is less than the cost of redrawing a smaller copy of the scene. i'd put my money on the second case, tho'; a lot of engines use multiple passes, and this is no different.

    my 2c worth,

    cheers,
    John

  6. #6
    Guest

    Re: Render in a texture

    ok guys, i'll try the two methods and will stay with the fastest.

    thank you all very much
    marcio

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