Jump to content
Fórum Script Brasil
  • 0

Erro em interface gráfica com Pyqt5 e OpenGL


Question

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 to post
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      148900
    • Total Posts
      644981
×
×
  • Create New...