View Full Version : Creating OpenGL commands at runtime

02-09-2005, 10:16 AM
I am trying to find a way to create OpenGL commands at runtime. I have situation where I need to take information from a text file discribing the object and render it to the screen using OpenGL. However, to do this I need to create the OpenGL commands in a string and then execute them.

Currently I only know how to hard code the commands within the source and compile / execute them in that manner. I realize I could propably create multiple functions containing the OpenGL commands and call them in that manner but I really do not want to.

Can someone tell me if there is a way to do this or am I way out of the ball park.


02-09-2005, 01:14 PM
Honestly the easiest way I can think of is using an interpreted language like Perl or Python that has an OpenGL wrapper. In that way you can just create the commands in a sctring and let the interpreter execute it.

Hope it helps


02-09-2005, 02:04 PM
Here are some links you may find cool.


I'm a big fan of python and being able to integrate it into your application and have two way interactions from your app and python scripts is really cool. I'm right now starting to integrate it into my little 3d demo engine. It should turn out nicely.


02-09-2005, 04:04 PM
For some reason my brain kept reading "OpenGL Commandos" and I couldn't help but imagine this scene of a landing craft hitting a beach and several dozen polygon-rendered texture-mapped guys with the OpenGL logo on their chests streaming off, guns blazing.

I really need to take a break from computers.

02-09-2005, 06:43 PM
Haha. OpenGL commandos, that's funny. Maybe you should live your fantasy and make a game like that. :D

Oh and each commando's name is one of the OpenGL function or extension names. :)

Wait a min...you're "name" is Omaha and you are picturing a beach landing scene with commandos pouring out? Interesting... ;)


02-10-2005, 03:17 AM
Thanks for the advice I will look into the python solution but I really do not think it is going to work. I need to update the information at 30 to 60 fps.

I guess I will just continue with creating the gazzilion and one function calls.

Anyway, I like the idea of the OpenGL commandos attacking the beach.

02-10-2005, 07:25 AM
When you just want to render a geometric model saved in a file, the easiest way would be loading it, storing the vertices & co in arrays an then looping over them and calling glVertex... Or simply use vertex arrays.

For general commands, you could save each command as a string and do something like this. It's an ugly way to do it and I wouldn't do it by myself, but maybe you get the idea and expand on it. Or you could implement a parser and make it nice and save :)

string commands[] = { "glPushMatrix", "glLoadIdentity" ,...}
for (int i=0; i < num_commands; ++i)
switch ( command[i])
case "glPushMatrix": glPushmatrix(); break;
case "glLoadIdentity": glLoadIdentity(); break;

02-10-2005, 09:02 AM
Just to let you know, scripting languages like python are not slow. Entire 3d engines have actually been written purely in python. If you tried it out I'm sure you would be amazed. :)


02-10-2005, 09:45 AM
That data is not really stored in a file like that. It is CGM and location data that shows up in a video stream at 30/60/120 hertz. I need to interpet the CGM, mix in some other mapping / user specific information and display it to the screen overtop of the video. Also it needs to have a generic code base that can easily be recompiled on windows, UNIX, MAC, and LINUX. That is why I am using OpenGL to do all of the object drawing.

I can easily interpet the CGM and location information but I was having some issues with the speed of overlaying all of the interpeted information and transformaing the information on the fly to openGL.

That is why I was looking for an easier way to handle the creation of the OpenGL commands on the fly.

02-10-2005, 12:16 PM
Omaha, are you a devotee of latestchatty.x? Yes, this is rather cryptic for some people. :)

02-14-2005, 04:39 AM
Alternative to Python : http://www.lua.org
Both are real powerful tools.

Delayed call in all their splendor : boost::function and boost::bind http://www.boost.org
boost::bind changed my life

Basic tutorial on functors :