Re: [PyOpenGL-Users] help!!
Brought to you by:
mcfletch
From: altern <al...@gm...> - 2007-10-02 14:54:08
|
I think this is correct now (i am not very good at 3D). you were not setting the perspective. you also have to translate in the z axis before drawing to make sure the sphere is with the area rendered. from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * from math import * def display(): global obj1 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) materialColor = [0.1745, 0.0, 0.1, 0.0] #the light scattered off the environment diffuseColor = [0.1, 0.0, 0.6, 0.0] #the light rays coming directly from source specularColor = [0.7, 0.6, 0.8, 0.0] #the light reflected off a shiny surface shininess = 80 glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor) glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor) glMaterialfv(GL_FRONT, GL_SPECULAR,specularColor) glMaterialf(GL_FRONT, GL_SHININESS, shininess) glPushMatrix() ########################## glTranslated(0.0,0.0,-11.0) # translate in the Z axix before drawing ########################## gluSphere(obj1, 3.0, 50, 50) glPopMatrix() glFlush() #glutSwapBuffers() def init(): glClearColor(0, 0, 0, 0) glMatrixMode(GL_PROJECTION) glLoadIdentity() ########################## gluPerspective(45.0, 250/250, 0.1, 10.0) # set perspective ########################## glLightfv(GL_LIGHT0, GL_AMBIENT, [0.0, 0.0, 0.0, 1.0]) glLightfv(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0]) glLightfv(GL_LIGHT0, GL_POSITION, [0.0, 3.0, 3.0, 0.0]) glLightModelfv(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0]) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) if __name__ == "__main__": global obj1 obj1 = gluNewQuadric() glutInit([]) glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) glutInitWindowSize(250, 250) glutCreateWindow('Hello GLUT') #glutSetDisplayFuncCall(display) glutDisplayFunc(display) #gluQuadricDrawStyle(obj1, GLU_FILL) init() glutMainLoop() Eric Germaneau(e)k dio: > PyOpenGL users, > > Does someone can tell me why the following code does not work? > I only get black screen? > Thanks in advance!! > > Eric. > > > *from OpenGL.GL import * > from OpenGL.GLU import * > from OpenGL.GLUT import * > from math import * > > > def display(): > > global obj1 > glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) > > materialColor = [0.1745, 0.0, 0.1, 0.0] #the light scattered off the > environment > diffuseColor = [0.1, 0.0, 0.6, 0.0] #the light rays coming directly > from source > specularColor = [0.7, 0.6, 0.8, 0.0] #the light reflected off a shiny > surface > shininess = 80 > > glMaterialfv(GL_FRONT, GL_AMBIENT, materialColor) > glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuseColor) > glMaterialfv(GL_FRONT, GL_SPECULAR,specularColor) > glMaterialf(GL_FRONT, GL_SHININESS, shininess) > > glPushMatrix() > glTranslated(0.0,0.0,0.0) > gluSphere(obj1, 3.0, 50, 50) > glPopMatrix() > > glFlush() > #glutSwapBuffers() > > > def init(): > glClearColor(0, 0, 0, 0) > glMatrixMode(GL_PROJECTION) > glLoadIdentity() > glLightfv(GL_LIGHT0, GL_AMBIENT, > [0.0, 0.0, 0.0, 1.0]) > glLightfv(GL_LIGHT0, GL_DIFFUSE, > [1.0, 1.0, 1.0, 1.0]) > glLightfv(GL_LIGHT0, GL_POSITION, > [0.0, 3.0, 3.0, 0.0]) > glLightModelfv(GL_LIGHT_MODEL_AMBIENT, > [0.2, 0.2, 0.2, 1.0]) > glEnable(GL_LIGHTING) > glEnable(GL_LIGHT0) > > if __name__ == "__main__": > > global obj1 > > obj1 = gluNewQuadric() > > glutInit([]) > glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB) > glutInitWindowSize(250, 250) > glutCreateWindow('Hello GLUT') > #glutSetDisplayFuncCall(display) > glutDisplayFunc(display) > #gluQuadricDrawStyle(obj1, GLU_FILL) > init() > glutMainLoop()* > > > -- > / "Love, Gift from Life, is given naturally." > / > Eric Germaneau <http://lcr.epfl.ch/page37437.html> > Ecole polytechnique fédérale de Lausanne (EPFL) > FSB - IPMC > Laboratoire de Cristallographie(LCr) <http://lcr.epfl.ch> > BSP 518 > CH-1015 Lausanne > Switzerland > eri...@ep... <mailto:eri...@ep...> > /Tel./: +41 (0)21 / 693 06 36 > /Fax./: +41 (0)21 / 693 05 04 > /msn/: ai...@ho... <mailto:ai...@ho...> > /skype/: aihaike > > / Please consider the environment before printing this email - > Considérez svp l'environnement avant d'imprimer cet email / > > > ------------------------------------------------------------------------ > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > ------------------------------------------------------------------------ > > _______________________________________________ > PyOpenGL Homepage > http://pyopengl.sourceforge.net > _______________________________________________ > PyOpenGL-Users mailing list > PyO...@li... > https://lists.sourceforge.net/lists/listinfo/pyopengl-users |