为什么四边形不渲染?
Why the quads do not render?
我正在使用 PyOpenGL 和 PyQt5 小部件。
在我的 OpenGL 小部件中,我有以下代码:
class Renderizador(QOpenGLWidget):
def __init__(self, parent=None):
super().__init__(parent)
self._x = -0.1
self._y = -0.1
self._z = -0.1
self._rx = 45
self._ry = 45
self._rz = -45
self.vertices_vertical = [[100, 100, 0], [100, -100, 0],
[-100, -100, 0], [-100, 100, 0]]
self.vertices_horizontal = [[100, 0, -100], [100, 0, 100],
[-100, 0, 100], [-100, 0, -100]]
def initializeGL(self):
glClear(GL_COLOR_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-1, 1, 1, -1, -15, 1)
glTranslate(self._x, self._y, self._z)
glRotate(self._rx, 1, 0, 0)
glRotate(self._ry, 0, 1, 0)
glRotate(self._rz, 0, 0, 0)
def paintGL(self):
glClearColor(1, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslate(self._x, self._y, self._z)
glRotate(self._rx, 1, 0, 0)
glRotate(self._ry, 0, 1, 0)
glRotate(self._rz, 0, 0, 1)
# Axis lines
glBegin(GL_LINES)
glColor3d(1, 0, 0)
glVertex3d(0, 0, 0)
glVertex3d(1, 0, 0)
glColor3d(0, 1, 0)
glVertex3d(0, 0, 0)
glVertex3d(0, 1, 0)
glColor3d(0, 0, 1)
glVertex3d(0, 0, 0)
glVertex3d(0, 0, 1)
glEnd()
# Plane drawing, does not work
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR)
glBegin(GL_QUADS)
glColor4fv((0, 1, 0, 0.6))
for vertex in range(4):
glVertex3fv(self.vertices_vertical[vertex])
glColor4fv((1, 0, 0, 0.6))
for vertex in range(4):
glVertex3fv(self.vertices_horizontal[vertex])
glEnd()
glDisable(GL_BLEND)
为什么两个平面没有渲染?我将背景颜色更改为白色,先使用 glClearColor
然后使用 glClear
函数,然后再执行此操作。它起作用了。我能看到轴线,但看不到我画的平面。
由于 Blending.
你不能 "see" 飞机
混合函数(参见glBlendFunc
)
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR)
测量如下(R
红色,G
绿色,B
蓝色,A
alpha,s
源,d
目标) :
R = Rs * As + Rd * Rd
G = Gs * As + Gd * Gd
B = Bs * As + Bd * Bd
A = As * As + Ad * Ad
在您的例子中,源的 Alpha 通道是 0.6,目标颜色是用于清除帧缓冲区的颜色 (1, 1, 1, 1):
R = Rs * 0.6 + 1 * 1
G = Gs * 0.6 + 1 * 1
B = Bs * 0.6 + 1 * 1
A = As * 0.6 + 1 * 1
所以结果颜色无论如何都是白色的,因为每个颜色通道的结果都大于 1。
我正在使用 PyOpenGL 和 PyQt5 小部件。 在我的 OpenGL 小部件中,我有以下代码:
class Renderizador(QOpenGLWidget):
def __init__(self, parent=None):
super().__init__(parent)
self._x = -0.1
self._y = -0.1
self._z = -0.1
self._rx = 45
self._ry = 45
self._rz = -45
self.vertices_vertical = [[100, 100, 0], [100, -100, 0],
[-100, -100, 0], [-100, 100, 0]]
self.vertices_horizontal = [[100, 0, -100], [100, 0, 100],
[-100, 0, 100], [-100, 0, -100]]
def initializeGL(self):
glClear(GL_COLOR_BUFFER_BIT)
glEnable(GL_DEPTH_TEST)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(-1, 1, 1, -1, -15, 1)
glTranslate(self._x, self._y, self._z)
glRotate(self._rx, 1, 0, 0)
glRotate(self._ry, 0, 1, 0)
glRotate(self._rz, 0, 0, 0)
def paintGL(self):
glClearColor(1, 1, 1, 1)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
glTranslate(self._x, self._y, self._z)
glRotate(self._rx, 1, 0, 0)
glRotate(self._ry, 0, 1, 0)
glRotate(self._rz, 0, 0, 1)
# Axis lines
glBegin(GL_LINES)
glColor3d(1, 0, 0)
glVertex3d(0, 0, 0)
glVertex3d(1, 0, 0)
glColor3d(0, 1, 0)
glVertex3d(0, 0, 0)
glVertex3d(0, 1, 0)
glColor3d(0, 0, 1)
glVertex3d(0, 0, 0)
glVertex3d(0, 0, 1)
glEnd()
# Plane drawing, does not work
glEnable(GL_BLEND)
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR)
glBegin(GL_QUADS)
glColor4fv((0, 1, 0, 0.6))
for vertex in range(4):
glVertex3fv(self.vertices_vertical[vertex])
glColor4fv((1, 0, 0, 0.6))
for vertex in range(4):
glVertex3fv(self.vertices_horizontal[vertex])
glEnd()
glDisable(GL_BLEND)
为什么两个平面没有渲染?我将背景颜色更改为白色,先使用 glClearColor
然后使用 glClear
函数,然后再执行此操作。它起作用了。我能看到轴线,但看不到我画的平面。
由于 Blending.
你不能 "see" 飞机混合函数(参见glBlendFunc
)
glBlendFunc(GL_SRC_ALPHA, GL_DST_COLOR)
测量如下(R
红色,G
绿色,B
蓝色,A
alpha,s
源,d
目标) :
R = Rs * As + Rd * Rd
G = Gs * As + Gd * Gd
B = Bs * As + Bd * Bd
A = As * As + Ad * Ad
在您的例子中,源的 Alpha 通道是 0.6,目标颜色是用于清除帧缓冲区的颜色 (1, 1, 1, 1):
R = Rs * 0.6 + 1 * 1
G = Gs * 0.6 + 1 * 1
B = Bs * 0.6 + 1 * 1
A = As * 0.6 + 1 * 1
所以结果颜色无论如何都是白色的,因为每个颜色通道的结果都大于 1。