Virtual terminal in C++ based OpenGL program

Hello All!

I use OpenGL for small research applications. In many cases, I need to control a few variables, and I either use GLUI or just glut and a very simply keyboard interface.

However, games and some graphics applications have a nice feature where you simply hit the terminal key in order to get a text interface where you can issue commands and change variables in your program. If such a console is of variable size and overlayed it could also be used to display things like framerate and other state.

See, this is where I get greedy. If I could also script in LUA or Python in such a beast, I would have an awesome flexibility.

Of course there are OpenGL bindings for anything you can code in, so I could just change my apps to libraries and run them from a scripting console.

However, that is not what I want. I want a console embedded in my application. The input and output should be via the same window that displays OpenGL and the input and output should go to/come from a script engine that has access to my C++ program state.

I know some people have made consoles (eg there is one for SDL) and it is arguably not an enormous task to make a simple console, but it only becomes elegant when IO is funneled to a scripting engine that can see the state of the program.

Is there some beast like that?



This discussion seem related to your needs :…;num=1215072649

absolutely - it is. However, the project you link to seems to be based on Java and using the Java introspection feature. That sounds very elegant, but my starting point is a C++ application :slight_smile:

And what about using BOOST to interface directly with Python ?
In fact your problem is not “how to do a console” but “how to embed a scripting language”.
This has some infos :
And more here :

> In fact your problem is not “how to do a console” but “how to embed a scripting
> language”.

Embedding a scripting language is the most important part of the solution, but what I am looking for is the glue between C++ and the scripting engine that is embedded.

As I understand it, I would still have the problem of getting input from the OpenGL window to the embedded scripting engine and rendering the text output from the scripting engine in the OpenGL window?

Of course, I would like things like tab completion and history :sunglasses:


BOOST is a glue between python and c++.

The input does not look so hard to me, just catch keypresses, store in a string (with special cases for backspace/delete/left/right keys), and when ‘enter’ is hit, feed it to the embedded python interpreter.

History is pretty easy.

But tab completion… Maybe use python introspection ?

Thanks for your suggestions. Your are right, most of the glue I need is fairly straightforward and I do know how to implement it. It is just a great deal of work, and I would be curious to know about other people who have been there and done that. At least it would be a useful source of information about how to make such a project.

Meanwhile since posting, I have, in fact, found some projects:

OGLConsole :

is simple to compile and provides a very simple console feature. It is only implemented on top of SDL however, and although a screenshot shows python integration, it is not a feature in the example.

GLConsole :

is a bit more sophisticated with the nice feature that it can serialize the variables changed in the console to disk so that they are the same when you restart. I did not manage to compile this. I work on Mac and the example is made for Windows. Should be possible though, but I got a lot of template errors and no patience.
Unlike the other projects, it is made for glut.


another example. I think there is one more with a similar name. I did not go into details with these projects.


The GPL game SoulRide :

has a built in LUA console. Thatcher Ulrich pointed someone else in the general direction of the game in response to a question similar to min. Indeed I can compile that and run the game (which is simple but cool) and get a nice console to play with. Looking at the code should be helpful.

So I guess SoulRide was really the example I was looking for.

Perhaps this brief list can of some use to others: Initially I did not find these, since google: “console opengl” just gets you a lot of Visual Studio console programs that use OpenGL. Searching directly on sourceforge was more useful.


Thanks for the links indeed.
I heard about OGLConsole but was unable to find it again, as you said searching for “console opengl” does not give significant results.