1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
|
If you ever come across a situation where you need to \b\pass data from PyGLM\b\'s data types \b\to another library\b\ that uses \b\external C code\b\, you should be able to accomplish your goal doing the following:
It doesn't matter which kind of PyGLM type you have, but let's pretend you have a \b\4x4 matrix\b\ that you need to \b\pass to PyOpenGL\b\.
\code Python\
# a very important identity matrix
m = glm.mat4()
# a ctypes pointer to m's data
ptr = glm.value_ptr(m)
# size of m's data in bytes (here 4 * 4 * 4 = 64 bytes)
nbytes = glm.sizeof(m)
glBufferData(GL_UNIFORM_BUFFER, nbytes, ptr, GL_STATIC_DRAW)
\code\
This also works for any \b\vector, quaternion or array\b\ type.
You can take a \b\shortcut for arrays\b\ though:
\code Python \
arr = glm.array(glm.mat4(1), glm.mat4(2), glm.mat4(3))
glBufferData(GL_UNIFORM_BUFFER, arr.nbytes, arr.ptr, GL_STATIC_DRAW)
\code\
|