[PyOpenGL-Users] glColor problem
Brought to you by:
mcfletch
From: Greg H. <gho...@co...> - 2004-02-22 08:58:53
|
I'm trying to write a simple app using PyOpenG, unfortunately the glColor*() function seems to have no effect. I'm sure I'm just missing something. Any help would be appreciated. The following source code only shows the 2 classes used to extend the wxGLCanvas...the remaining code simply adds a Contour canvas to a Frame and shows the Frame. A polygon shows up, but only in gray. I've tried many variations, all resulting in only a gray polygon. Thank you. class MyCanvasBase(wxGLCanvas): def __init__(self, parent, size, pos = wxDefaultPosition): wxGLCanvas.__init__(self, parent, -1, size = size, pos = pos, attribList = WX_GL_RGBA) self.parent = parent self.size = size self.init = False # initial mouse position self.lastx = self.x = 30 self.lasty = self.y = 30 self.SetColour('white') self.SetCurrent() glViewport(0, 0, self.size.width, self.size.height) EVT_ERASE_BACKGROUND(self, self.OnEraseBackground) EVT_SIZE(self, self.OnSize) EVT_PAINT(self, self.OnPaint) EVT_LEFT_DOWN(self, self.OnMouseDown) # needs fixing... EVT_LEFT_UP(self, self.OnMouseUp) EVT_MOTION(self, self.OnMouseMotion) def OnEraseBackground(self, event): pass # Do nothing, to avoid flashing on MSW. def OnSize(self, event): #size = self.GetClientSize() if self.GetContext(): self.SetCurrent() glViewport(0, 0, self.size.width, self.size.height) def OnPaint(self, event): dc = wxPaintDC(self) self.SetCurrent() glViewport(0, 0, self.size.width, self.size.height) if not self.init: self.InitGL() self.init = True self.OnDraw() def OnMouseDown(self, evt): self.x, self.y = evt.GetPosition() self.CaptureMouse() def OnMouseUp(self, evt): self.ReleaseMouse() def OnMouseMotion(self, evt): if evt.Dragging() and evt.LeftIsDown(): self.lastx, self.lasty = self.x, self.y #self.x, self.y = self.lastx, self.lasty self.x, self.y = evt.GetPosition() self.Refresh(False) class Contourcanvas(MyCanvasBase): def InitGL(self): # set viewing projection glMatrixMode(GL_PROJECTION) glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0) # position viewer glMatrixMode(GL_MODELVIEW) glTranslatef(0.0, 0.0, -2.0) # position object glRotatef(self.y, 1.0, 0.0, 0.0) glRotatef(self.x, 0.0, 1.0, 0.0) glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) def OnDraw(self): max = 0; for i in range(NUM_ROWS): for j in range(NUM_COLS): val = int(self.parent.mappanel.grid.GetCellValue(i, j)) if max < val: max = val # clear color and depth buffers glClearColor(1.0, 1.0, 1.0, 1.0) glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) glBegin(GL_QUADS) glColor3f(1.0, 0.0, 0.0) glVertex3f(0.0, 1.0, 1.0) glVertex3f(0.0, -1.0, -1.0) glColor3f(0.0, 0.0, 1.0) glVertex3f(0.0, -1.0, 1.0) glVertex3f(0.0, 1.0, -1.0) glEnd() glFlush() glRotatef((self.lasty - self.y)/10., 1.0, 0.0, 0.0); glRotatef((self.lastx - self.x)/10., 0.0, 1.0, 0.0); self.SwapBuffers() --Greg |