Hello,

By calling glOrtho(0, 600, 0, 500, -1, 1), you're saying that the
window's coordinates are not in pixels, but they run from (0, 0) in
the lower-left corner to (600, 500) in the upper left. If the window
is not 6:5, a square in these coordinates won't be a square on screen.

There are two possibilities here: either you wanted to say glOrtho(0,
w, 0, h, -1, 1) ­­-- note the lowercase -- and use pixel coordinates;
or you want to use the coordinates you have, in which case you'll need
to temporarily undo the scaling before drawing each label.


On Wed, Jul 4, 2012 at 3:54 PM, Andreas <[email protected]> wrote:
> Hi,
>
> I'm trying to figure out how I can keep the aspect ratio of my rendered
> objects constant, without distorting labels / text in my scene. In my
> 'on_resize()' function I call 'label.begin_update()' and
> 'label.end_update()', assuming that these calls will prevent the label from
> getting scaled. However this does not work - I'm probably doing something
> wrong here.
> Does anybody have a suggestion on how to preserve the text / label? I'm
> using pyglet 1.1.4.
>
> thanks!
> andreas
>
>
> import pyglet
> from pyglet.gl import *
>
> class myWindow(pyglet.window.Window):
>
> def __init__(self, *args, **kwargs):
> pyglet.window.Window.__init__(self, *args, **kwargs)
>
>
> def setup(self):
>
> self.labels = []
> self.labels.append(pyglet.text.Label(
>   """dummy text""",
>   font_size=12,
>   x=130, y=130, anchor_x = 'left', anchor_y = 'center'))
>
> glClearColor(0, 0, 0, 1.0)
> glPointSize(5)
>
>
> def draw_square(self):
>   glLineWidth(1)
>   glBegin(GL_LINE_LOOP)
>   glVertex2f(100, 100)
>   glVertex2f(400, 100)
>   glVertex2f(400, 400)
>   glVertex2f(100, 400)
>   glEnd()
>
>
> def on_draw(self):
>
> glEnable(GL_NORMALIZE)
> glPushMatrix()
> glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
>
> # draw the square and the text label
> self.draw_square()
> for label in self.labels:
> label.draw()
>
> glPopMatrix()
>
>
> def on_resize(self, w, h):
> # set viewport to new view dimensions but don't scale text labels
> for label in self.labels:
> label.begin_update()
>
> glViewport(0, 0, w, h)
>
> glMatrixMode(GL_PROJECTION)
> glLoadIdentity()
> glOrtho(0, W, 0, H, -1.0, 1.0)
> glMatrixMode(GL_MODELVIEW)
>
> for label in self.labels:
> label.end_update()
>
>
> if __name__ == "__main__":
>
> H = 600
> W = 500
>
> my_win = myWindow(width=W, height=H, resizable=True)
> my_win.setup()
>
> pyglet.app.run()
>
> --
> You received this message because you are subscribed to the Google Groups
> "pyglet-users" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/pyglet-users/-/L18wTS8I3lkJ.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/pyglet-users?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to