Viewport rendering upside-down and backwards

32 views
Skip to first unread message

zzes

unread,
Sep 18, 2011, 11:44:40 PM9/18/11
to Rabbyt
I am trying to use the viewport feature to implement a sort of camera
type thing, (with zooming and panning), but I am getting some very
strange behavior.

left = centerpoint[0]+(size[0]/2)/zoom
right = centerpoint[0]-(size[0]/2)/zoom
top = centerpoint[1]+(size[1]/2)/zoom
bottom = centerpoint[1]-(size[1]/2)/zoom

rabbyt.set_viewport((left, top, right, bottom))

Where (zoom) is the zoom multiplier, centerpoint is the XY of the
middle of the pygame display and size is the size in pixels of the
window, I get my sprites rendered very nicely, but upside-down and
backwards. Zooming works just as expected, and at all zoom levels the
drawn image fills the screen.

If I flip the corner coords:
rabbyt.set_viewport((right, bottom, left, top))

The sprites render rightways-up, but for some reason the image doesn't
scale anymore. (Giving me black bars all around my image)

Is there any way to re-enable automatic stretching to fit the screen?
Or am I doing it all wrong?

Matthew Marshall

unread,
Oct 2, 2011, 2:05:12 PM10/2/11
to rab...@googlegroups.com
Notice that set_viewport takes a second argument, 'projection'. You
probably want the first argument to always be the size of your window,
then change the second argument to be the region of your world that
you want to draw on the screen.

MWM

> --
> You received this message because you are subscribed to the Google Groups "Rabbyt" group.
> To post to this group, send email to rab...@googlegroups.com.
> To unsubscribe from this group, send email to rabbyt+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/rabbyt?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages