netgen/py_tutorials/opengl.py

75 lines
1.6 KiB
Python
Raw Normal View History

2014-10-06 22:36:17 +06:00
from netgen.csg import *
import netgen.meshing as meshing
2014-10-10 17:18:51 +06:00
import libvisual
2014-10-06 22:36:17 +06:00
from OpenGL.GLUT import *
# import Window class from other file
from opengl_window import Window
2014-10-06 22:36:17 +06:00
sp1 = Sphere (Pnt(0,0,0), 0.2)
sp2 = Sphere (Pnt(0.5,0,0), 0.2)
2014-10-10 17:18:51 +06:00
all = sp1+sp2
2014-10-06 22:36:17 +06:00
geom = CSGeometry()
geom.Add (all)
2014-10-10 17:18:51 +06:00
param = meshing.MeshingParameters()
param.maxh = 0.1
m1 = GenerateMesh (geom, param)
2014-10-06 22:36:17 +06:00
vis = VS(geom)
# window callback functions
2014-10-06 22:36:17 +06:00
def mydraw():
vis.Draw()
glutSwapBuffers()
def mymouse(xold, yold, x, y, mode):
MouseMove(vis,xold,yold, x,y, mode)
# init glut and create window
glutInit("mainwin")
win_geom = Window( name=b"ngs", drawfunc=mydraw, mousefunc=mymouse)
###########################################
# press ctrl+c to break loop
2015-10-20 14:09:29 +05:00
while(True):
for i in range(10000):
glutMainLoopEvent()
print('press ctrl+c to create second window!')
###########################################
# create second window (transformation matrices are shared)
vismesh = libvisual.meshvis.VS(m1)
def mydraw2():
vismesh.Draw()
glutSwapBuffers()
2014-10-07 02:01:44 +06:00
win_mesh = Window( name=b"ngs2", drawfunc=mydraw2, mousefunc=mymouse)
2014-10-10 17:18:51 +06:00
###########################################
# press ctrl+c to break loop
try:
while(True):
for i in range(10000):
glutMainLoopEvent()
print('press ctrl+c to hide/destroy first window!')
except:
pass
2014-10-06 22:36:17 +06:00
###########################################
2014-10-06 22:36:17 +06:00
## BREAKS (on numericus) as soon as mouse touches remaining window ("Error of failed request: GLXBadContextTag")
# glutDestroyWindow(win_geom.handle)
2014-10-06 22:36:17 +06:00
## WORKS
glutHideWindow(win_geom.handle)
2014-10-06 22:36:17 +06:00
try:
while(True):
glutMainLoopEvent()
except:
pass