1

I downloaded pyOpenGL and when I import it, my program runs just fine. However, a problem occurs when I try to create a shader. Here is my code:

from OpenGL.GL import * 
import OpenGL.GL.shaders
computeShader = OpenGL.GL.glCreateShader(GL_COMPUTE_SHADER)

When I try to run this code, it throws this error: Process finished with exit code 139 (interrupted by signal 11: SIGSEGV)

Does anybody have any idea what is wrong or how I could fix this? Any help would be much appreciated. Thanks.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Matthew
  • 101
  • 2
  • 8

1 Answers1

0

You must create the OpenGL window and Context before you can create the shader. Every OpenGL command needs an OpenGL Context, without a Context it fails. In general, the OpenGL context is created with the OpenGL window. This is a disadvantage of OpenGL (OpenGL is pretty old), you can't create a shader without a window. At least you have to create a hidden window. Use Pygame, glfw or freeglut to create the window. With glfw you can create an initially hidden window, freeglut is contained within the PyOpenGL package.

To create an OpenGL window with Pygame, you need add the OPENGL flag to pygame.display.set_mode. e.g.:

pygame.display.set_mode(size, pygame.DOUBLEBUF| pygame.OPENGL)

However you need to draw everything with OpenGL. See How can I draw using pygame, while also drawing with pyopengl?

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • @Matthew What is your OS? What is the OpenGL Context version? – Rabbid76 May 17 '22 at 10:47
  • my os is mac BigSir version 1.4 and when I type the command `print(OpenGL.contextdata.getContext())` it prints -927276032. This doesn't look like an OpenGL context. Am I using the correct command? – Matthew May 17 '22 at 11:08
  • OpenGL version 4.3 is required for compute shaders. Apple does not support this version for dogmatic reasons. See [Compute shaders on a mac](https://www.reddit.com/r/opengl/comments/9wifho/compute_shaders_on_a_mac/) – Rabbid76 May 17 '22 at 13:28