RafaVieira Postado Abril 5, 2020 Denunciar Share Postado Abril 5, 2020 Esse código deveria mostrar uma janela e desenhar um triângulo. import sys from PyQt5 import QtOpenGL from PyQt5.QtWidgets import * from OpenGL.GL import * class MyCanvas(QtOpenGL.QGLWidget): def __init__(self): super(MyCanvas, self).__init__() self.setGeometry(100, 100, 600, 400) self.setWindowTitle('MyGLDrawer') self.m_w = 0 self.m_h = 0 def initializeGL(self): glClearColor(1.0, 1.0, 1.0, 1.0) glClear(GL_COLOR_BUFFER_BIT) def resizeGL(self, _width, _height): self.m_w = _width self.m_h = _height glViewport(0, 0, self.m_w, self.m_h) glMatrixMode(GL_PROJECTION) glLoadIdentity() glOrtho(0.0, self.m_w, 0.0, self.m_h, -1.0, 1.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() def paintGL(self): glClear(GL_COLOR_BUFFER_BIT) xA = self.m_w / 3.0 yA = self.m_h / 3.0 xB = self.m_w * (2.0 / 3.0) yB = self.m_h / 3.0 xC = self.m_w / 2.0 yC = self.m_h * (2.0 / 3.0) glShadeModel(GL_SMOOTH) glBegin(GL_TRIANGLES) glColor3f(1.0, 0.0, 0.0) # red glVertex2f(xA, yA) glColor3f(0.0, 1.0, 0.0) # green glVertex2f(xB, yB) glColor3f(0.0, 0.0, 1.0) # blue glVertex2f(xC, yc) glEnd() if __name__ == '__main__': app = QApplication(sys.argv) widget = MyCanvas() widget.show() sys.exit(app.exec_()) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Executando esse código está aparecendo o seguinte erro: File "C:\Users\BuscapÚ\PycharmProjects\Rafael_Vieira\main3.py", line 19, in initializeGL glClearColor(1.0, 1.0, 1.0, 1.0) File "C:\Users\BuscapÚ\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__ return self( *args, **named ) File "C:\Users\BuscapÚ\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenGL\error.py", line 234, in glCheckError baseOperation = baseOperation, OpenGL.error.GLError: GLError( err = 1282, description = b'opera\xe7\xe3o inv\xe1lida', baseOperation = glClearColor, cArguments = (1.0, 1.0, 1.0, 1.0) ) Alguém tem ideia do que pode ser? Citar Link para o comentário Compartilhar em outros sites More sharing options...
Pergunta
RafaVieira
Esse código deveria mostrar uma janela e desenhar um triângulo.
import sys
from PyQt5 import QtOpenGL
from PyQt5.QtWidgets import *
from OpenGL.GL import *
class MyCanvas(QtOpenGL.QGLWidget):
def __init__(self):
super(MyCanvas, self).__init__()
self.setGeometry(100, 100, 600, 400)
self.setWindowTitle('MyGLDrawer')
self.m_w = 0
self.m_h = 0
def initializeGL(self):
glClearColor(1.0, 1.0, 1.0, 1.0)
glClear(GL_COLOR_BUFFER_BIT)
def resizeGL(self, _width, _height):
self.m_w = _width
self.m_h = _height
glViewport(0, 0, self.m_w, self.m_h)
glMatrixMode(GL_PROJECTION)
glLoadIdentity()
glOrtho(0.0, self.m_w, 0.0, self.m_h, -1.0, 1.0)
glMatrixMode(GL_MODELVIEW)
glLoadIdentity()
def paintGL(self):
glClear(GL_COLOR_BUFFER_BIT)
xA = self.m_w / 3.0
yA = self.m_h / 3.0
xB = self.m_w * (2.0 / 3.0)
yB = self.m_h / 3.0
xC = self.m_w / 2.0
yC = self.m_h * (2.0 / 3.0)
glShadeModel(GL_SMOOTH)
glBegin(GL_TRIANGLES)
glColor3f(1.0, 0.0, 0.0) # red
glVertex2f(xA, yA)
glColor3f(0.0, 1.0, 0.0) # green
glVertex2f(xB, yB)
glColor3f(0.0, 0.0, 1.0) # blue
glVertex2f(xC, yc)
glEnd()
if __name__ == '__main__':
app = QApplication(sys.argv)
widget = MyCanvas()
widget.show()
sys.exit(app.exec_())
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Executando esse código está aparecendo o seguinte erro:
File "C:\Users\BuscapÚ\PycharmProjects\Rafael_Vieira\main3.py", line 19, in initializeGL
glClearColor(1.0, 1.0, 1.0, 1.0)
File "C:\Users\BuscapÚ\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__
return self( *args, **named )
File "C:\Users\BuscapÚ\AppData\Local\Programs\Python\Python36\lib\site-packages\OpenGL\error.py", line 234, in glCheckError
baseOperation = baseOperation,
OpenGL.error.GLError: GLError(
err = 1282,
description = b'opera\xe7\xe3o inv\xe1lida',
baseOperation = glClearColor,
cArguments = (1.0, 1.0, 1.0, 1.0)
)
Alguém tem ideia do que pode ser?
Link para o comentário
Compartilhar em outros sites
0 respostass a esta questão
Posts Recomendados
Participe da discussão
Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.