Author Topic: How to "Render to texture"  (Read 4873 times)

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
How to "Render to texture"
« on: June 11, 2007, 08:22:34 am »
By looking at the "window_blinds" video i think that is something i need to use in the near future. Any hint on how is it done? And is it possible that image created on the fly (e.g. ImageIcon painted by Graphics) can be used as textures to be drown in this manner, and in GLCanvas mode?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline halcor

  • byte
  • *
  • Posts: 28
    • View Profile
Re: How to "Render to texture"
« Reply #1 on: June 11, 2007, 12:42:35 pm »
Quote
And is it possible that image created on the fly (e.g. ImageIcon painted by Graphics) can be used as textures to be drown in this manner, and in GLCanvas mode?
Sure, construct an Image, add it to the texture manager (or modify existing texture), apply the texture to an object and here you go.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: How to "Render to texture"
« Reply #2 on: June 11, 2007, 01:03:48 pm »
Thanks, i tried it and get it solved.

New question: what's the best way to update the image rendered to the texture on the fly? Is TextureManager.replaceTexture() alone enough? If that's the case, does it matter to produce so many Texture objects just because we need to update it every frame? I am inexperienced in all kinds of realtime app so i am sort of newbie about whether creating a new object per frame kills the app.
« Last Edit: June 11, 2007, 01:06:15 pm by hytparadisee »
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to "Render to texture"
« Reply #3 on: June 11, 2007, 01:21:08 pm »
Uploading a new texture every frame is cheap in software mode but expensive in hardware mode. It's a bit cheaper to use an ITextureEffect to update a texture's content, but it's still expensive in hardware mode.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to "Render to texture"
« Reply #4 on: June 11, 2007, 01:27:31 pm »
BTW: Render to texture is done via setting a texture as render target in the FrameBuffer.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: How to "Render to texture"
« Reply #5 on: June 11, 2007, 01:40:55 pm »
in other words, FrameBuffer.setRenderTarget() before calling FrameBuffer.update()?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to "Render to texture"
« Reply #6 on: June 11, 2007, 01:43:29 pm »
No, before the whole render section, i.e. it has to include the clear() and everything. Set it first, do the usual stuff as you would do it when rendering directly to screen, remove it and render the scene one again, but now with the correct camera view.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: How to "Render to texture"
« Reply #7 on: June 11, 2007, 02:00:59 pm »
Now see whether my understanding is correct.

1. Create the object as usual.
2. Apply the initial texture as usual.
3. Before that series of rendering commands, do FrameBuffer.setRenderTarget()
4. Now update the texture (drawing, painting etc)
5. Render
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to "Render to texture"
« Reply #8 on: June 11, 2007, 02:07:10 pm »
No, render to texture and updating the texture from the "outside" via your application are totally different things. If all you want to do is to refill the texture with your generated content, then you don't have to care about render to texture.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: How to "Render to texture"
« Reply #9 on: June 11, 2007, 02:12:03 pm »
Sorry today something wrong with my head. ;D Ya how come I mixed them up, render to texture basically means capturing whatever it is in the buffer to an external texture right?
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11748
    • View Profile
    • http://www.jpct.net
Re: How to "Render to texture"
« Reply #10 on: June 11, 2007, 02:13:24 pm »
Rendering to texture means to render the current scene into a texture instead of the framebuffer. Like the video shows it on the TV screen.

Offline hytparadisee

  • int
  • **
  • Posts: 86
    • View Profile
    • http://peterhi.com
Re: How to "Render to texture"
« Reply #11 on: June 11, 2007, 02:19:27 pm »
Quote
Rendering to texture means to render the current scene into a texture instead of the framebuffer.

:) No wonder you said:

Quote
do the usual stuff as you would do it when rendering directly to screen, remove it and render the scene one again, but now with the correct camera view
Today I finally found a problem to my soluuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuution