www.jpct.net

jPCT - a 3d engine for Java => Support => Topic started by: hytparadisee on June 11, 2007, 08:22:34 am

Title: How to "Render to texture"
Post by: hytparadisee 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?
Title: Re: How to "Render to texture"
Post by: halcor 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.
Title: Re: How to "Render to texture"
Post by: hytparadisee 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.
Title: Re: How to "Render to texture"
Post by: EgonOlsen 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.
Title: Re: How to "Render to texture"
Post by: EgonOlsen on June 11, 2007, 01:27:31 pm
BTW: Render to texture is done via setting a texture as render target in the FrameBuffer.
Title: Re: How to "Render to texture"
Post by: hytparadisee on June 11, 2007, 01:40:55 pm
in other words, FrameBuffer.setRenderTarget() before calling FrameBuffer.update()?
Title: Re: How to "Render to texture"
Post by: EgonOlsen 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.
Title: Re: How to "Render to texture"
Post by: hytparadisee 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
Title: Re: How to "Render to texture"
Post by: EgonOlsen 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.
Title: Re: How to "Render to texture"
Post by: hytparadisee 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?
Title: Re: How to "Render to texture"
Post by: EgonOlsen 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.
Title: Re: How to "Render to texture"
Post by: hytparadisee 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