[Solved] PointStarField and Viewport


31-03-2009 07:29:20

Hello again,
I have a problem with point star field when there are 2 viewports attached to the main camera. When there is only one viewport (the main RenderWindow) attached to the camera, everything is okay. But when I add another viewport to the same camera, the stars are getting much bigger than usual :? . I have tried using setAutoAttachViewportsToComponents to false, but the problem still exists. Thanks for any help :) !


31-03-2009 12:15:04

Are you sure notifyCameraChanged gets called for each viewport? It has to be called per viewport; not actually per camera.

setAutoAttachViewportsToComponents has no effect on stars.


31-03-2009 13:53:50

Hmm... You're right, I didn't call notifyCameraChanged per viewport, but per camera :oops:. But how can I do that? The parameter of notifyCameraChanged is Camera, but I have 2 viewports for 1 camera, how can I update per viewport? Thanks cdleonard & the amazing caelum!


01-04-2009 08:05:17

Updating Caelum is complicated; read this for more info.

PointStarfield uses camera->getViewport to resize stars for one particular viewport; somehow you need to make sure the camera properly references the "right" viewport before updating that viewport. The safest way to get it to work is to drop auto-updating render targets (RenderTarget::setAutoUpdated(false)) and just call Viewport::update by hand; probably something like this:


There are various ways that CaelumSystem tries to avoid stuff like that through listeners; but basically the same calls have to happen. I've never tested CaelumSystem with multiple viewports on the same camera; magical listeners probably won't work. But explicit _notifyViewport calls should make it reliably work.


02-04-2009 07:13:19

Your suggestion works well.
Thanks cdleonard!