Right now I'm trying to do a very tiny OpenGL in nim. I'm at the stage where I need to bind my buffer data. The compiler is giving me this error:
Error: expression has no address
Here is the C code I'm trying to port:
float points = [
0.0, 0.5, 0.0,
0.5, -0.5, 0.0,
-0.5, -0.5, 0.0
];
// ...
GLuint vbo = 0;
glGenBuffers(1, &vbo);
glBindBuffer(GL_ARRAY_BUFFER, vbo);
glBufferData(GL_ARRAY_BUFFER, 9 * sizeof(float), points, GL_STATIC_DRAW);
And here is my nim code right now:
let
points = [
0.0, 0.5, 0.0,
0.5, -0.5, 0.0,
-0.5, -0.5, 0.0
]
numVertexBuffers = GlSizei(1)
pointsBufferSize = GlSizeiptr(sizeof(points))
# ...
var
vbo: GlUint
glGenBuffers(numVertexBuffers, vbo.addr)
glBindBuffer(GL_ARRAY_BUFFER, vbo)
glBufferData(GL_ARRAY_BUFFER, pointsBufferSize, points.addr, GL_STATIC_DRAW) # It errors here on `points.addr`
Here is the definition for the glBufferData() proc: https://github.com/nimious/gles/blob/master/src/gles2/gl2.nim#L494 I have no idea what's wrong here.
Alright, I figured out my own solution. I had to change that let points to a var points.
Can I get some insight into why I can't call addr on a let'd variable?