Removed all non wx stuff from the glcanvas module since DA's PyOpenGL
is better and compatible with the wxGLCanvas. You can get it at http://starship.python.net:9673/crew/da/Code/PyOpenGL. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5102 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
5e6a0e8315
commit
d2103cf2e2
@ -66,6 +66,9 @@ Added a wrapper for the PCX and TIFF ImageHandlers.
|
||||
|
||||
wxRect now simulates attributes named left, right, top and bottom.
|
||||
|
||||
Removed all non wx stuff from the glcanvas module since DA's PyOpenGL
|
||||
is better and compatible with the wxGLCanvas. You can get it at
|
||||
http://starship.python.net:9673/crew/da/Code/PyOpenGL.
|
||||
|
||||
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
from wxPython.wx import *
|
||||
try:
|
||||
from wxPython.glcanvas import *
|
||||
from OpenGL.GL import *
|
||||
from OpenGL.GLUT import *
|
||||
haveGLCanvas = true
|
||||
except ImportError:
|
||||
haveGLCanvas = false
|
||||
@ -19,34 +21,37 @@ else:
|
||||
|
||||
|
||||
def runTest(frame, nb, log):
|
||||
#win = TestGLCanvas(nb)
|
||||
#win.SetFocus()
|
||||
#return win
|
||||
win = wxFrame(frame, -1, "GL Cube", wxDefaultPosition, wxSize(400,300))
|
||||
canvas = TestGLCanvas(win)
|
||||
win = wxFrame(frame, -1, "GL Demos", wxDefaultPosition, wxSize(300,300))
|
||||
CubeCanvas(win)
|
||||
#MySplitter(win)
|
||||
frame.otherWin = win
|
||||
win.Show(true)
|
||||
return None
|
||||
|
||||
|
||||
class MySplitter(wxSplitterWindow):
|
||||
def __init__(self, parent):
|
||||
wxSplitterWindow.__init__(self, parent, -1)
|
||||
cube = CubeCanvas(self)
|
||||
cone = ConeCanvas(self)
|
||||
|
||||
class TestGLCanvas(wxGLCanvas):
|
||||
self.SplitVertically(cube, cone)
|
||||
self.SetSashPosition(300)
|
||||
|
||||
|
||||
|
||||
class CubeCanvas(wxGLCanvas):
|
||||
def __init__(self, parent):
|
||||
wxGLCanvas.__init__(self, parent, -1)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
self.init = false
|
||||
EVT_CHAR(self, self.MyOnChar)
|
||||
|
||||
def MyOnChar(self, event):
|
||||
print "MyOnChar"
|
||||
|
||||
def OnEraseBackground(self, event):
|
||||
pass # Do nothing, to avoid flashing.
|
||||
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
if self.GetContext() != 'NULL':
|
||||
if self.GetContext():
|
||||
self.SetCurrent()
|
||||
glViewport(0, 0, size.width, size.height)
|
||||
|
||||
@ -54,12 +59,8 @@ else:
|
||||
def OnPaint(self, event):
|
||||
dc = wxPaintDC(self)
|
||||
|
||||
ctx = self.GetContext()
|
||||
if not ctx: return
|
||||
|
||||
self.SetCurrent()
|
||||
|
||||
|
||||
if not self.init:
|
||||
self.InitGL()
|
||||
self.init = true
|
||||
@ -128,6 +129,67 @@ else:
|
||||
|
||||
|
||||
|
||||
class ConeCanvas(wxGLCanvas):
|
||||
def __init__(self, parent):
|
||||
wxGLCanvas.__init__(self, parent, -1)
|
||||
EVT_ERASE_BACKGROUND(self, self.OnEraseBackground)
|
||||
self.init = false
|
||||
|
||||
def OnEraseBackground(self, event):
|
||||
pass # Do nothing, to avoid flashing.
|
||||
|
||||
def OnSize(self, event):
|
||||
size = self.GetClientSize()
|
||||
if self.GetContext():
|
||||
self.SetCurrent()
|
||||
glViewport(0, 0, size.width, size.height)
|
||||
|
||||
def GLInit( self ):
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
# camera frustrum setup
|
||||
glFrustum(-0.5, 0.5, -0.5, 0.5, 1.0, 3.0);
|
||||
glMaterial(GL_FRONT, GL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
|
||||
glMaterial(GL_FRONT, GL_DIFFUSE, [0.8, 0.8, 0.8, 1.0])
|
||||
glMaterial(GL_FRONT, GL_SPECULAR, [1.0, 0.0, 1.0, 1.0])
|
||||
glMaterial(GL_FRONT, GL_SHININESS, 50.0)
|
||||
glLight(GL_LIGHT0, GL_AMBIENT, [0.0, 1.0, 0.0, 1.0])
|
||||
glLight(GL_LIGHT0, GL_DIFFUSE, [1.0, 1.0, 1.0, 1.0])
|
||||
glLight(GL_LIGHT0, GL_SPECULAR, [1.0, 1.0, 1.0, 1.0])
|
||||
glLight(GL_LIGHT0, GL_POSITION, [1.0, 1.0, 1.0, 0.0]);
|
||||
glLightModel(GL_LIGHT_MODEL_AMBIENT, [0.2, 0.2, 0.2, 1.0])
|
||||
glEnable(GL_LIGHTING)
|
||||
glEnable(GL_LIGHT0)
|
||||
glDepthFunc(GL_LESS)
|
||||
glEnable(GL_DEPTH_TEST)
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
|
||||
def OnPaint( self, event ):
|
||||
dc = wxPaintDC(self)
|
||||
if not self.init:
|
||||
self.GLInit()
|
||||
self.init = true
|
||||
|
||||
### Tell system to use _this_ glcanvas for all commands
|
||||
self.SetCurrent()
|
||||
# clear color and depth buffers
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
# position viewer
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
# use a fresh transformation matrix
|
||||
glPushMatrix()
|
||||
# position object
|
||||
glTranslate(0.0, 0.0, -2.0);
|
||||
glRotate(30.0, 1.0, 0.0, 0.0);
|
||||
glRotate(30.0, 0.0, 1.0, 0.0);
|
||||
|
||||
### From cone.py
|
||||
glTranslate(0, -1, 0)
|
||||
glRotate(250, 1, 0, 0)
|
||||
glutSolidCone(1, 2, 50, 10)
|
||||
glPopMatrix()
|
||||
# push into visible buffer
|
||||
self.SwapBuffers()
|
||||
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@ -151,8 +213,9 @@ overview = """\
|
||||
def _test():
|
||||
class MyApp(wxApp):
|
||||
def OnInit(self):
|
||||
frame = wxFrame(NULL, -1, "GL Cube", wxDefaultPosition, wxSize(400,300))
|
||||
win = TestGLCanvas(frame)
|
||||
frame = wxFrame(NULL, -1, "GL Demos", wxDefaultPosition, wxSize(600,300))
|
||||
#win = ConeCanvas(frame)
|
||||
MySplitter(frame)
|
||||
frame.Show(TRUE)
|
||||
self.SetTopWindow(frame)
|
||||
return TRUE
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user