Thread: [PyOpenGL-Users] First fragment shader - corrected
Brought to you by:
mcfletch
From: Mads I. <mp...@co...> - 2009-10-12 07:56:49
|
Please ignore the first post which had errors. This one is correct OK, so its time to write the first most simple fragment shader ever. But it doesn't work: void main() { gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); } No teapot - just black. Changing to gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); gives red teapot, and vec4(0.0, 1.0, 0.0, 1.0) and vec4(0.0, 0.0, 1.0, 1.0) gives green and blue teapot. But any RGB triplet with values < 1.0 are always truncated to 0.0. For example: vec4(1.0, 0.5, 0.0, 1.0) -> pure red vec4(0.0, 0.5, 0.5, 1.0) -> pure black I have no clue about whats up. Best regards, Mads -- +-------------------------------------------------------------+ | Mads Ipsen, Scientific developer | +-------------------------------+-----------------------------+ | QuantumWise A/S | phone: +45-29716388 | | Nørre Søgade 27A | www: www.quantumwise.com | | DK-1370 Copenhagen K, Denmark | email: mp...@qu... | +-------------------------------+-----------------------------+ |
From: Mads I. <mp...@co...> - 2009-10-16 10:46:07
|
No, I haven't solved this one yet. Here's what I found out: 1. Works in a pure PyOpenGL setting on Ubuntu 8.04 with an ATI card (fglrx). 2. *Fails* in a QGLWidget on Ubuntu 8.04 with an ATI card (fglrx). 3. Works in a pure PyOpenGL setting on Ubuntu 9.04 with an NVidia card. 4. Works in a QGLWidget Ubuntu 8.04 with an ATI card. It's really strange! Anyway I have attached my PyOpenGL version below. If you think I am doing something that potentially could mess things up, please let me know. from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * theta = 0.0 def InitGL(Width, Height): glClearColor(1.0, 1.0, 1.0, 1.0) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45.0, float(Width)/float(Height), 0.1, 100.0) glMatrixMode(GL_MODELVIEW) setShaders() def ReSizeGLScene(w, h): ratio = 1.0 * w / h glMatrixMode(GL_PROJECTION) glLoadIdentity() glViewport(0, 0, w, h); gluPerspective(45,ratio,1,1000) glMatrixMode(GL_MODELVIEW); def DrawGLScene(): global theta glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glLoadIdentity() gluLookAt(0.0, 0.0, 5.0, 0.0, 0.0,-1.0, 0.0, 1.0, 0.0) glRotatef(theta, 0, 1, 1); glColor(0.0, 0.5, 0.5, 1.0) glutSolidTeapot(1) glutSwapBuffers() theta += 0.1 def setShaders(): v = glCreateShader(GL_VERTEX_SHADER) f = glCreateShader(GL_FRAGMENT_SHADER) vs = ['''void main() { gl_Position = ftransform(); }'''] fs = ['''void main() { gl_FragColor = vec4(1.0, 0.5, 0.5, 1.0); }'''] glShaderSource(v, vs) glShaderSource(f, fs) glCompileShader(v) glCompileShader(f) p = glCreateProgram() glAttachShader(p,v) glAttachShader(p,f) glLinkProgram(p) glUseProgram(p) def keyPressed(*args): if args[0] == '\x1b': sys.exit() def main(): glutInit(sys.argv) glutInitDisplayMode(GLUT_RGBA | GLUT_DOUBLE | GLUT_DEPTH) glutInitWindowSize(640, 480) glutInitWindowPosition(0, 0) glutCreateWindow("Shader") glutDisplayFunc(DrawGLScene) glutIdleFunc(DrawGLScene) glutReshapeFunc(ReSizeGLScene) glutKeyboardFunc(keyPressed) InitGL(640, 480) glutMainLoop() # Print message to console, and kick off the main to get it rolling. if __name__ == "__main__": print "Hit ESC key to quit." main() Ben De Luca wrote: > Did you figure it out? your shader looks to be ok, which implies the > issue is out side of your shader some where? > > > What platform are you on? > > > On 12/10/2009, at 8:56 AM, Mads Ipsen wrote: > >> Please ignore the first post which had errors. This one is correct >> >> OK, so its time to write the first most simple fragment shader ever. But >> it doesn't work: >> >> void main() >> { >> gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); >> } >> >> No teapot - just black. Changing to >> >> gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0); >> >> gives red teapot, and vec4(0.0, 1.0, 0.0, 1.0) and vec4(0.0, 0.0, 1.0, >> 1.0) gives green and blue teapot. But any RGB triplet with values < 1.0 >> are always truncated to 0.0. For example: >> >> >> vec4(1.0, 0.5, 0.0, 1.0) -> pure red >> vec4(0.0, 0.5, 0.5, 1.0) -> pure black >> >> I have no clue about whats up. >> >> Best regards, >> >> Mads >> >> -- >> +-------------------------------------------------------------+ >> | Mads Ipsen, Scientific developer | >> +-------------------------------+-----------------------------+ >> | QuantumWise A/S | phone: +45-29716388 | >> | Nørre Søgade 27A | www: www.quantumwise.com | >> | DK-1370 Copenhagen K, Denmark | email: mp...@qu... | >> +-------------------------------+-----------------------------+ >> >> >> >> ------------------------------------------------------------------------------ >> >> Come build with us! The BlackBerry(R) Developer Conference in SF, CA >> is the only developer event you need to attend this year. Jumpstart your >> developing skills, take BlackBerry mobile applications to market and >> stay >> ahead of the curve. Join us from November 9 - 12, 2009. Register now! >> http://p.sf.net/sfu/devconference >> _______________________________________________ >> PyOpenGL Homepage >> http://pyopengl.sourceforge.net >> _______________________________________________ >> PyOpenGL-Users mailing list >> PyO...@li... >> https://lists.sourceforge.net/lists/listinfo/pyopengl-users > -- +-------------------------------------------------------------+ | Mads Ipsen, Scientific developer | +-------------------------------+-----------------------------+ | QuantumWise A/S | phone: +45-29716388 | | Nørre Søgade 27A | www: www.quantumwise.com | | DK-1370 Copenhagen K, Denmark | email: mp...@qu... | +-------------------------------+-----------------------------+ |
From: Mads I. <mp...@co...> - 2009-10-19 06:11:53
|
I keep adding typos. Here's what it should be (sorry): 1. Works in a pure PyOpenGL setting on Ubuntu 8.04 with an ATI card (fglrx). 2. *Fails* in a QGLWidget on Ubuntu 8.04 with an ATI card (fglrx). 3. Works in a pure PyOpenGL setting on Ubuntu 9.04 with an NVidia card. 4. Works in a QGLWidget Ubuntu 9.04 with an NVidia card. -- +-------------------------------------------------------------+ | Mads Ipsen, Scientific developer | +-------------------------------+-----------------------------+ | QuantumWise A/S | phone: +45-29716388 | | Nørre Søgade 27A | www: www.quantumwise.com | | DK-1370 Copenhagen K, Denmark | email: mp...@qu... | +-------------------------------+-----------------------------+ |