[PyOpenGL-Users] glDrawElements problemo
Brought to you by:
mcfletch
From: Robert <ro...@ma...> - 2004-04-15 05:47:14
|
hi, i've looked around the web and at the list for the following problem. i thought a message on the list had solved but after trying out the solution, i still couldn't get it to work. here's my problem: i want to render a simple triangle made of of vertices and indices. i use glEnableClientState(GL_VERTEX_ARRAY), glVertexPointerf( vertices ), glDrawElementsui( surfaces ) but nothing gets drawn. i then wrote a simple loop that would traverse the vertices and surfaces in the order in which i expect (!) glDrawElementsui to work and it works. it draws the simple triangle. below is the code: i'm using PyOpenGl 2.0.0.44 on win32 with Python 2.2 the proposed solution on the mailing list (http://sourceforge.net/mailarchive/message.php?msg_id=4959668) was to disable culling. apparently, the guy was specifying indices in a clockwise manner so he wasn't seeing his polys because they were facing away, but you'll see that mine is CCW. this bit of code will display a window and let you spin, rotate, and zoom the "scene". if you uncomment the lines after glDrawElementsui you'll see the small triangle i'm trying to render on the bottom of the screen. use the right mouse button to spin it up or down. i'm new to OpenGL so i might well have made a dork mistake. if so, i apologize for taking up your time but i'll be thankful for the solution. /r import sys, time, os from Numeric import * from math import * import Image from OpenGL.GL import * from OpenGL.GLE import * from OpenGL.GLUT import * from OpenGL.GLU import * #from lwo2daruma import * class ObjectViewer: def __init__ (self): self.width = 640 self.height = 480 self.mouseX = 0 self.mouseY = 0 self.twistAngle = -45. self.tiltAngle = -70. self.distance = 200. self.LeftMouseButtonDown = False self.RightMouseButtonDown = 0 self.scale = 1. glutInit([]) glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ) glutInitWindowSize(self.width, self.height) glutCreateWindow("Object Viewer") glutDisplayFunc(self.OnDisplay) glutMotionFunc(self.OnMotion) glutIdleFunc(self.OnIdle) glutReshapeFunc(self.OnReshape) glutMotionFunc(self.OnMotion) glutMouseFunc(self.OnMouseFunc) glutPassiveMotionFunc(self.OnMotion) glutMainLoop() def OnMouseFunc(self, button, state, x, y): y = self.height - y - 1 if button == GLUT_LEFT_BUTTON: self.LeftMouseButtonDown = state == GLUT_DOWN if button == GLUT_RIGHT_BUTTON: self.RightMouseButtonDown = state == GLUT_DOWN self.mouseX = x self.mouseY = y def OnMotion(self, x, y): y = self.height - y - 1 # if mouseButtonDown: if self.LeftMouseButtonDown: self.twistAngle += x - self.mouseX self.tiltAngle -= y - self.mouseY # if right mouse button down if self.RightMouseButtonDown: self.distance -= (y-self.mouseY)/3. if self.distance < 0.: self.distance = 0. self.mouseX = x self.mouseY = y def OnReshape (self, width, height): glViewport(0,0,width,height) self.width = width self.height = height def OnIdle (self): glutPostRedisplay() def OnDisplay (self): glClearColor(0., 0., .3, 0.) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glMatrixMode(GL_PROJECTION) glLoadIdentity() gluPerspective(45., self.width / self.height, self.scale*50., self.scale*1000.) glMatrixMode(GL_MODELVIEW) glLoadIdentity() # translate viewpoint glTranslatef(0., 0., -self.distance * self.scale) glRotatef(self.tiltAngle, 1., 0., 0.) glRotatef(self.twistAngle, 0., 0., 1.) glTranslatef(0., 0., -90. * self.scale) self.renderObjects() glutSwapBuffers() def renderObjects (self): #glDisable(GL_LIGHTING) #glDisable(GL_CULL_FACE) glEnable(GL_DEPTH_TEST) glShadeModel(GL_SMOOTH) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) # test with wireframe glPolygonMode(GL_FRONT_AND_BACK, GL_LINE) vertices = array([ [0.,0.,0.], [10.,0.,0.], [0.,10.,0.] ], 'f') surfaces = array( [ 0, 1, 2 ], 'i') glColor4f(1., 1., 1., 1.) glVertexPointerf(vertices) glEnableClientState(GL_VERTEX_ARRAY) glDrawElementsui(GL_TRIANGLES, surfaces) # this works =( # comment out """ below and you'll see the triangle down towards the bottom # of the screen """ glBegin(GL_TRIANGLES) for i in range(len(surfaces)/3): for j in range(3): glVertex3f( vertices[surfaces[i*3+j]][0], vertices[surfaces[i*3+j]][1], vertices[surfaces[i*3+j]][2]) glEnd() #""" glDisableClientState(GL_VERTEX_ARRAY) glDisable(GL_LIGHTING) glDisable(GL_LIGHT0) glDisable(GL_DEPTH_TEST) if __name__ == '__main__': ObjectViewer() |