oktatas:programozas:python:wxpython_gui:wxpython_opengl
wxPython OpenGL
- Szerző: Sallai András
- Copyright © Sallai András, 2020
- Web: https://szit.hu
Koordináta tengelyek rajzolása
- koordinatarendszer.py
import sys import wx import wx.glcanvas as glcanvas from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * class SimpleCanvas(glcanvas.GLCanvas): def __init__(self, parent): glcanvas.GLCanvas.__init__(self, parent, -1) self.init = False self.context = glcanvas.GLContext(self) self.SetBackgroundStyle(wx.BG_STYLE_PAINT) self.Bind(wx.EVT_SIZE, self.OnSize) self.Bind(wx.EVT_PAINT, self.OnPaint) def OnSize(self, event): wx.CallAfter(self.DoSetViewport) event.Skip() def DoSetViewport(self): size = self.size = self.GetClientSize() self.SetCurrent(self.context) glViewport(0, 0, size.width, size.height) def OnPaint(self, event): dc = wx.PaintDC(self) self.SetCurrent(self.context) if not self.init: self.InitGL() self.init = True self.OnDraw() class AxisDraw(SimpleCanvas): def InitGL(self): glEnable(GL_DEPTH_TEST) glEnable(GL_LIGHTING) glEnable(GL_LIGHT0) def OnDraw(self): glClearColor(1,1,1,1) glClear(GL_COLOR_BUFFER_BIT) gluLookAt(-0.1, 0.1, 0.0, 0.0, 0.0, 0.4, 0.0, 0.1, 0) glBegin(GL_LINES) glVertex3f(-1.0, 0.0, 0.0) glVertex3f(1.0, 0.0, 0.0) glVertex3f(0.0, 1.0, 0.0) glVertex3f(0.0, -1.0, 0.0) glVertex3f(0.0, 0.0, -1.0) glVertex3f(0.0, 0.0, 1.0) glEnd() glFlush() self.SwapBuffers() class SimpleOpengl(wx.App): def OnInit(self): frame = wx.Frame(None) frame.SetSize((800,600)) canvas = AxisDraw(frame) frame.Show() return True app = SimpleOpengl() app.MainLoop()
oktatas/programozas/python/wxpython_gui/wxpython_opengl.txt · Utolsó módosítás: 2020/08/20 22:47 szerkesztette: admin