I would like to use an osgViewer::Viewer which should render to a constant
aspect ratio and fill the rest of any rendering window with black in any case;
also on resizing.
For that matter, I have implemented an updateViewport() method that resizes my
Viewport centered in the correct aspect ratio and according to my current window
size. This works in general, but two questions remain:
- I have called this method both as an event handler on window resize events,
and as a ResizeCallback in my GraphicsContext. Where is the correct place to put
this? If I replace the ResizeCallback of the Context, do I have to take care of
more things than just setting the viewport correctly?
- On resize in either case, ghost images of the rendering to the former window
size remain. What do I have to do to flush anything that happened before, and
just render black in the surrounding area of my viewport? Also interesting: if I
render to texture in my application, and use the frame buffer as target, those
areas that are not overwritten by the actual rendering viewport still show the
texture that is rendered to in RTT. In all cases, what I want is just plain
black. ;)
Thanks a lot,
Alex.
_______________________________________________
osg-users mailing list
osg-...@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
On Fri, Oct 17, 2008 at 9:29 AM, Alexander Löffler <alexlo...@gmx.net> wrote:
> For that matter, I have implemented an updateViewport() method that resizes my
> Viewport centered in the correct aspect ratio and according to my current window
> size. This works in general, but two questions remain:
>
> - I have called this method both as an event handler on window resize events,
> and as a ResizeCallback in my GraphicsContext. Where is the correct place to put
> this? If I replace the ResizeCallback of the Context, do I have to take care of
> more things than just setting the viewport correctly?
Have a browse through the GraphicsContext::resizedImplementation(..)
method in src/osg/GraphicsContext.cpp as it's this implementation that
you are overriding. See what it does w.r.t viewpors and aspect
ratios. You may be able to ignore all of it, but it's better to
ignore all of it in knowledge of what you are leaving out than miss
something.
> - On resize in either case, ghost images of the rendering to the former window
> size remain. What do I have to do to flush anything that happened before, and
> just render black in the surrounding area of my viewport? Also interesting: if I
> render to texture in my application, and use the frame buffer as target, those
> areas that are not overwritten by the actual rendering viewport still show the
> texture that is rendered to in RTT. In all cases, what I want is just plain
> black. ;)
The GraphicsContext has a clear colour colour and clear mask methods
that you can use to clear the graphics context on each new frame. By
default the GraphicsContext has a clear mask of 0 so does nothing, as
the Camera's normally cover the whole screen, but in your case you'll
need the GraphicsContext clear. The methods are:
/** Sets the clear color. */
inline void setClearColor(const Vec4& color) { _clearColor = color; }
/** Returns the clear color. */
inline const Vec4& getClearColor() const { return _clearColor; }
/** Set the clear mask used in glClear(..).
* Defaults to GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT. */
inline void setClearMask(GLbitfield mask) { _clearMask = mask; }
/** Get the clear mask.*/
inline GLbitfield getClearMask() const { return _clearMask; }
I vaguely recall that I might have tested this in the osgcamera
example, so have a look at this.
Robert.
The call to setClearMask() was the crucial point, as I assumed the
GL_COLOR_BUFFER_BIT to be set by default. Which the Doxygen comment for
the method, as pasted above, suggests for me too. After setting this,
everything cleared as expected.
Thanks a lot, Robert!
Alex.
Good to hear things are now working. I've checked the doxygen comment
and it looks like a case of the copy and paste anti-pattern striking
again. I've rewritten the doxygen comment to be better reflect the
default and the methods usage.
Robert.