PyOpenGL.x = glGetDoublev(GL_MODELVIEW_MATRIX) 返回内存地址 [英] PyOpenGL. x = glGetDoublev(GL_MODELVIEW_MATRIX) Returns Memory Address

查看:60
本文介绍了PyOpenGL.x = glGetDoublev(GL_MODELVIEW_MATRIX) 返回内存地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将立方体的位置存储在值 x 中,当我尝试 print(x) 而不是打印位置时,它打印

额外信息:

Windows 8.1 64 位Python 3.4.3 32 位PyOpenGL 3.1.1 32 位PyGame 32 位(找不到版本)

我的 PC 上有管理员权限,PyOpenGL 和 PyGame 的安装似乎没问题.谢谢.如果你还有什么想看的,例如我的脚本的完整代码,请问.


编辑:
这个问题不再需要答案,因为我已经从这个开始了.感谢所有试图提供帮助的人,你们都是了不起的人,他们花时间这样做.

解决方案

我真的很喜欢那些提供对新手不友好的答案的人.

Rafael Cardoso 似乎希望您知道如何使用 VBO 等.
(从你的措辞来看,我可以假设你几乎不知道你在做什么)

我对 ctypes 或 OpenGL.arrays 不太熟练,
(我昨晚刚开始尝试从 GLSL 3D 查看器中删除 numpy)
但是根据我的 Python 经验,他说的是您需要执行以下操作:

from OpenGL import GL, 数组x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)handler = arrays.ctypesarrays.CtypesArrayHandler()打印 handler.asArray(x,typecode=None)

我真的帮不上忙,因为我安装了 PyOpenGL 可以识别的 numpy...
所以对我来说,glGetDoublev(GL_MODELVIEW_MATRIX) 返回一个令人厌恶的 numpy.array() 对象,而不是一个 OpenGL.arrays.ctypesarrays.c_double_Array_4_Array_4 对象...

我上面的测试打印如下:

<预><代码>>>>h = arrays.ctypesarrays.CtypesArrayHandler()>>>x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)>>>X数组([[ 0., 0., 0., 0.],[ 0., 0., 0., 0.],[ 0., 0., 0., 0.],[ 0., 0., 0., 0.]])>>>h.asArray( x, ctypes.c_double )数组([[ 0., 0., 0., 0.],[ 0., 0., 0., 0.],[ 0., 0., 0., 0.],[ 0., 0., 0., 0.]])

从外观上看,它不是很有用.

忘了我的虚拟机,它有一个没有 numpy 的 python 安装:)

结果相同:

<预><代码>>>>从 OpenGL 导入 GL,数组>>>h = arrays.ctypesarrays.CtypesArrayHandler()>>>x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)>>>X<OpenGL.arrays.lists.c_double_Array_4_Array_4 对象在 0x015FEE90>>>>h.asArray( x )<OpenGL.arrays.lists.c_double_Array_4_Array_4 对象在 0x015FEE90>


这有效:

<预><代码>>>>[[c for c in r] for r in x][[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]

你甚至不需要重新格式化为 是一个 2D 迭代器.;)

<预><代码>>>>对于 x 中的 r:打印 r<OpenGL.constants.c_double_Array_4 对象在 0x01605CB0><OpenGL.constants.c_double_Array_4 对象在 0x01605D50><OpenGL.constants.c_double_Array_4 对象在 0x01605CB0><OpenGL.constants.c_double_Array_4 对象在 0x01605D50>

另一个例子:

<预><代码>>>>列表(x)[<OpenGL.constants.c_double_Array_4 对象在 0x01605CB0>、<OpenGL.constants.c_double_Array_4 对象在 0x01605D00>、<OpenGL.constants.c_double_Array_4 对象在 0x01605DA0>OpenGL.constants.c_double_Array_4 对象在 0x01605DA0>OpenGL.constants.c_double_Array_4 对象在 0x01605DA0>0x01605DA0>OpenGL.constants.c_double_Array_4 对象

I'm trying to store the location of a cube in the value x and when I try and print(x) instead of printing the location, it prints

<OpenGL.arrays.ctypesarrays.c_double_Array_4_Array_4 object at 0x043E63A0>

Extra Info:

Windows 8.1 64-Bit
Python 3.4.3 32-Bit
PyOpenGL 3.1.1 32-Bit
PyGame 32-Bit (Can't find the version)

I have admin perms on my PC and the install of PyOpenGL and PyGame seemed to go ok. Thanks. If there's anythin else you would like to see e.g. the full code for my script, just ask.


EDIT:
This question is no longer needing an answer as I've moved on from this. Thanks to all who tried to help out, you're all amazing people for giving your time to do so.

解决方案

I really love people who provide answers that aren't noob-friendly.

Rafael Cardoso seems to expect you know how to use VBOs and such.
(from your wording, I can assume you hardly know much about what you're doing)

I'm not too skilled with ctypes or OpenGL.arrays,
(I just got into them last night trying to remove numpy from a GLSL 3D viewer)
but from my python experience, what he's saying is you need to do something like:

from OpenGL import GL, arrays
x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
handler = arrays.ctypesarrays.CtypesArrayHandler()
print handler.asArray(x,typecode=None)

I can't really help because I have cruddy numpy installed which PyOpenGL recognizes...
So for me, glGetDoublev(GL_MODELVIEW_MATRIX) returns a disgusting numpy.array() object rather than an OpenGL.arrays.ctypesarrays.c_double_Array_4_Array_4 object...

my tests with the above prints this:

>>> h = arrays.ctypesarrays.CtypesArrayHandler()
>>> x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
>>> x
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])
>>> h.asArray( x, ctypes.c_double )
array([[ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.]])

From the way it looks, it's not very useful.

EDIT: forgot about my VM, which has a python installation without numpy :)

same result though:

>>> from OpenGL import GL, arrays
>>> h = arrays.ctypesarrays.CtypesArrayHandler()
>>> x = GL.glGetDoublev(GL.GL_MODELVIEW_MATRIX)
>>> x
<OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90>
>>> h.asArray( x )
<OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90>

EDIT2:
this works:

>>> [[ c for c in r] for r in x]
[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]

you really don't even need to reformat as <OpenGL.arrays.lists.c_double_Array_4_Array_4 object at 0x015FEE90> is a 2D iterator. ;)

>>> for r in x: print r

<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>
<OpenGL.constants.c_double_Array_4 object at 0x01605D50>
<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>
<OpenGL.constants.c_double_Array_4 object at 0x01605D50>

another example:

>>> list(x)
[<OpenGL.constants.c_double_Array_4 object at 0x01605CB0>, <OpenGL.constants.c_double_Array_4 object at 0x01605D00>, <OpenGL.constants.c_double_Array_4 object at 0x01605DA0>, <OpenGL.constants.c_double_Array_4 object at 0x01605DF0>]

这篇关于PyOpenGL.x = glGetDoublev(GL_MODELVIEW_MATRIX) 返回内存地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆