🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Hey, I'm writing a bind of modern OpenGL for Lua

Started by
0 comments, last by vstrakh 8 years, 11 months ago

So, the LuaGL we currently have is not very suited for modern OpenGL, for example, use shaders. It has some pitfals regarding moving data **from** and **to** OpenGL, and an overcomplicated code.

I'm writing a bind (which I'm using the same name: LuaGL) using only the functions describeds at the **OpenGL 4.5 API Reference Card**. My objective is to make it available for OpenGL 3.0 to 4.5. I will not put deprecated functions such "glBegin", "glEnd". So, to draw, you can use shaders.

I'm solving the problem of passing data to and from Lua-side with the implementation of two custom functions gl.DataToTable and gl.TableToData. With these two functions you can convert a table of vertex to a string (remember that you can store binary data in Lua's strings) and pass to gl.BufferData().

It is still a novice project, but is growing fast (I'm in dependence of this project to be done).

https://github.com/FelipeFS/luagl

Cheers, Gamedev's

My WebBlog : PixelDeveloper
Advertisement

I'm solving the problem of passing data to and from Lua-side with the implementation of two custom functions gl.DataToTable and gl.TableToData

...

and pass to gl.BufferData().

Consider Lua's flexibility. You don't have to enforce strict GL api, and then fight with it by adding more functions.

In my toy engine I'm trying to express GL/D3D api at higher level. Don't prepare data to fill buffer, just create new vbo, and hide conversions from scripts.

For example:


local mesh = vao {
    vbo {
        pos = vec3f {0,0,0, ......},
        normal = vec3f {0,1,0, ....}
    },
    live_colors = vbo {
        color = vec4b {255,255,255,255, ....}
    },
    vbo {
        index = {0,1,2,2,3,0,....}
    }
}

It looks clean, expressive, you can bind that object as vao - it hides details about GL's VAO or D3D's vertex declaration, and it allows automatic binding of vertex streams to shader attribs.

You can assing new data as simple as this:


-- alter single semantic
mesh[1].normal = vec3f {... new normals}

-- replace one buffer in vao with completely new data of different format
mesh.live_colors = vbo { colors = vec3f {1.0,1.0,1.0,...} }

Same with shaders. It's much more convenient to assign values to uniforms with "shader_obj.uniform_name = {1,2,3,0}" than bind/ask uniform location then use acquired indices to actually write data.

vec3f/vec4f/vec4b doesn't convert data, it only alters passed table by inserting fields identifying desired data type and vector size, and is actually lua function.

This topic is closed to new replies.

Advertisement