简体   繁体   English

如何绘制单个 3D 点?

[英]How can I draw single 3D points?

I am using Python 3 with PyOpenGL and I need to draw single points in space.我在 PyOpenGL 中使用 Python 3,我需要在空间中绘制单个点。 I know a point does not have volume, but I do not know if there is an easy way of drawing a point/sphere at certain coordinates.我知道一个点没有体积,但我不知道是否有一种简单的方法可以在某些坐标处绘制一个点/球体。 Edit: I am using opengl inside of pygame and inside a tkinter gui编辑:我在 pygame 和 tkinter gui 中使用 opengl

I have tried the following code:我尝试了以下代码:

glEnable(GL_POINT_SMOOTH)
glBegin(GL_POINTS)
glColor3d(1, 1, 1)
glPointSize(200)
glVertex3d(1, 1, 1)
glEnd() # This throws an error

Error:错误:

Exception in Tkinter callback
Traceback (most recent call last):
  File "C:\Program Files (x86)\Python37-32\lib\tkinter\__init__.py", line 1702, in __call__
    return self.func(*args)
  File "C:/Users/reas/Desktop/Programación/Dibujo/Dibujo.py", line 65, in vista_alzado
    glEnd()
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\latebind.py", line 61, in __call__
    return self.wrapperFunction( self.baseFunction, *args, **named )
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\GL\exceptional.py", line 45, in glEnd
    return baseFunction( )
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\platform\baseplatform.py", line 409, in __call__
    return self( *args, **named )
  File "C:\Program Files (x86)\Python37-32\lib\site-packages\OpenGL\error.py", line 232, in glCheckError
    baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
    err = 1282,
    description = b'operaci\xf3n no v\xe1lida',
    baseOperation = glEnd,
    cArguments = ()
)

The error is caused because glPointSize() is call with in a glBegin / glEnd sequence.该错误是由于glPointSize()glBegin / glEnd序列中被调用而引起的。 This is not allowed.这是不允许的。
You've to call glPointSize before glBegin , eg:你必须在glBegin之前调用glPointSize ,例如:

glEnable(GL_POINT_SMOOTH)
glPointSize(5)

glBegin(GL_POINTS)
glColor3d(1, 1, 1)
glVertex3d(0, 0, 0)
glEnd()

Once drawing of primitives was started by glBegin it is only allowed to specify vertex coordinates ( glVertex ) and change attributes (eg glColor , glTexCoord ...), till the drawn is ended ( glEnd ).一旦glBegin开始绘制图元,它只允许指定顶点坐标( glVertex )和更改属性(例如glColorglTexCoord ...),直到绘制结束( glEnd )。
All other instruction will be ignored and cause a GL_INVALID_OPERATION error (error code 1282).所有其他指令将被忽略并导致GL_INVALID_OPERATION错误(错误代码 1282)。


Note, if the model view matrix and the projection matrix is the identity matrix, then the coordinate (1, 1, 1) is the top, right (far) point of the viewport.注意,如果模型视图矩阵和投影矩阵是单位矩阵,则坐标 (1, 1, 1) 是视口的顶部、右侧(远)点。
The coordinate (0, 0, 0) would be in the center of the view (volume).坐标 (0, 0, 0) 将位于视图(体积)的中心。

Whereas if a perspective projection is used,而如果使用透视投影,

gluPerspective(40, display[0]/display[1], 0.1, 50)

then the z coordinate of the point has to be less than -near (near plane is 0.1 in the example) and grater than -far (far plane is 50) else the point is clipped by the near plane or far plane of the view frustum.那么该点的 z 坐标必须小于-near (在示例中近平面为 0.1)并且大于-far (远平面为 50),否则该点被视锥体的近平面或远平面裁剪. Note the view space z-axis points out of the viewport.注意视图空间 z 轴指向视口外。 eg例如

glVertex3d(0, 0, -1)

See also Immediate mode and legacy OpenGL另请参阅立即模式和旧版 OpenGL

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM