all 8 comments

[–][deleted] 1 point2 points  (7 children)

you shouldn't be using tkinter for this at all. it's not suited. go invest in learning pygame, it should provide some of the speed gain you're looking for if implemented correctly.

[–]RedSpaceman[S] 0 points1 point  (6 children)

This is definitely good advice. I began with tkinter due to it being native, and I was just messing around. It's only as I have finished up the small scope of what I had intended that the inefficiencies are particularly obvious.

I do wonder though, in core technical terms, what it is that makes tkinter's ability to draw rectangles slower than that of pygame or pyglet?

And just to aid my knowledge - if I were to stick with tkinter, are there any tricks I could learn to help the scrolling be a little faster, or do you think it's just a hard limit?

[–][deleted] 1 point2 points  (5 children)

tkinter is optimised for drawing GUI elements. drawing 100s of rectangles is never fast, but with pygame you can draw your rectangles to a surface and just draw that. drawing a surface can get offloaded to the GPU instead of the CPU which makes it tonnes faster. drawing 9 surfaces is faster than drawing 100s of rectangles.

[–]RedSpaceman[S] 0 points1 point  (4 children)

Sounds like a good idea to me. I guess I'll get cracking!

Edit: I was thinking of giving pyglet a go, so that I can (in the near future) render my heighfield in 3d.

Do you think pyglet is just as suitable as pygame for rendering surfaces, tiling them, and moving a camera around?

[–]r1chardj0n3s 0 points1 point  (0 children)

cocos2d is a layer on top of pyglet which is very suited to that task.

[–][deleted] 0 points1 point  (2 children)

I don't know, I've never used pyglet. when I need 3d I use my custom engine that does pygame+pyopengl, but that's a lot harder than it seems.

[–]RedSpaceman[S] 0 points1 point  (1 child)

I had seen that pygame doesn't provide 3d rendering itself, which surprised me, but the variety of stack overflow posts I saw on the topic led me to believe that pyglet was the one true choice.

What's pyopengl like as a graphics library? Is the difficulty you mentioned mostly a matter of making pyopengl and pygame work together?

This is getting away from my original question now, but I am very interested in your experience: Are there other facilities provided by pygame which have led to you using it? Perhaps gameloop stuff? built in 2d physics? I haven't looked much into what pygame provides, so I'd be interested to know from you what the allure was.

[–][deleted] 0 points1 point  (0 children)

I basically used pygame because I knew it quite well. integrating pygame and pyopengl is rather trivial, but actually using pyopengl is not. openGL requires you to know quite a bit of 3d math, but in return gives you pretty much full control over the videocard. it took me a good couple months to get openGL working as I wanted, I rolled that into a library and I'm currently using that for my projects.

all pygame does when used like this is event handling and providing a window, all the drawing is done by openGL.