Using glGetFloatv to retrieve the modelview matrix in pyglet

前提是你 提交于 2019-12-11 01:05:33

问题


I'm doing 3d visualization in python using pyglet, and need to retrieve the modelview and projection matrices to do some picking. I define my window using:

from pyglet.gl import *
from pyglet.window import *

win = Window(fullscreen=True, visible=True, vsync=True)

I then define all of my window events:

@win.event
def on_draw():
    # All of the drawing happens here

@win.event
def on_mouse_release(x, y, button, modifiers):
    if button == mouse.LEFT:

    # This is where I'm having problems
    a = GLfloat()
    mvm = glGetFloatv(GL_MODELVIEW_MATRIX, a)
    print a.value

When I click, it will print...

1.0
Segmentation fault

and crash. Calling glGetFloatv with GL_MODELVIEW_MATRIX is supposed to return 16 values, and I'm not exactly sure how to handle that. I tried defining a = GLfloat*16 but I get the following error:

ctypes.ArgumentError: argument 2: <type 'exceptions.TypeError'>: expected LP_c_float instance instead of _ctypes.PyCArrayType

How can I retrieve these matrices?


回答1:


You need to pass 16 element float array. To do that use following code:

  a = (GLfloat * 16)()
  mvm = glGetFloatv(GL_MODELVIEW_MATRIX, a)
  print list(a)

Of course, you can access individual elements of "a" by using a[0] syntax.



来源:https://stackoverflow.com/questions/9849374/using-glgetfloatv-to-retrieve-the-modelview-matrix-in-pyglet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!