{"action":"created","issue":{"url":"https://api.github.com/repos/bitcraft/PyTMX/issues/59","labels_url":"https://api.github.com/repos/bitcraft/PyTMX/issues/59/labels{/name}","comments_url":"https://api.github.com/repos/bitcraft/PyTMX/issues/59/comments","events_url":"https://api.github.com/repos/bitcraft/PyTMX/issues/59/events","html_url":"https://github.com/bitcraft/PyTMX/issues/59","id":95966098,"number":59,"title":"convenient Image Loader for OpenGL formatted display coordinates","user":{"login":"evbo","id":6313004,"avatar_url":"https://avatars.githubusercontent.com/u/6313004?v=3","gravatar_id":"","url":"https://api.github.com/users/evbo","html_url":"https://github.com/evbo","followers_url":"https://api.github.com/users/evbo/followers","following_url":"https://api.github.com/users/evbo/following{/other_user}","gists_url":"https://api.github.com/users/evbo/gists{/gist_id}","starred_url":"https://api.github.com/users/evbo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evbo/subscriptions","organizations_url":"https://api.github.com/users/evbo/orgs","repos_url":"https://api.github.com/users/evbo/repos","events_url":"https://api.github.com/users/evbo/events{/privacy}","received_events_url":"https://api.github.com/users/evbo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-20T01:26:42Z","updated_at":"2015-07-20T03:00:27Z","closed_at":null,"body":"When displaying tiles in OpenGL formatted coordinate systems (y=0 occurs at bottom of page instead of top of page), there is a simple transformation needed to ensure data appearing at the top of the page has coordinates starting from max(y) rather than 0. Would it make sense to incorporate an image loader that handles this simple, yet common transformation?\r\n\r\nSee below where I had to subclass TiledMap and override the `reload_images` method just to set the `image_loader` to one that **sets the y ordinate based on the current `tileset`'s `tileheight` and `height`**. Is there a cleaner, more future-version-compatible-robust way for loading images with correct coordinates for OpenGL displays?\r\n\r\n\r\n\r\n\r\n    class OpenGLTiledMap(TiledMap):\r\n\r\n\r\n        def reload_images(self):\r\n\r\n            def GL_image_loader(filename, flags, **kwargs):\r\n                \"\"\" convert the y coordinate to opengl format where\r\n                    the bottom-most coordinate in the image is 0\r\n                \"\"\"\r\n                ts = self.fname2ts[filename]\r\n                def load((x,y,w,h)=None, flags=None):\r\n                    GL_y = ts.height - ts.tileheight - y\r\n                    return filename, (x,GL_y,w,h), flags\r\n\r\n                return load\r\n\r\n            self.fname2ts = dict((ts.source, ts) for ts in self.tilesets)\r\n            self.image_loader = GL_image_loader\r\n            super(OpenGLTiledMap, self).reload_images()\r\n\r\n\r\nAlso, this issue comes up again after you've loaded the images from the tileset and now need to play them as widgets in your OpenGL display window. Again, the conversion is needing to know `tileset` specific dimensions. Is there a convenient way to look this up?\r\n\r\nFor instance, I do something kinda ugly like this:\r\n\r\n    layer = self.map.get_layer_by_name('ground')\r\n    max_y = len(layer.data)\r\n    for (x, y, ts_props) in layer.tiles():\r\n        # correct the y value for openGL displays\r\n        y = max_y - y\r\n"},"comment":{"url":"https://api.github.com/repos/bitcraft/PyTMX/issues/comments/122738104","html_url":"https://github.com/bitcraft/PyTMX/issues/59#issuecomment-122738104","issue_url":"https://api.github.com/repos/bitcraft/PyTMX/issues/59","id":122738104,"user":{"login":"bitcraft","id":556711,"avatar_url":"https://avatars.githubusercontent.com/u/556711?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcraft","html_url":"https://github.com/bitcraft","followers_url":"https://api.github.com/users/bitcraft/followers","following_url":"https://api.github.com/users/bitcraft/following{/other_user}","gists_url":"https://api.github.com/users/bitcraft/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcraft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcraft/subscriptions","organizations_url":"https://api.github.com/users/bitcraft/orgs","repos_url":"https://api.github.com/users/bitcraft/repos","events_url":"https://api.github.com/users/bitcraft/events{/privacy}","received_events_url":"https://api.github.com/users/bitcraft/received_events","type":"User","site_admin":false},"created_at":"2015-07-20T03:00:27Z","updated_at":"2015-07-20T03:00:27Z","body":"Thanks for your interest with pytmx.  As far as inverting the y-coordinate, there is a way to do that already (has partial support).  Pass 'invert_y=True' to whatever loader or to the TiledMap constructor.  That value will be saved in the TiledMap instance.  I think the proper solution would be to modify TiledTileLayer.parse_xml to be inverted_axis aware.  That would be somewhere around here:  https://github.com/bitcraft/PyTMX/blob/master/pytmx/pytmx.py#L916\r\nIt would remove the need for a special loader and all data access would be flipped.  Of course, then the data in memory will be flipped as well.  Thoughts?\r\n\r\n```python\r\n    tmx_data = pytmx.TiledMap(..., invert_y=True)\r\n```\r\n\r\nAs far as image loading goes, there is another approach to image loading that you may be interested in.  You can define a function to load images, without resorting to subclassing...pass an argument to the TiledMap constructor.  Please see the link below for more information:\r\nhttps://github.com/bitcraft/pytmx#custom-image-loading\r\n\r\nWhat graphics library are you using now?   ...just curious."}}