[PyOpenGL-Users] PyOpenGL Problem
Brought to you by:
mcfletch
From: <sh...@lo...> - 2007-10-22 23:26:33
|
Hello, I'm having trouble with a PyOpenGL application that I'm trying to run. I'm hoping it's a configuration error. Here is the error I get: ============================================ (python:3903): Gdk-WARNING **: gdkdrawable-x11.c:878 drawable is not a pixmap or window (python:3903): Gdk-WARNING **: gdkdrawable-x11.c:878 drawable is not a pixmap or window The program 'python' received an X Window System error. This probably reflects a bug in the program. The error was 'GLXBadDrawable'. (Details: serial 286 error_code 156 request_code 143 minor_code 11) (Note to programmers: normally, X errors are reported asynchronously; that is, you will receive the error a while after causing it. To debug your program, run it with the --sync command line option to change this behavior. You can then get a meaningful backtrace from your debugger if you break on the gdk_x_error() function.) ============================================== When I instantiate the an object of type Gallery (the class definition is shown below), I get this error. The same code runs fine on another Linux computer, and I have another program on this system that creates a similar class (a child of glcanvas.GLCanvas) and works fine, and I absolutely cannot figure out the difference between the two. Does anyone have any ideas for me? Thank you very much in advance - I have been tearing out my hair trying to solve this problem. Shari Here is the class that seems to cause the problem: =============================================== import wx from wx import glcanvas import Image from OpenGL.GL import * from OpenGL.GLUT import * from OpenGL.GLU import * class myGLCanvas(glcanvas.GLCanvas): def __init__(self, parent): glcanvas.GLCanvas.__init__(self, parent, -1) self.init = False # initial mouse position self.lastx = self.x = 30 self.lasty = self.y = 30 self.Bind(wx.EVT_ERASE_BACKGROUND, self.OnEraseBackground) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_PAINT, self.OnPaint) self.Bind(wx.EVT_LEFT_DOWN, self.OnMouseDown) self.Bind(wx.EVT_LEFT_UP, self.OnMouseUp) self.Bind(wx.EVT_MOTION, self.OnMouseMotion) self.InitGL() def OnEraseBackground(self, event): pass # Do nothing, to avoid flashing on MSW. def OnSize(self, event): self.SetCurrent() size = self.GetClientSize() if self.GetContext(): self.SetCurrent() if (True): if (size.height == 0): size.height = 1 # prevent divide by 0 glViewport(0, 0, size.width, size.height) glMatrixMode(GL_PROJECTION) glLoadIdentity() # Calculate the aspect ratio of the window gluPerspective(80.0, float(size.width) / float(size.height), 1.0, 50.0) glMatrixMode(GL_MODELVIEW) glLoadIdentity() self.OnDraw() event.Skip() def OnPaint(self, event): dc = wx.PaintDC(self) self.SetCurrent() if not self.init: self.InitGL() self.init = True self.OnDraw() def OnMouseDown(self, evt): self.CaptureMouse() def OnMouseUp(self, evt): self.ReleaseMouse() def OnMouseMotion(self, evt): if evt.Dragging() and evt.LeftIsDown(): self.x, self.y = self.lastx, self.lasty self.x, self.y = evt.GetPosition() self.Refresh(False) class Gallery(myGLCanvas): SIZE_X = 1.0 SIZE_Y = 1.0 DIST_X = 0.5 DIST_Z = 1.0 BOTTOM_Y = -0.5 # TODO: Change this after I get it working xMapSize = 1 yMapSize = 2 def InitGL(self): print "In InitGL" self.SetCurrent() glClearColor(0.7, 0.7, 0.7, 0.0) glShadeModel(GL_FLAT) glutInitDisplayMode(GLUT_DEPTH) glEnable(GL_ALPHA_TEST) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) glMatrixMode(GL_MODELVIEW) # Following commands affect model glLoadIdentity() # Generate a set of textures to use self.vizImageIds = glGenTextures(self.xMapSize * self.yMapSize + 1) self.billboardList = 0 self.CreateDisplayList() self.OnDraw() def OnDraw(self): self.SetCurrent() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glCallList(self.billboardList) glFlush() glLoadIdentity() # gluLookAt( 1.0, 0.0, -0.5, # camera position # 1.0, 0.0, 1.0, # camera aimed at # 0.0, 1.0, 0.0) # view-up matrix self.SwapBuffers() def DrawBillboard(self, x, z, filename, textureCount): self.textureId = self.LoadImage(filename, textureCount) self.SetupTexture(textureCount) glBindTexture(GL_TEXTURE_2D, self.vizImageIds[textureCount]) # Added 20061003 glBegin(GL_QUADS) leftX = x * (self.SIZE_X + self.DIST_X) rightX = leftX + self.SIZE_X bottomY = self.BOTTOM_Y topY = bottomY + self.SIZE_Y zVal = z * self.DIST_Z + 1.0 print "zVal = ", zVal glNormal3f(0.0, 0.0, 1.0) glTexCoord2f(1.0, 1.0); glVertex3f(rightX, topY, zVal) glTexCoord2f(0.0, 1.0); glVertex3f(leftX, topY, zVal) glTexCoord2f(0.0, 0.0); glVertex3f(leftX, bottomY, zVal) glTexCoord2f(1.0, 0.0); glVertex3f(rightX, bottomY, zVal) glEnd() def LoadImage(self, filename, id): # First, load bitmap if filename == None: return None textureImageFile = None textureImageFile = open(filename, 'r') if textureImageFile: textureImageFile.close() im = Image.open(filename) try: ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBA", 0, -1) except SystemError: ix, iy, image = im.size[0], im.size[1], im.tostring("raw", "RGBX", 0, -1) glPixelStorei(GL_UNPACK_ALIGNMENT, 1) glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image) return self.vizImageIds[id] def SetupTexture(self, textureId): glEnable(GL_TEXTURE_2D) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT) glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST) glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL) def CreateDisplayList(self): self.billboardList = glGenLists(1) glNewList(self.billboardList, GL_COMPILE) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); # Draw a matrix of billboards textureCount = 0 for x in range(0, self.xMapSize): for z in range(0, self.yMapSize): #textureFilename = self.myVizEngine.getViz([x, z]) textureFilename = "/home/shari/thesisFiles/TestFileName.bmp" textureCount = 0 self.DrawBillboard(x, z, textureFilename, textureCount) textureCount += 1 glEndList() |