View Full Version : AST macros to generate OpenGL boilerplatie

12-14-2016, 10:01 AM
Hey people, I am currently working on a macro library that I would like to advertise a bit here, when I am allowed to (I hope so, when not pleas let me know). Generally speaking it is a library that tries to be as thin around OpenGL as possible, but in areas, where writing raw OpenGL would be tedious and error prone. Everything that can be determined from the environment should be generated, and the programmer should not be bothered with details like uniform locations, or compiling and linking together shader source files. I realized that I would not be able to do this in c++, so I have chosen another language that is more powerful in terms of AST based macros, but without giving of the static typing or the control of the memory layout. It would be great if I could get some feedback from people who actually do OpenGL programming. It is of course far from being complete, but it is ready to be played around with and receive some feedback.

The idea is to make everything much more locale to where it is needed, and overall make the programmer much more productive. Here is an example of the Hello triangle, and I could get it down to just a few lines. Of course it does not show all the capabilities of my library, but it is a starting point:

import ../fancygl

let (window, context) = defaultSetup()

let vertices = arrayBuffer([vec4f(-1,-1,0,1), vec4f(1,-1,0,1), vec4f(0,1,0,1)])
let colors = arrayBuffer([vec4f( 1, 0,0,1), vec4f(0, 1,0,1), vec4f(0,0,1,1)])

var evt: Event = defaultEvent
var runGame: bool = true

while runGame:
while pollEvent(evt):
if evt.kind == QuitEvent:
runGame = false
if evt.kind == KeyDown and evt.key.keysym.scancode == SDL_SCANCODE_ESCAPE:
runGame = false

primitiveMode = GL_TRIANGLES
numVertices = 3
a_vertex = vertices
a_color = colors
gl_Position = a_vertex;
v_color = a_color;
"out vec4 v_color"
color = v_color;

My project is on here on github (https://github.com/krux02/opengl-sandbox) with more examples.

I would like to read some comments about it, positive as well as negative. I am also very interested in doubts about where this idea to wrap OpenGL might fail. Som fancy graphics effects that could net be implemented with a system like this.