Is it possible yet to script in rendering type commands for Celestia or am I just dreaming?
I figure that might be a tad difficult to do OpenGL rendering scripts via Lua....but something like this would be very cool....
Is this possible yet?
Is this possible yet?
I'm trying to teach the cavemen how to play scrabble, its uphill work. The only word they know is Uhh and they dont know how to spell it!
-
- Posts: 164
- Joined: 18.03.2004
- Age: 63
- With us: 20 years 8 months
- Location: Victoria, BC Canada
Re: Is this possible yet?
Rassilon wrote:Is it possible yet to script in rendering type commands for Celestia or am I just dreaming?
I figure that might be a tad difficult to do OpenGL rendering scripts via Lua....but something like this would be very cool....
If you mean that you would like to have lines or objects drawn by using script commands, then this is not yet possible. Sorry.
I myself would love to see even simple draw line commands supported. Maybe someday.
Clive Pottinger
Victoria, BC Canada
Victoria, BC Canada
Re: Is this possible yet?
cpotting wrote:I myself would love to see even simple draw line commands supported. Maybe someday.
well, I'm currently working on adding a drawline celx-command.
but it's a lot of coding and testing todo yet
most recent celestia win32-SVN-build - use at your own risk (copy over existing 1.5.1 release)
Re: Is this possible yet?
phoenix wrote:cpotting wrote:I myself would love to see even simple draw line commands supported. Maybe someday.
well, I'm currently working on adding a drawline celx-command.
but it's a lot of coding and testing todo yet ;)
phoenix,
I've implemented a Lua binding to some basic OpenGL commands as a part of my Lua hook experiments. For convenience I included it in celx.cpp to avoid the need for a dynamic library. Here's what the code looks like:
Code: Select all
static int gl_Vertex(lua_State* l)
{
checkArgs(l, 2, 2, "Two arguments expected for gl.Vertex()");
float x = (float)safeGetNumber(l, 1, WrongType, "argument 1 to gl.Vertex must be a number", 0.0);
float y = (float)safeGetNumber(l, 2, WrongType, "argument 2 to gl.Vertex must be a number", 0.0);
glVertex2f(x,y);
return 0;
}
static int gl_Color(lua_State* l)
{
checkArgs(l, 4, 4, "Four arguments expected for gl.Color()");
float r = (float)safeGetNumber(l, 1, WrongType, "argument 1 to gl.Color must be a number", 0.0);
float g = (float)safeGetNumber(l, 2, WrongType, "argument 2 to gl.Color must be a number", 0.0);
float b = (float)safeGetNumber(l, 3, WrongType, "argument 3 to gl.Color must be a number", 0.0);
float a = (float)safeGetNumber(l, 4, WrongType, "argument 4 to gl.Color must be a number", 0.0);
glColor4f(r,g,b,a);
return 0;
}
static int gl_Begin(lua_State* l)
{
checkArgs(l, 1, 1, "One argument expected for gl.Begin()");
int i = (int)safeGetNumber(l, 1, WrongType, "argument 1 to gl.Begin must be a number", 0.0);
glBegin(i);
return 0;
}
static int gl_End(lua_State* l)
{
checkArgs(l, 0, 0, "No arguments expected for gl.PopMatrix()");
glEnd();
return 0;
}
static int gl_Enable(lua_State* l)
{
checkArgs(l, 1, 1, "One argument expected for gl.Enable()");
int i = (int)safeGetNumber(l, 1, WrongType, "argument 1 to gl.Enable must be a number", 0.0);
glEnable(i);
return 0;
}
static int gl_Disable(lua_State* l)
{
checkArgs(l, 1, 1, "One argument expected for gl.Disable()");
int i = (int)safeGetNumber(l, 1, WrongType, "argument 1 to gl.Disable must be a number", 0.0);
glDisable(i);
return 0;
}
...
static void gl_loadlib(lua_State* l)
{
lua_pushstring(l, "gl");
lua_newtable(l);
RegisterMethod(l, "Frustum", gl_Frustum);
RegisterMethod(l, "Ortho", gl_Ortho);
RegisterMethod(l, "Color", gl_Color);
RegisterMethod(l, "TexCoord", gl_TexCoord);
RegisterMethod(l, "Vertex", gl_Vertex);
RegisterMethod(l, "Translate", gl_Translate);
RegisterMethod(l, "BlendFunc", gl_BlendFunc);
RegisterMethod(l, "Begin", gl_Begin);
RegisterMethod(l, "End", gl_End);
RegisterMethod(l, "Enable", gl_Enable);
RegisterMethod(l, "Disable", gl_Disable);
RegisterMethod(l, "MatrixMode", gl_MatrixMode);
RegisterMethod(l, "PopMatrix", gl_PopMatrix);
RegisterMethod(l, "LoadIdentity", gl_LoadIdentity);
RegisterMethod(l, "PushMatrix", gl_PushMatrix);
RegisterValue(l, "QUADS", GL_QUADS);
RegisterValue(l, "LIGHTING", GL_LIGHTING);
RegisterValue(l, "LINE_LOOP", GL_LINE_LOOP);
RegisterValue(l, "POLYGON", GL_POLYGON);
RegisterValue(l, "PROJECTION", GL_PROJECTION);
RegisterValue(l, "MODELVIEW", GL_MODELVIEW);
RegisterValue(l, "BLEND", GL_BLEND);
RegisterValue(l, "TEXTURE_2D", GL_TEXTURE_2D);
RegisterValue(l, "SRC_ALPHA", GL_SRC_ALPHA);
RegisterValue(l, "ONE_MINUS_SRC_ALPHA", GL_ONE_MINUS_SRC_ALPHA);
lua_settable(l, LUA_GLOBALSINDEX);
}
The subset of OpenGL functions I've implemented should be more than sufficient for simple line drawing, and others can be added in a similar manner as needed. With this in place you can write Lua code that looks like this:
Code: Select all
gl.Enable(gl.TEXTURE_2D);
gl.Begin(gl.QUADS);
gl.Color(0.8, 0.8, 1.0, 1.0);
gl.TexCoord(0.0, 1.0);
gl.Vertex(lb, bb);
gl.TexCoord(1.0, 1.0);
gl.Vertex(rb, bb);
gl.Color(0.6, 0.6, 1.0, 1.0);
gl.TexCoord(1.0, 0.0);
gl.Vertex(rb, tb);
gl.TexCoord(0.0, 0.0);
gl.Vertex(lb, tb);
gl.End();
This will be included in the Lua hook patch which I hope to have ready in a day or two (or three...).
- Hank
I see.
does it really work? i've tried opengl commands directly from celx.cpp but had to write my own functions in render.cpp
I suspect you have a lua-hook implemented at the right position to make rendering possible with this?
what about depth-sorting and stuff?
I really like to play with your new code
does it really work? i've tried opengl commands directly from celx.cpp but had to write my own functions in render.cpp
I suspect you have a lua-hook implemented at the right position to make rendering possible with this?
what about depth-sorting and stuff?
I really like to play with your new code
most recent celestia win32-SVN-build - use at your own risk (copy over existing 1.5.1 release)
phoenix wrote:I see.
does it really work? i've tried opengl commands directly from celx.cpp but had to write my own functions in render.cpp
I suspect you have a lua-hook implemented at the right position to make rendering possible with this?
what about depth-sorting and stuff?
I really like to play with your new code :wink:
Yes, it really works. But it does require a Lua hook at the appropriate place in the Celestia C++ code. I've been using a hook in CelestiaCore:renderOverlay. This hook is for custom overlay drawing. For drawing within the 3D space simulation you'd need to have a hook at the appopriate point in the rendering code. In principle it should be possible to place hooks in any Celestia C++ object, but thus far I've only experimented with hooks in CelestiaCore.
I still have a bit of code cleanup and testing to do, but the patch should be ready soon. I think you'll have fun with it.
- Hank
Hooks ready?
Are the Lua hook patches ready yet? Will it be in 1.5 release? Is there going to be a hook in the rendering part or just overlay? (by overlay, I presume you mean the constellation and boundary stuff?) Would it be possible to use your hooks to force the drawing of an image (e.g. to implement constellation images in addition to apherisms)?
--Dale--
--Dale--
--Dale--