utikeev
02/22/2021, 11:01 PMcglm
library (https://github.com/recp/cglm) for supporting OpenGL maths. Though, I have some problems with it. Details in 🧵.utikeev
02/22/2021, 11:01 PMfun foo() {
val fdata = floatArrayOf(
1f, 2f, 4f,
2f, 5f, 3f,
1f, 1f, 1f,
)
fdata.usePinned {
glm_mat3_inv(it.addressOf(0), it.addressOf(0))
}
println(fdata.joinToString())
}
-----
-0.25 -0.25 1.75 -0.125 0.375 -0.625 0.375 -0.125 -0.125
Though, I have some weird behavoiur regarding defined constants:
fun bar() {
val x = GLM_YUP
x?.let {
println("${x[0]} ${x[1]} ${x[2]}")
}
}
-----
0.0 1.1750706E-38 0.0
-----
where
typedef float vec3[3];
#define GLM_YUP ((vec3){0.0f, 1.0f, 0.0f})
GLM_YUP
type is CPointer<FloatVar>
, so I thought it was the right way to dereference it, but apparently not. What's the right way to get values from it?Dominaezzz
02/22/2021, 11:45 PMutikeev
02/22/2021, 11:51 PMval cmakeGlm by tasks.creating(Exec::class) {
dependsOn(unzipGlm)
environment("PATH", "${mingwPath.resolve("bin").absolutePath};${System.getenv("PATH")}")
glmBuildDir.mkdir()
workingDir = glmBuildDir
executable(cmakePath.resolve("cmake"))
args("..", "-DCGLM_STATIC=ON", "-G", "\"MinGW Makefiles\"")
}
val makeGlm by tasks.creating(Exec::class) {
dependsOn(cmakeGlm)
workingDir = glmBuildDir
executable(mingwPath.resolve("bin/mingw32-make"))
}
CInterop:
val glm by creating {
tasks[interopProcessingTaskName].dependsOn(makeGlm)
includeDirs(glmDir.resolve("include/cglm"))
}
----
glm.def
package = glm
headers = cglm.h struct.h call.h
staticLibraries = libcglm.a
libraryPaths = build/downloads/cglm-0.7.9/build
compilerOpts = -DCGLM_USE_ANONYMOUS_STRUCT -DCGLM_STATIC
Also, I don't get some of the defines. For example: include/cglm/sturct/vec2.h
contains #define GLMS_VEC2_ONE_INIT {GLM_VEC2_ONE_INIT}
which doesn't end up in klib symbols.utikeev
02/23/2021, 1:05 PMfun zar() {
memScoped {
val projection: mat3 = allocArrayOf(
1f, 2f, 4f,
2f, 5f, 3f,
1f, 1f, 1f
)
glm_mat3_inv(projection, projection)
for (i in 0 until 9) {
print(projection[i])
print(' ')
}
}
}
-----
-0.25 -0.25 1.75 -0.125 0.375 -0.625 0.375 -0.125 -0.125
And this doesn't:
fun zar() {
memScoped {
val view: mat4 = allocArray(16)
glm_mat4_identity(view)
for (i in 0 until 16) {
print(view[i])
print(' ')
}
}
}
-----
Execution failed for task ':sandbox:runDebugExecutableNative'.
> Process 'command 'C:\_Code\opengl-kotlin\sandbox\build\bin\native\debugExecutable\sandbox.exe'' finished with non-zero exit value -1073741819