Методы перенасыщения, не распознаваемые даже с помощью DLL (Pyopengl3 / Python3 .8 / Windows10 -64) - PullRequest
1 голос
/ 25 апреля 2020

При запуске основного скрипта в Pyopengl3.1.5 (Python3 .8 - Windows10Pro / 64bit) , установленного через Pip , компилятор не распознает методы Glut.

После выполнения этих ответов stackoverflow ( 1 & 2 ) ie .reinstall Колесо Пиопенгля и установка dll's в основной папке сценариев (C: .. Python \… \ site-packages - основной каталог PyOpengl), в среде Path, System32 и SysWow64 компилятор по-прежнему выдает ту же ошибку:

import OpenGL.GLUT  
glutInit()
NameError: name 'glutInit' is not defined (# checked for casetype )

Тем не менее, существует сценарий python с именем «special.py», расположенный в Site-packages \ Opengl \ Glut, в котором определены методы glut. Для добавления пути метода glutinit к init .py (каталог Glut) и компиляция, компилятор по-прежнему выдает следующие ошибки.

OpenGL\GLUT\special.py:- def glutInit(INITIALIZED = False)   

OpenGL\GLUT\init.py:- from OpenGL.GLUT.special import *
                      from OpenGL.GLUT.special import glutInit (#added)  


OpenGL\GLUT\main.py:- import OpenGL.GLUT
                      import OpenGL.GLUT.special(#added) 
                      import OpenGL.GLUT.special.glutInit (#added)   

                      glutInit(INITIALIZED = True)  (# function call)

                      ModuleNotFoundError: No module named 'OpenGL.GLUT.special.glutInit'; 'OpenGL.GLUT.special' is not a package  

Итак, вопрос в том, как заставить компилятор распознавать методы перенасыщения в special.py , а также есть Любой способ обновить .py c файлы , чтобы отразить обновленные пути импорта init.py?

Основной скрипт Pyopengl (stackabuse.com)

import OpenGL
import OpenGL.GL
import OpenGL.GLUT
import OpenGL.GLUT.special #(added)
import OpenGL.GLUT.special.glutInit #(added)
import OpenGL.GLU
print("Imports successful!")

w, h = 500,500

# define square 
def square():
    # We have to declare the points in this sequence: bottom left, bottom right, top right, top left
glBegin(GL_QUADS) # Begin the sketch
glVertex2f(100, 100) # Coordinates for the bottom left point
glVertex2f(200, 100) # Coordinates for the bottom right point
glVertex2f(200, 200) # Coordinates for the top right point
glVertex2f(100, 200) # Coordinates for the top left point
glEnd() # Mark the end of drawing


# draw square
def showScreen():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    glLoadIdentity() # Reset all graphic/shape's position
    square() # Draw a square using our function
    glutSwapBuffers()

# Initialise and create Opengl screen
glutInit(True)
glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
glutInitWindowSize(500, 500)   # Set the w and h of your window
glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
wind = glutCreateWindow("OpenGL Coding Practice") # Set a window title
glutDisplayFunc(showScreen)
glutIdleFunc(showScreen) # Keeps the window open
glutMainLoop()  # Keeps the above created window displaying/running in a loop

1 Ответ

0 голосов
/ 25 апреля 2020

Либо вы должны предшествовать пути к модулю при каждом вызове функции:

Например:

glutInit(True)

OpenGL.GLUT.glutInit()

Или вы должны изменить операторы import , используя предложение from.

Например:

from OpenGL import *
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *
...