Load OpenGL Commands From A Text File

Started by
8 comments, last by nefthy 18 years ago
Is it possible? I mean, say I had my simple code to render a quad within a text file glBegin bmquads glvertex3f 0,0,0 glvertex3f 0,1,0 glvertex3f 1,0,0 glvertex3f 1,1,0 glend Is there any way I can simply get OGL to loads those commands? Thanks for any help.
Advertisement
No, but what you can do is store the vertices in a file, load them into a vertex array, and render them that way.

You could also read the opengl calls from the file, determine what they were through some interpretive type functions, and then call them as part of a display list creation.
If all you were doing is quads, then you could do something like, read in the first word (i.e. the OpenGL command) and then say, if(command == "glBegin") then do some stuff, else if(command == "glVertex3f") do other stuff... But, as you can see, that can become tedious. To do what you're asking, you would need to integrate a scripting language into your program. I would recommend looking into Lua.
not unless you want to write a mini lexer/tokeniser and parse all that crap yourself, its probrably easier to just have it load regular 3d models? i can't see any good reason for wanting to load OGL commands from a file?
Steven ToveySPUify | Twitter
The reason that i want to load ogl commands from a while is that i've written a file that interprets a VRML file from Pro/Desktop or 3ds Max and sorts all the faces etc, then you have to chose a texture as your next step, because that's not included in the VRML file. If it was then i would just load the VRML file straight into my OGL program.

Thanks for your help guys, have to think of some other way :(
Hello,

You can always load a DLL with the code. Or you can write a simple parser language as suggested above but I think it would be too complicated for the task. DLLs also allows the user to code in the language he is more comfortable with. Hope this helps,

JVFF
ThanQ, JVFF (Janito Vaqueiro Ferreira Filho)
Quote:Original post by jvff
Hello,

You can always load a DLL with the code. Or you can write a simple parser language as suggested above but I think it would be too complicated for the task. DLLs also allows the user to code in the language he is more comfortable with. Hope this helps,

JVFF


Screw writing your own parser, if you are interested in changing certain material properties look into the shader language used for quake3.
----------------------------

http://djoubert.co.uk
double post:accident
----------------------------

http://djoubert.co.uk
Quote:Original post by dawidjoubert
Quote:Original post by jvff
Hello,

You can always load a DLL with the code. Or you can write a simple parser language as suggested above but I think it would be too complicated for the task. DLLs also allows the user to code in the language he is more comfortable with. Hope this helps,

JVFF


Screw writing your own parser, if you are interested in changing certain material properties look into the shader language used for quake3.


Erm, unless you write your own lexer/parser, how you do expect to parse a script similar to the one Q3 uses? Anyway you look at it, if you have a pure text input that you want to convert to anything else you're going to have some sort of parser in there.

Quite luckily however, there are some very decent parsers/lexers out there. Take a look at boost::spirit and Yacc/flex/bison.

You probably don't want to do any of that however, just look into loading standard model formats.
If at first you don't succeed, redefine success.
Ofcourse it is possible. The question is how much code you need to write for it. Function pointers would be the way to go if you ask me. Somthing allong the lines of a table that associates function names (strings) with function pointers and some way to translate the argument. A lot of this could be generated automaticaly using the infos contained in the header.

I think using lex and similar stuff would be overkill, but then I haven't used this tools much.

Edit: supposing that you want to do somthing script-like. Not only geometry. Anyway if you want to type the whole stuff, you can simply make it a function and name the file .c

This topic is closed to new replies.

Advertisement