I’m having issues understanding and making to work...
# kotlin-native
n
I’m having issues understanding and making to work OpenGL with Kotlin, I’ve done some progress in last few days, but is so slow, the issue I’m facing is that cannot load textures, followed a lot of different C tutorials and tried to migrate them to Kotlin, but it just doesn’t work, The texture is supposed to show one in front of the other in a rectangle, but seems that is not rendered (I just saw a coloured rectangle instead of the texture), I’ve uploaded an example here https://github.com/norman784/kotlin-native-opengl-tutorial/blob/master/src/5-ATexturedCube/main.kt
g
I don’t know if it can be of any help, but 2 weeks ago I just published a small code using WebGL to do heatmap rendering with kotlin. https://github.com/data2viz/webglheatmap-kotlin/blob/master/src/main/kotlin/WebGLHeatmap.kt
o
OpenGL is not very easy to follow API, so maybe higher level wrapper written in Kotlin style would be nice. We cannot invest in such wrapper ourselves at the moment, but would welcome community contribution.
👍 1
n
I’ve been working on a wrapper myself, and thats why I follow the opengl tutorial, to test with the opengl interop to later on wrap around to be easier to work with. https://github.com/norman784/lwkgl
@gaetan wil check it out your repo, thanks
@olonho found where the issue is (but I’ve not solved yet, https://github.com/norman784/kotlin-native-opengl-tutorial/blob/master/src/5-ATexturedCube/main.kt#L64-L71) basically seems that I’m not passing correctly the last parameter and thats why the texture isn’t rendered, because the colors and texture coords in the shader are 0, can you point me the right direction to fix this? Btw tried to pass the pointer of an IntVar without luck, if I set the last parameter of
glVertexAttribPointer
null it works kinda (but with the vertex coordinates)
n
I already checked and use the same method, but with the last parameter null, in my case I need to pass the last parameter to tell opengl where to look for the color and the uv coordinates, check this
glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
maybe I can reformulate te question and ask how can I translate to kotlin this
(void*)(3 * sizeof(float))
, tried with
cValuesOf(3 * FloatVar.size)
and
val pointer: FloatVar = alloc(); pointer.value = 3 * FloatVar size; glVertexAttribPointer(...., pointer.prt);
o
if using 12 as value of
void*
is what you indeed want, then
12.toLong().toCPointer()
is what you need
n
I get
Copy code
error: type inference failed: Not enough information to infer parameter T in fun <T : CPointed> Long.toCPointer(): CPointer<T>?
Please specify it explicitly.
o
right,
12.toLong().toCPointer<COpaque>()
😘 1
n
thanks, it works like a charm!