On running the main script in Pyopengl3.1.5(Python3.8- Windows10Pro/64bit) installed via Pip,the compiler doesn't recognise Glut methods.
After following these stackoverflow answers (1 & 2) ie.reinstalling Pyopengl wheel & putting dll's in main script folder(C:..Python\…\site-packages - PyOpengl's main directory) ,Environment Path,System32 & SysWow64 , the compiler still gives the same error :
import OpenGL.GLUT
glutInit()
NameError: name 'glutInit' is not defined (# checked for casetype )
However, there is a python script named "special.py" located in Site-packages\Opengl\Glut which has the glut methods defined.So on adding the glutinit method's path to init.py (Glut directory)and compiling, the compiler still gives following errors.
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
So the question is - How to get the compiler to recognise the glut methods in special.py and also is there any way to update the .pyc files so as to reflect the updated init.py import path's?
Main Pyopengl Script (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
Either you have to precede the module path to at each function call:
For instance:
glutInit(True)
OpenGL.GLUT.glutInit()
Or you have to change the import
statements, by using the from
clause.
For instance:
from OpenGL import *
from OpenGL.GL import *
from OpenGL.GLUT import *
from OpenGL.GLU import *