Graphics with Python help please

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

TSPhoenix
Posts: 10
Joined: Tue Apr 01, 2008 7:57 am UTC

Graphics with Python help please

Postby TSPhoenix » Thu Mar 24, 2011 7:29 am UTC

Hi everyone. I recently got back into coding and I wound up coding the backend for an strategy RPG. Its written in Python 3 and working quite nicely, but currently all the "graphics" are in the terminal and I can't really progress any further without a proper way to represent whats going on and a GUI to feed input to the game.

I've spent like days Googling different libraries, OpenGL stuff, and so forth but I'm totally lost.

I don't know if I'm completely overlooking something. Or whether Python 3 wasn't the way to go and (1) I should just move it to Python 2 and use PyGame as that looks good. (2) I should learn another language??

Any advice would be much appreciated as I've found the infomation I've dug up on this topic nearly impossible to parse.

For now I'd be happy to get a top-down 2D tile-based grid working;
Image

But since my game has height and gradients coded in I need an isometric-type view to represent that;
Image

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Graphics with Python help please

Postby thoughtfully » Thu Mar 24, 2011 10:41 am UTC

In general, you're going to get better support from third party libraries if you use Python 2.x. However, PyGame seems to support 3.x (although it says 2.5 is best for Windows).
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

kmatzen
Posts: 214
Joined: Thu Nov 15, 2007 2:55 pm UTC
Location: Ithaca, NY

Re: Graphics with Python help please

Postby kmatzen » Thu Mar 24, 2011 6:26 pm UTC

I Googled "pygame isometric" and it looks like they have a category highlighting isometric projection-based engines. I haven't done it myself, but doing isometric projection with 2D graphics sounds really difficult as in there are a lot of cases to handle, right? Wouldn't it be easier to just use OpenGL and set up the projection matrix to get an isometric effect? I'm just thinking about things like occlusions and so on. If you want to put this on a cell phone or something afterwards, modern mobile devices will be able to handle the 3D graphics. There's even the question of efficiently rendering 2D sprites. I wonder if pygame helps you to efficiently manage sprite batches.

Sorry that I don't have a direct answer. I hope these ideas help you in your research.

User avatar
laranzu
Posts: 104
Joined: Fri Nov 30, 2007 4:21 pm UTC
Location: Physical: Canberra, Australia
Contact:

Re: Graphics with Python help please

Postby laranzu » Sat Mar 26, 2011 12:49 pm UTC

TSPhoenix wrote:Hi everyone. I recently got back into coding and I wound up coding the backend for an strategy RPG. Its written in Python 3 and working quite nicely, but currently all the "graphics" are in the terminal and I can't really progress any further without a proper way to represent whats going on and a GUI to feed input to the game.

I've spent like days Googling different libraries, OpenGL stuff, and so forth but I'm totally lost.

I don't know if I'm completely overlooking something. Or whether Python 3 wasn't the way to go and (1) I should just move it to Python 2 and use PyGame as that looks good. (2) I should learn another language??

Any advice would be much appreciated as I've found the infomation I've dug up on this topic nearly impossible to parse.

Moving to Python 2 for the GUI/graphics is probably going to be easier. Most Python interfaces to GUIs are still at Python 2 AFAIK.

A common design pattern for games is to separate the backend from the frontend user interface anyway, communicating by messages over a socket or similar. This allows you to do multiplayer very easily later on. And in the meantime, you can keep your backend in Python 3 and only use Python 2 for the frontend.

As for a GUI toolkit, I'd recommend wxPython. Runs on Macs, Linux, and MS Windows and probably other platforms. PyQt would be my second choice. Right now I recommend wxPython over PyQt because it just seems much more "Pythony" to use. PyQt also works, but too much of the underlying C++ shows through IMHO.

Both wxPython and PyQt can create OpenGL windows, and I'd recommend PyOpenGL if you're comfortable writing graphics directly. It's a pure Python wrapper for OpenGL using ctypes to do the native API calls. Yes, this is slow, but modern graphics cards are so fast that you're not going to notice. I've found that a lot of OpenGL code written in C can be pasted directly into PyOpenGL and it just works.

If you want to do higher level 2D/3D graphics, get yourself a copy of the Python Computer Graphics Kit. And if you're doing lots of stuff with raster graphics, the Python Imaging Library as well.

Hope this helps.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 8 guests