glOrtho setup for rendering "impostors" into a texture.

Actually, using the phrase "imposter" here is perhaps a bit too fancy.

I'm prototyping having my trees render 3 views to a texture map ( +X, +Y, -Z ) for use in distant rendering. I'd render those distant trees by rendering the three planes, with the appropriate texture coordinates. (For reference, my engine creates a small number of unique tree "prototypes" and then positions thousands of lightweight clones of them on the stage so as to not use up way to much memory -- which is to say that if I have 4 prototypes, I'll only need to render four impostors. )

Anyway, this morning I wrote some test code just to see if I could render a single view of the tree into a square texture. After all, baby steps first. My approach goes like this:

1) get the combined AABB of the tree's solid geometry and its foliage ( the foliage is a separate object, with its own bounds ).

2) Create and bind an FBO.

3) Set up a viewport corresponding to the FBO's texture size ( obviously, when I render more views I'll partition ).

4) Set up an ortho projection to encompass the tree's bounding box

5) Set up the modelview to look at the tree

6) Render

Seems straightforward enough. When I run it via OpenGL Profiler and take a look at the rendered texture, I *do* see the tree and it's leaves. The thing is, I'm only seeing the top of the tree, and the near and far planes are screwy, in that I'm getting obvious clipping.

Here's my code:

Code:

void Tree::generateImposter( void )
{
_renderingImposter = true;

/*
For the purposes of development, at first, we'll just set
up an ortho projection and an FBO to render into, looking
down the +Y axis. The ortho projection will correspond
to the dimension of the tree's AABB and the viewport will
correspond to the texture size.
*/

For a little side-note, I use a z-as-up camera. It's just the way I prefer things. I think my problems might lie in confusion between my tree's AABB ( where x/y is the horizontal plane and z is up ) and the glOrtho command.

Does anybody have any suggestions?

Finally screenshots for clarity. Here's the actual tree:

And here's the "imposter", or rather just its head in gl profiler:

( yeah, the rendering's ugly. I'll probably have to futz around to make certain the blending on the foliage looks right in render-to-texture, but right now I'm more concerned with getting the whole tree in there )

For what it's worth, I solved the projection issue. It makes sense in retrospect, but the fact that I use z-up is only relevant in the modelview matrix, not the projection matrix when I set up the ortho projection.

Rendering against a black background should do the trick. Just to be sure that you are doing that, try setting the blend function in OpenGL Profiler to GL_ONE, GL_ZERO. That will make the texture show up with the background color - if it is white, then that's what's causing your halos.

That makes sense. I just did it, and I'm getting what "appears" to be a white background. I use scare quotes because the big white block seems to have the classic aqua pinstripes in it, which I find somewhat disturbing.

That looks perfectly as if you clear the impostor to glClear(0,0,0,0), and there is no blending when you draw the texture. Since the texture is all transparent, you see through your view onto the window's background, which are the pinstripes.

TomorrowPlusX Wrote:Huh. So what do you do when you want to clear alpha to zero?

If you don't have a transparent window context thing set up, why would you want to do that? If the of clear is to draw over with a large rectangle effectively, except in hardware with some other kind of complications, why would you draw an invisible clear on top? Isn't that completely pointless?

socksy Wrote:If you don't have a transparent window context thing set up, why would you want to do that? If the of clear is to draw over with a large rectangle effectively, except in hardware with some other kind of complications, why would you draw an invisible clear on top? Isn't that completely pointless?

Because I'm rendering to texture, and I want the parts of the texture not rendered to to be fully transparent.

ThemsAllTook Wrote:False information. Clearing to transparent black is the typical thing to do, and it certainly works with alpha set to 0.

Well, that's reassuring (thanks!), but I still have the problem to fix...

Skortche! I think you're right. I was contemplating this while looking at what the render looks like when drawn on-screen See the screenshot:

I came to the same conclusion, that alpha's being saturated, e.g., wherever a fragment makes it to the render buffer, alpha's being saturated to one.

I'd *never* even heard of this glBlendFuncSeparate... I was going to ask if there was something that did what it sounds like that does. I'm going to read the manpages. Thank you so much!

@arrekusu -- can GL Profiler allow me to see the renderbuffer contents when I'm doing RTT? I thought it only allowed me to see the contents of the display context.

EDIT: To use glBlendFuncSeparate, with some googling it looks like I only have to enable GL_BLEND ( but the only place I saw that was on a german Wikki, and I don't speak German... ) so is that correct? Or so I have to enable a different token?