Jump to content
  • Advertisement
Sign in to follow this  
Geometrian

OpenGL Simple PyOpenGL Shader

This topic is 3590 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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
>>>

Share this post


Link to post
Share on other sites
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 pygame
from 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)


Share this post


Link to post
Share on other sites
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
>>>

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!