0

I'm following this guide for my program activity

I installed pip install PyOpenGL PyOpenGL_accelerate , all good.

I tested the installation through the test code:

import OpenGL.GL import OpenGL.GLUT import OpenGL.GLU print("Imports successful!") # If you see this printed to the console then installation was successful

all good

I now run this script:

   import OpenGL

   import OpenGL.GL
   import OpenGL.GLUT
   import OpenGL.GLU
   print("Imports successful!") # If you see this printed to the console then installation was successful

   def showScreen():
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)

   glutInit() # Initialize a glut instance which will allow us to customize our window
   glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
   glutInitWindowSize(500, 500)   # Set the width and height of your window
   glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
   wind = glutCreateWindow("OpenGL Coding Practice") # Give your window a title
   glutDisplayFunc(showScreen)  # Tell OpenGL to call the showScreen method continuously
   glutIdleFunc(showScreen)     # Draw any graphics or shapes in the showScreen function at all times
   glutMainLoop()  # Keeps the window created above displaying/running in a loop

I get This in my terminal:

    Python 3.7.9 (tags/v3.7.9:13c94747c7, Aug 17 2020, 16:30:00) [MSC v.1900 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import OpenGL
    >>> import OpenGL.GL
    >>> import OpenGL.GLUT
    >>> import OpenGL.GLU
    >>> print("Imports successful!") # If you see this printed to the console then installation was successful
    Imports successful!
    >>> def showScreen():
    ...     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) # Remove everything from screen (i.e. displays all white)
    ...
    >>> glutInit() # Initialize a glut instance which will allow us to customize our window
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutInit' is not defined
    >>> glutInitDisplayMode(GLUT_RGBA) # Set the display mode to be colored
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutInitDisplayMode' is not defined
    >>> glutInitWindowSize(500, 500)   # Set the width and height of your window
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutInitWindowSize' is not defined
    >>> glutInitWindowPosition(0, 0)   # Set the position at which this windows should appear
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutInitWindowPosition' is not defined
    >>> wind = glutCreateWindow("OpenGL Coding Practice") # Give your window a title
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutCreateWindow' is not defined
    >>> glutDisplayFunc(showScreen)  # Tell OpenGL to call the showScreen method continuously
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutDisplayFunc' is not defined
    >>> glutIdleFunc(showScreen)     # Draw any graphics or shapes in the showScreen function at all times
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutIdleFunc' is not defined
    >>> glutMainLoop()  # Keeps the window created above displaying/running in a loop
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    NameError: name 'glutMainLoop' is not defined

I am using Visual Studio Code as my compiler

I followed the answer for this similar question but it led me to this error:

    pip install PyOpenGL-3.1.5-cp39-cp39-win_amd64.whl
    WARNING: Requirement 'PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl' looks like a filename, but the file does not exist
    ERROR: PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl is not a valid wheel filename.

I have downloaded the stated .whl file

  • There is nothing wrong with your code. You have to reinstall PyOpenGL. Repeating the question does not change this. This question is duplicate. See [PyOpenGL :: OpenGL.error.NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling](https://stackoverflow.com/questions/65699670/pyopengl-opengl-error-nullfunctionerror-attempt-to-call-an-undefined-functio/65699812#65699812). Please believe me. I had exactly the same problem. If I answered your question, I would copy the answer from the "duplicate" question. – Rabbid76 Apr 11 '21 at 07:21
  • I followed the answer and led me to this error: WARNING: Requirement 'PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl' looks like a filename, but the file does not exist ERROR: PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl is not a valid wheel filename. – Phylle Contreras Apr 11 '21 at 07:34
  • You have to download the file from [Unofficial Windows Binaries for Python Extension Packages](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pyopengl). (as explained in the answer) – Rabbid76 Apr 11 '21 at 07:36
  • I have downloaded the file, but still provides the error. I am also not sure where to put the file. – Phylle Contreras Apr 11 '21 at 07:41
  • Just execute the command "pip install PyOpenGL‑3.1.5‑cp39‑cp39‑win_amd64.whl" in the directory where put the file (use cmd.exe or powershell). Sadly freeglut is missing in the official Windows PyOpenGL package. So you have to install it manually. Anyway, I recommend to use glfw instead of glut. – Rabbid76 Apr 11 '21 at 07:46
  • Same error still appears. I still dont know what I am doing wrong, the error states that the file does not exist but I have already downloaded it – Phylle Contreras Apr 11 '21 at 07:54

0 Answers0