Simple PyOpenGL Shader

Started by
4 comments, last by Geometrian 15 years, 7 months ago
Hi, I'm looking for a very simple shader tutorial in PyOpenGL (not PyGlet) that works. I found some tutorials online, but they didn't work. This one, for example, which looks good: http://www.pygame.org/wiki/GLSLExample?parent=CookBook doesn't run--it crashes at 'glCreateShader = gl.glCreateShader' with 'AttributeError: function 'glCreateShader' not found'. I kept at it, but eventually ran into problems with glShaderSource(), which doesn't like anything I feed it. That PyOpenGL tutorial is outdated by nearly two years--I need some working examples. Thanks, Ian

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
The sample works just fine for me (under linux). The problem must be somewhere else. Are you sure your gpu supports glsl? Have you tried installing the latest driver?
glCreateShader is available only if the GL version is 2.0 or greater.
You can get the GL version using glGetString(GL_VERSION).

[Edited by - Kambiz on September 20, 2008 1:28:41 AM]
Quote:The sample works just fine for me (under linux). The problem must be somewhere else. Are you sure your gpu supports glsl?
No, but I bought my computer after that demo was made and it was middle-end tech-wise.
Quote:Have you tried installing the latest driver?
I tried and I think I have it, but it still doesn't work.
Quote:glCreateShader is available only if the GL version is 2.0 or greater.
You can get the GL version using glGetString(GL_VERSION).
>>> from OpenGL.GL import *
>>> print glGetString(GL_VERSION)
None
>>>

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Hey, is there a way to do this without GLSL?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Quote:Original post by Geometrian
>>> from OpenGL.GL import *
>>> print glGetString(GL_VERSION)
None
>>>


Most of the opengl functions including glGetString(GL_VERSION) work only after opengl context creation. This means you have to call it after pygame.display.set_mode(...).
import pygamefrom pygame.locals import * from OpenGL.GL import *from OpenGL.GLUT import * if __name__ == '__main__':    glutInit(sys.argv)    width, height = 640, 480    pygame.init()    pygame.display.set_mode((width, height), OPENGL | DOUBLEBUF)    print glGetString(GL_VERSION)
Ah, thank you.
>>> import pygame
>>> from pygame.locals import *
>>> from OpenGL.GL import *
>>> from OpenGL.GLUT import *
>>> glutInit()
['foo']
>>> width, height = 640, 480
>>> pygame.init()
(6, 0)
>>> pygame.display.set_mode((width, height), OPENGL | DOUBLEBUF)
<Surface(640x480x32 SW)>
>>> print glGetString(GL_VERSION)
2.1.0
>>>

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

This topic is closed to new replies.

Advertisement