Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
Chris Ashurst wrote: I think on all systems (and if you're used to getting mouse x/y coordinates via the SDL side of pygame) the mouse is flipped when you use OpenGL. No, it's a known (and resolved in later versions) bug in SDL. Workaround locally by flipping Y or use a later version. Alex.
RE: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
Aha! Thanks for clarifying... After doing so many braintwisting tutorials that required me to move my camera right to make my object go left has left my brain swiss-cheesed :) -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Alex Holkner Sent: Wednesday, January 17, 2007 09:45 To: pygame-users@seul.org Subject: Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion Chris Ashurst wrote: I think on all systems (and if you're used to getting mouse x/y coordinates via the SDL side of pygame) the mouse is flipped when you use OpenGL. No, it's a known (and resolved in later versions) bug in SDL. Workaround locally by flipping Y or use a later version. Alex. CONFIDENTIAL NOTICE: This email including any attachments, contains confidential information belonging to the sender. It may also be privileged or otherwise protected by work product immunity or other legal rules. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information is strictly prohibited. If you have received this email in error, please immediately notify us by reply email of the error and then delete this email immediately.
Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
try to use glOrtho instead og gluOrtho2D and see if you still get the same # glOrtho(left, right, bottom, top, zNear, zFar) glOrtho(0, 640, 480, 0, 1, 0) should set 0,0 to the left,top Chris Ashurst wrote: I think on all systems (and if you're used to getting mouse x/y coordinates via the SDL side of pygame) the mouse is flipped when you use OpenGL. I think it's something to do with the fact that OpenGL itself is device and system agnostic, and was built with the idea in mind that it's just a 3d engine rather than a 3d engine + widgets. Additionally, it may also be something to do with the fact that any object you manipulate in an OGL context is relative to the camera, and to move the camera around an object you have to move it right if you want the object to move left, up to move it down and so on. People with more experience with OpenGL can probably clarify, but I have hit this same issue before, too. I think the x coord turned out to be fine, all I needed to do was write a function that inverted the y coordinate to get the real value. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dave LeCompte (really) Sent: Tuesday, January 16, 2007 20:20 To: pygame-users@seul.org Subject: [pygame] MacOS/PyGame/PyOpenGL mouse inversion Hi there, I'm new to the list, so this may have been answered before. I've got a PyGame/PyOpenGL app that I'm working on which I can run under MSWindows or Mac OSX and in windowed or fullscreen mode. I notice that when I run in a window on my Mac, the value returned by pygame.mouse.get_pos() is relative to the lower left corner of the screen, but if I run fullscreen on the Mac, fullscreen on by Windows PC, or in a window on the Windows PC, the value is relative the the upper left corner (agreeing with the docs at http://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos ). Is this a known issue? Attached is a short test script that displays the strange behavior. -Dave LeCompte CONFIDENTIAL NOTICE: This email including any attachments, contains confidential information belonging to the sender. It may also be privileged or otherwise protected by work product immunity or other legal rules. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information is strictly prohibited. If you have received this email in error, please immediately notify us by reply email of the error and then delete this email immediately.
Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
altern wrote: No, it's a known (and resolved in later versions) bug in SDL. Workaround locally by flipping Y or use a later version. My pygame.__version__ reports '1.8.0pre', which suggests to me that this bug fix hasn't made it into the latest Mac binaries. altern wrote: try to use glOrtho instead og gluOrtho2D and see if you still get the same # glOrtho(left, right, bottom, top, zNear, zFar) glOrtho(0, 640, 480, 0, 1, 0) should set 0,0 to the left,top Replacing glOrtho with glOrtho2D produced identical results on all platforms, including the inconsistency on the Mac when windowed. Thanks for the help. -Dave LeCompte Chris Ashurst wrote: I think on all systems (and if you're used to getting mouse x/y coordinates via the SDL side of pygame) the mouse is flipped when you use OpenGL. I think it's something to do with the fact that OpenGL itself is device and system agnostic, and was built with the idea in mind that it's just a 3d engine rather than a 3d engine + widgets. Additionally, it may also be something to do with the fact that any object you manipulate in an OGL context is relative to the camera, and to move the camera around an object you have to move it right if you want the object to move left, up to move it down and so on. People with more experience with OpenGL can probably clarify, but I have hit this same issue before, too. I think the x coord turned out to be fine, all I needed to do was write a function that inverted the y coordinate to get the real value. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of Dave LeCompte (really) Sent: Tuesday, January 16, 2007 20:20 To: pygame-users@seul.org Subject: [pygame] MacOS/PyGame/PyOpenGL mouse inversion Hi there, I'm new to the list, so this may have been answered before. I've got a PyGame/PyOpenGL app that I'm working on which I can run under MSWindows or Mac OSX and in windowed or fullscreen mode. I notice that when I run in a window on my Mac, the value returned by pygame.mouse.get_pos() is relative to the lower left corner of the screen, but if I run fullscreen on the Mac, fullscreen on by Windows PC, or in a window on the Windows PC, the value is relative the the upper left corner (agreeing with the docs at http://www.pygame.org/docs/ref/mouse.html#pygame.mouse.get_pos ). Is this a known issue? Attached is a short test script that displays the strange behavior. -Dave LeCompte CONFIDENTIAL NOTICE: This email including any attachments, contains confidential information belonging to the sender. It may also be privileged or otherwise protected by work product immunity or other legal rules. This information is intended only for the use of the individual or entity named above. If you are not the intended recipient, you are hereby notified that any disclosure, copying, distribution or the taking of any action in reliance on the contents of this emailed information is strictly prohibited. If you have received this email in error, please immediately notify us by reply email of the error and then delete this email immediately.
Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
Good news everyone! I found out why I could never get anywhere: I was too afraid of breaking stuff so I didn't try to mess with anything. However, if you don't break it, how can you fix it? So, I looked over that pygame thing again and decided to just start doing things that came to mind. It took me five minutes to get it working, much faster than if I had begged someone to tell me how to do it. Python really is a simple language after all, I think I really understand this now! This is what my code looks like now: *** #Credit to scriptedfun (http://www.scriptedfun.com) for the help with the typing portion #Stil a very VERY barebones typing script. Still got one last part of the main #engine to go before getting to work on part two. import pygame from pygame.locals import * SCREENRECT = Rect(0, 0, 640, 480) class Textsprite(pygame.sprite.Sprite): def __init__(self, text): pygame.sprite.Sprite.__init__(self) self.text = text self.pos = 0 self.current_string = 0 self.update() def update(self): self.image = pygame.font.Font(None, 36).render(self.text[self.current_string], 1, (0, 0, 0)) self.highlight = pygame.font.Font(None, 36).render(self.text[self.current_string][:self.pos], 1, (0, 0, 255)) self.image.blit(self.highlight, (0, 0)) self.rect = self.image.get_rect() self.rect.center = pygame.display.get_surface().get_rect().center def keyin(self, key): if key == self.text[self.current_string][self.pos]: self.pos = self.pos + 1 elif key == K_TAB: self.pos = self.pos else: self.combo = 0 if len(self.text[self.current_string]) == self.pos: self.pos = 0 self.current_string = self.current_string +1 def main(): pygame.init() screen = pygame.display.set_mode(SCREENRECT.size) # make background background = pygame.Surface(SCREENRECT.size).convert() background.fill((255, 255, 255)) screen.blit(background, (0, 0)) pygame.display.update() # keep track of sprites all = pygame.sprite.RenderUpdates() # keep track of time clock = pygame.time.Clock() textsprite = Textsprite([test string1, another test!, can you type this?]) all.add(textsprite) # game loop while 1: # get input for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: return else: textsprite.keyin(event.unicode) # clear sprites all.clear(screen, background) # update sprites all.update() # redraw sprites dirty = all.draw(screen) pygame.display.update(dirty) # maintain frame rate clock.tick(30) if __name__ == '__main__': main() *** Now, there's just one problem, and I'm pretty sure you can see it: After the program goes through all the strings, it doesn't stop at the last one and tries to add one again. Which won't work, and the program will print an error about it going out of bounds. I'm working on that now, it should take no less than five or ten minutes to figure out. Thanks for all your help!
Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?
Great progress! One question, are you backing up your code in between breaking it? On Jan 17, 2007, at 11:43 AM, Charles Christie wrote: Good news everyone! I found out why I could never get anywhere: I was too afraid of breaking stuff so I didn't try to mess with anything. However, if you don't break it, how can you fix it? So, I looked over that pygame thing again and decided to just start doing things that came to mind. It took me five minutes to get it working, much faster than if I had begged someone to tell me how to do it. Python really is a simple language after all, I think I really understand this now! This is what my code looks like now: *** #Credit to scriptedfun (http://www.scriptedfun.com) for the help with the typing portion #Stil a very VERY barebones typing script. Still got one last part of the main #engine to go before getting to work on part two. import pygame from pygame.locals import * SCREENRECT = Rect(0, 0, 640, 480) class Textsprite(pygame.sprite.Sprite): def __init__(self, text): pygame.sprite.Sprite.__init__(self) self.text = text self.pos = 0 self.current_string = 0 self.update() def update(self): self.image = pygame.font.Font(None, 36).render(self.text[self.current_string], 1, (0, 0, 0)) self.highlight = pygame.font.Font(None, 36).render(self.text[self.current_string][:self.pos], 1, (0, 0, 255)) self.image.blit(self.highlight, (0, 0)) self.rect = self.image.get_rect() self.rect.center = pygame.display.get_surface().get_rect ().center def keyin(self, key): if key == self.text[self.current_string][self.pos]: self.pos = self.pos + 1 elif key == K_TAB: self.pos = self.pos else: self.combo = 0 if len(self.text[self.current_string]) == self.pos: self.pos = 0 self.current_string = self.current_string +1 def main(): pygame.init() screen = pygame.display.set_mode(SCREENRECT.size) # make background background = pygame.Surface(SCREENRECT.size).convert() background.fill((255, 255, 255)) screen.blit(background, (0, 0)) pygame.display.update() # keep track of sprites all = pygame.sprite.RenderUpdates() # keep track of time clock = pygame.time.Clock() textsprite = Textsprite([test string1, another test!, can you type this?]) all.add(textsprite) # game loop while 1: # get input for event in pygame.event.get(): if event.type == QUIT: return elif event.type == KEYDOWN: if event.key == K_ESCAPE: return else: textsprite.keyin(event.unicode) # clear sprites all.clear(screen, background) # update sprites all.update() # redraw sprites dirty = all.draw(screen) pygame.display.update(dirty) # maintain frame rate clock.tick(30) if __name__ == '__main__': main() *** Now, there's just one problem, and I'm pretty sure you can see it: After the program goes through all the strings, it doesn't stop at the last one and tries to add one again. Which won't work, and the program will print an error about it going out of bounds. I'm working on that now, it should take no less than five or ten minutes to figure out. Thanks for all your help!
Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
This is all good knowledge to have, to be sure, but I think we're wandering afield from my original issue - I didn't want to ask about the default OpenGL coordinate systems, I'm reporting that the same code behaves differently on a Mac in a window than anywhere else. Run the code fullscreen on a Mac, it behaves as I expect. Run the code on a MSWindows PC, it behaves as I expect. I'm proceeding with the understanding that this is a known and resolved bug in the Mac SDL code and will be fixed when the 1.8 (final) binaries of PyGame are ready. Thanks, Dave LeCompte On 1/17/07, Chris Ashurst [EMAIL PROTECTED] wrote: I think on all systems (and if you're used to getting mouse x/y coordinates via the SDL side of pygame) the mouse is flipped when you use OpenGL. People with more experience with OpenGL can probably clarify, but I have hit this same issue before, too. I think the x coord turned out to be fine, all I needed to do was write a function that inverted the y coordinate to get the real value. If your use of openGL changes anything about the mouse coordinates returned from pygame, then I think it's a bug, like Alex says. Moving the mouse down (towards you) should always make it's y position increase, and moving it up (away from you) should always make it's y position decrease. However, when it comes to window coordinates, openGL by default uses a coordinate system where 0,0 is the lower left, and positive x goes right and positive y goes up. This is different from most computer systems where y goes down and 0,0 is the upper left. OpenGL uses the system it does because it follows the conventions of the cartesian coordinate space used in math physics. The place where you'd notice this the most in games is when using trig functions like sin cos, which also are designed for math physics openGL coordinate systems (positive rotations are counter-clockwise, 0 degrees is straight right y is up) So basically, I'm saying it's not that the mouse is flipped with OpenGL, it's that unless you set up your transforms to change it, OpenGL is flipped from what all the pygame/SDL and desktop position stuff is
Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
Dave LeCompte (really) wrote: This is all good knowledge to have, to be sure, but I think we're wandering afield from my original issue - I didn't want to ask about the default OpenGL coordinate systems, I'm reporting that the same code behaves differently on a Mac in a window than anywhere else. Run the code fullscreen on a Mac, it behaves as I expect. Run the code on a MSWindows PC, it behaves as I expect. I'm proceeding with the understanding that this is a known and resolved bug in the Mac SDL code and will be fixed when the 1.8 (final) binaries of PyGame are ready. Sorry, made a mistake; the Pygame mac binary (1.7, haven't checked 1.8pre) includes SDL 1.2.11, which is current. Evidentally the issue is known but not resolved (some Googling on the topic will give you an idea of which releases of SDL it is fixed in, and which ones it is broken in). Alex.
Re: [pygame] MacOS/PyGame/PyOpenGL mouse inversion
I ran the sample script provided on an intel iMac OS X 10.4.8 with pygame 1.8.0pre and both windowed and full-screen behaved correctly (the diamond followed the mouse) according to the headers for the framework sdl build I've got, it's 1.2.11 It makes sense to me that it would be fixed in the latest because I looked at the libsdl mailing list archives and this post seemed to be a patch for the problem: http://www.libsdl.org/pipermail/sdl/2005-November/071307.html and this post indicated it had been applied: http://www.libsdl.org/pipermail/sdl/2005-November/071404.html So Dave, what OS X version are you running on? Can you tell which SDL your pygame is running on?