proc glLightfv(light: GLenum, pname: GLenum, params: ptr GLfloat) {.importc.}
How do I declare the last parameter "params: ptr GLfloat" with 4 float parameters in the Nim for use this procedure? In the Python it was:
In the C it looks like this:
GLfloat sp[4] = {1.45, 1.45, 1.30, 1.00};
glLightfv(GL_LIGHT0, GL_DIFFUSE, sp);
[RESOLVED:] In the Nim:
var
mySet: array[0..3, GLfloat] = [0.5'f32, 0.5'f32, 0.5'f32, 1.0'f32]
param_set: ptr = mySet[0].addr
glLightfv(GL_LIGHT0, GL_DIFFUSE, param_set)
I never generated high-level signatures based on the spec unfortunately. The thing with C is that it conflates pointers with arrays, but the typing is stronger in nim, so in this case you have to create either a array or seq var (var params = [...] and var params = @[...] respectively), and then pass in params[0].addr. params.addr is identical in the case of arrays, but I prefer to do the former just to prevent mistakes.
A var statement is necessary since it's not possible to create a var expression and take the address of that.
import opengl
loadExtensions()
type
ColorChannel = enum
r, g, b, a
var p: array[ColorChannel, GLfloat]
p[r] = 0.3
p[g] = 0.9
p[b] = 0.3
p[a] = 1.0
glLightfv(GL_LIGHT0, GL_DIFFUSE, addr(p[r]))
This compiles, but errors at runtime. I don't know the OpenGL API, but I'm assuming the runtime error is because we don't have an OpenGL context within which to draw?
Error: unhandled exception: OpenGL error: invalid operation [GLerror]
try this i think this will work but i did not try it, i will check for you edit: I tried it and made some adjustments this compiles but i don't know if it works for your program.
var d : ptr = j[0].addr
var c : ptr = p[0].addr
glLightfv(GL_LIGHT0, GL_AMBIENT, d)
glGetLightfv(GL_LIGHT0, GL_AMBIENT, c)
you may just have to wait till someone else with more experience comes along.. i'm still a nimlet :)
but it looks like the first parameter is getting its value maybe change the second and it will work?
try a variation of putting p into glGetLightFv
maybe try
glGetLightfv(GL_LIGHT0, GL_AMBIENT, p[0].addr)
or
glGetLightfv(GL_LIGHT0, GL_AMBIENT, p.addr)
trial and error sometimes works! maybe try
glGetLightfv(GL_LIGHT0, GL_AMBIENT, p)
or
glGetLightfv(GL_LIGHT0, GL_AMBIENT, p[])
just keep trying! var mySet: array[0..3, GLfloat] = [0.5'f32, 0.5'f32, 0.5'f32, 1.0'f32]
glLightfv(GL_LIGHT0, GL_DIFFUSE, mySet[0].addr)
and this [for aesthetes] too:
var
mySet: array[0..3, GLfloat] = [0.5'f32, 0.5'f32, 0.5'f32, 1.0'f32]
param_set: ptr = mySet[0].addr
glLightfv(GL_LIGHT0, GL_DIFFUSE, param_set)
Thank for all!