Drawing to the screen with Python

I’ve always been annoyed with having to mess with planes in the BGE to make any sort of gui/hud. So, after talking with some of the devs, a solution was found. This video outlines the problem and the solution. It also has a very simple demo using a gui library that I’m working on. I’ll work on a video that has a bit more “wow factor” and post it later. Also, some implementation specifics might change.

The video:

GREAT!!! will be included in official trunk?

The patch is pretty small, and not a lot of changes are made to the source code, so getting the patch accepted for 2.5 probably wont be difficult. However, I’ll still need to clean things up a bit.

AWESOME! That will make text/gui/EVERYTHING so much easier. In theory it should be faster as well?

Is this all software-based drawing, or can it be hardware accelerated?


Could this be used to make dynamic text messages? Letter by letter…

Wow… great timing. I just got started making an UI for the first time and spent the whole morning fighting with overlay scenes and imagining how wonderful would it be if I could just draw directly to the screen from my script.

Then I come to the forums and I read this. Awesome news :slight_smile: Thanks a lot for taking your time Moguri.

Very cool! I’ve been making HUDs by putting all the “2d” elements in an overlay scene with an ortho camera, but this would probably work far better.

note that this isnt limited to 2D elements, you could make a particle system (suggested by Moguri), skydome (backdrop), augmented reality - whatever :slight_smile:
The ZBuffer is available so you can draw overlays that dont go behind existing objects drom the depth buffer.

You could also use python to call an external C module (say if your particle system was very nice but 100000 particles was getting slow)

Another thing, if you want to draw complex objects and think it will be slow, - You can make them into a display list, then python only needs to pass an argument to openGL and the DispList gets drawn from openGL memory.

Wooow so we could actually use that info to make our own screen shaders in python without having to write in glsl. I could write things like glow effects for specific objects or full screen glare or any sorts of cool stuff using only python scripts. Omg… O.O

This sounds amazing, I really hope to see implemented soon ^^

I’ll work on a video that has a bit more “wow factor” and post it later.

Looking forward to it ^^

Yay :stuck_out_tongue:

The pre-draw and post-draw is a really good way of doing it as well.

Hi there… is there another version of the video… I’m getting strange errors from youtube complaining about javascript not being on and about not having the latest flash… which I do have… grrrrr. I would love to see it :wink:

Yeh, that would be great :cool:

+1, really nice ! quake-like console ^^
can you interact with the objects you draw ? (mouseover planes, game logic…)

Creating a way to interact with the objects would be up to the user. For example, a mouse click sensor could be used to give a script the coordinates of the mouse with it was clicked. Then, the script could look over the object’s it has drawn and see if the mouse is over any of them, then respond.

By the way, I haven’t been working much on a demo; I’ve gotten distracted by other things. I spent a few days trying to get a particle example going, but unfortunately, I couldn’t get it going quite right with the billboarding.

Yea, we all have that problem. :wink:

Just keep at it. I’m looking forward to seeing it in action.