File: gl-test.py

package info (click to toggle)
yade 2025.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,308 kB
  • sloc: cpp: 93,298; python: 50,409; sh: 577; makefile: 162
file content (50 lines) | stat: -rw-r--r-- 1,506 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#
# Test script for OpenGL from python (and from other threads in general)
# With GL locking, 1 view seems to work reliably, not two views, though.
#
# Some drivers (nvidia) raise XBadAccess if there is an attempt to access
#  OpenGL context concurrently from different threads.
# Other drivers (intel, at least on my laptop) freeze the videocard completely
#  if that is the case.
#
# You can enable the "if False:" part (say "if True:" instead) to see what
# it does in your case.
#

from yade import qt
from yade import utils

O.bodies.append(utils.box([0, 0, 0], [1, 1, 1], color=[1, 0, 0]))
O.bodies.append(utils.sphere([0, 2, 0], 1, color=[0, 1, 0]))

print('Begin here.')
qt.View()
print('Created view')
glv0 = qt.GLViewer()
print('view #0')  # get GLViewer instance for the primary view
glv0.grid = True, True, False
print('grid x,y')
glv0.axes = True
print('axes shown')
glv0.screenSize = 200, 200
print('screen size set to 200x200')
glv0.center(True)
print('median center')  # median center - will fallback since there are only 2 bodies

##
## !!! If you enable this, you may crash your machine !!!
##
if False:
	glv1 = qt.View()
	print('Created 2nd view')  # create new view
	glv1.fps = True
	print('fps shown')
	glv1.lookAt = (0, 1, 0)
	print('lookAt set')
	glv1.viewDirection = (0, -1, 0)
	print('viewDirection set')
	glv1.center()
	print('center')

print('list of views:', qt.views())  # list all views we have
print("CONGRATULATIONS! You passed the OpenGL test without crash or freeze :-)")