Here's what I do:
# Set default projection to use upper left as origin
pyglet.gl.glMatrixMode(pyglet.gl.GL_PROJECTION)
pyglet.gl.glLoadIdentity()
pyglet.gl.glOrtho(0.0, 1024.0, 768.0, 0.0, -1.0, 1.0)
pyglet.gl.glMatrixMode(pyglet.gl.GL_MODELVIEW)
pyglet.gl.glLoadIdentity()
This makes 0,0 the upper left corner of the screen and 1024, 768 the
bottom right corner. But if you're thinking that this is what you
want, you should consider what will happen! If you use any function
that is not expecting this, it will draw upside down. For example,
try drawing some text using:
label = pyglet.text.Label('Hello, world',
font_name='Times New Roman',
font_size=36,
x=window.width//2, y=window.height//2,
anchor_x='center', anchor_y='center')
label.draw()
It will come out beautifully rendered in the right location, but
reflected upside down.
--
Nathan Whitehead
I think the pyglet way of doing it is more intuitive. The other way
makes little sense. And this is coming from a pygame user of at least
4 years, who hasn't begun to use pyglet yet. It's just more intuitive
that way for me.
Whenever I animate a ball being shot or something, it feels unnatural
to have the image offset from the top, rather than from the direction
of gravity like I would expect it to be.
Imagine that the ground is the x-axis, and you're throwing a ball.
Would you choose an arbitrary line above you (say 15 feet) and state
that the ball is 5 feet from that line after .5 seconds, or would you
say the ball is 10 feet off the ground after .5 seconds? It just
makes more sense to me that way.
Do you have a reason that you prefer it the other way? Convention is
not the mother of invention, remember. Python ignored the
pretty-common convention of denoting blocks with either braces or a
start / end statement, and just used indentation solely. I personally
believe this to be one of the greatest features. It's a minor issue,
but it makes the code more readable (enforces decent code structure)
and gets rid of all those nasty braces that you just feel are a waste
of lines and are a trouble to keep up with. And this sort of
epitomizes Python tradition - do things the way that make the most
sense, not the way people have been doing them before.
At least that's my two cents. But pennies are pretty worthless (worth
even less now that the DOW is below 9k and our economy is tankin', but
that's neither here nor there.) so do with it what you will.
I agree that origin in the lower left is more intuitive. That's how
you learn it in math class! When you start doing any equations things
are much simpler if you don't have to convert from what you learned in
trig class to funky reversed y-axis coordinates.
But I also appreciate the origin in the upper left. That has been a
2D game programming standard a long time, as well as a standard for
bitmap images. When I use the Gimp to get rectangle coordinates from
an image, that's how it gives me coordinates.
--
Nathan Whitehead
Why? That's the way you do it.
> There's no simple cure? That's slightly mind-boggling. Every tool has
> its quirks, but I've not seen before the kind of balls it takes to
> blandly ignore a near-universal standard like this.
>
Pyglet didn't invent OpenGL. It's just provides an easy path to use
it directly if you need to.
> I suppose I can carry on what I'm doing, which is flipping every
> sprite's y co-ordinate before drawing it and putting it back after,
> but that's like a joke.
>
Abstract away the code Nathan gave you in a function called
flip_screen(). Or just use the more natural coordinate system
provided. Your explanation above ("they're drawn automatically by
the 'black box'") doesn't make any sense. I use batches as well, and
they don't pose any technical obstacle with regard to window origin.
Many other developers (obviously) have used sprites and batches
without a need to flip the screen. Maybe you could elaborate more on
the technical nature of your problem?
Drew
And let's not forget mathematics. In my high school math classes most
(all?) plots using the rectangular coordinate system were drawn with
positive Y pointing up.
The origin in the top left is a holdout from the days when display
controllers were wired to print text from top to bottom.
MWM
Wow. This is SO not the case in here.
> When you point out this out its users, they act shocked that anyone
> wold want it any other way: it's the rest of the world that's wrong!
Most people in this list that responded to this thread seem to find
the Y axis up convention more intuitive...
> On one hand you have all word processors, all spreadsheets, all paint
> programs, all map-making tools, all game-making libraries.
>
> On the other hand, you have... Pyglet.
And OpenGL and DirectX and High School Math...
> I am not reprogramming my brain to just to use this thing.
You sound like it's a humongous effort to switch the way you work
about coordinates in 2D. For me it's simply a matter of knowing wich
convention each library uses and stick to it. I know some people
understand some things faster and better than others, but I just can't
believe it's that hard to think with the Y axis up once you know it's
up. I hope you never get introduced to 3D programming and have to deal
with right-hand vs. left-hand conventions that are far more confusing
than that...
--
Kao Cardoso Félix
Página pessoal: http://www.inf.ufrgs.br/~kcfelix
Blog: http://kaofelix.blogspot.com
So do something creative instead of bitching and whining when we don't
give you a direct solution.
For example, store your values in a class, and use a property to
automatically convert your y value from a top-measured to a
bottom-measured value whenever you retrieve it. Or use a conversion
function for the coordinate as noted by dordna.
This isn't rocket science, seriously.
> I am not reprogramming my brain to just to use this thing.
So reprogram the computer to work how you expect it to. Core tenet of
Computer Science, friend.