Off screen rendering

39 views
Skip to first unread message

Pete

unread,
Nov 4, 2009, 7:20:37 AM11/4/09
to G3D Users
I was hoping someone could give me some pointers, as I'm not really
sure how best to go about this.

Background:
I have a "massive" landscape with a large amount of detail sat on top
of it. In order to render at realistic framerates the quality of the
render detail is being dropped off against distance.
The landscape is broken up into squares.
In order to produce a "quick draw" version of a square I want to do a
Non-perspective top down view of the full detailed square, and then
use that image as a texture to paste onto the basic landscape mesh.
So, I'm wanting to render a separate view of this landscape sqaure,
without perspective and produce an image i can then use for texturing,
and do it all off screen.

So the question is how do i (or what's the best way to) create and
render to a bitmap that isn't the screen/backbuffer that is normally
used. I'm guessing i need somehow to use setFramebuffer on the render
device, but i can't quite get my head around it (if that is even the
method i should be using).

Any thoughts, ideas or suggestions would be welcome.

Pete

andyc

unread,
Nov 4, 2009, 9:20:20 AM11/4/09
to G3D Users


On Nov 4, 12:20 pm, Pete <p...@theridouts.co.uk> wrote:
> ...
> So the question is how do i (or what's the best way to) create and
> render to a bitmap that isn't the screen/backbuffer that is normally
> used. I'm guessing i need somehow to use setFramebuffer on the render
> device, but i can't quite get my head around it (if that is even the
> method i should be using).
>
> Any thoughts, ideas or suggestions would be welcome.

Hi, if you are using the GApp framework you are actually rendering to
an off-screen bufffer already. See the docs for Film for a hint of how
you could do it (not using Film) in your own code. Stuff like this:
<pre>
film = Film::create();
fb = Framebuffer::create("Offscreen");
colorBuffer = Texture::createEmpty("Color", renderDevice->width(),
renderDevice->height(), ImageFormat::RGB16F(), Texture::DIM_2D_NPOT,
Texture::Settings::video());
fb->set(Framebuffer::COLOR_ATTACHMENT0, colorBuffer);
fb->set(Framebuffer::DEPTH_ATTACHMENT,
Texture::createEmpty("Depth", renderDevice->width(),
renderDevice->height(), ImageFormat::DEPTH24(), Texture::DIM_2D_NPOT,
Texture::Settings::video()));
</pre>

and then per frame,
<pre>
rd->pushState(fb);
...Rendering code here...
rd->popState();
film->exposeAndRender(rd, colorBuffer);
</pre>

G3D makes it really easy.

Best,
Andrew

>
> Pete

Pete

unread,
Nov 4, 2009, 10:16:39 AM11/4/09
to G3D Users
I've also now found the FrameBuffer details in the documentation
having read this, which gives another good example. I think i was
looking in the wrong place for the answer. Many thanks for your help.

Pete

corey taylor

unread,
Nov 4, 2009, 11:18:22 PM11/4/09
to g3d-...@googlegroups.com
If you have any issues using Framebuffer, please post.
 
corey

Pete

unread,
Nov 5, 2009, 6:00:27 AM11/5/09
to G3D Users
It was surprisingly easy to implement, thanks again for all the help.
The only thing that had me stuck for a bit was removing the
perspective, as I couldn't get gCamera to do that, so I just ended up
setting the ProjectionMatrix and CameraToWorldMatrix manually and it
all just fell into place.

Pete

Morgan McGuire

unread,
Nov 5, 2009, 10:53:33 AM11/5/09
to g3d-...@googlegroups.com
You might want to switch to 2D rendering mode using push2D() as well--that's how I do deferred shading.

-m

Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan

Pete

unread,
Nov 5, 2009, 12:42:40 PM11/5/09
to G3D Users
I need more than 2d rendering though (unless i misunderstand with
push2D does). The Landscape square being rendered onto the texture
will also contain 3d objects on its surface that will also be rendered
onto the texture, so I still need a depth buffer, culling
etc..etc..etc..
the idea being that just the landscape heightmap and this newly
created texture will give an approximation of the fully detailed
version.

or.. am I misunderstanding what push2D does.. It isn't obvious from
the documentation, so I'm just guessing based on a quick glance at the
code.

Pete



On Nov 5, 3:53 pm, Morgan McGuire <morga...@gmail.com> wrote:
> You might want to switch to 2D rendering mode using push2D() as well--that's
> how I do deferred shading.
>
> -m
>
> Prof. Morgan McGuire
> Computer Science Department
> Williams Collegehttp://cs.williams.edu/~morgan

Morgan McGuire

unread,
Nov 5, 2009, 12:44:59 PM11/5/09
to g3d-...@googlegroups.com
push2D switches to an orthogonal camera that is 1:1 with pixels, disables depth testing.


-m

Prof. Morgan McGuire
Computer Science Department
Williams College
http://cs.williams.edu/~morgan


Reply all
Reply to author
Forward
0 new messages