Newer
Older
"""
Debug
=====
Debug device for testing
"""
VERBOSE = False
def print_debug(*args):
if VERBOSE:
print("Debug: {0}".format(*args))
def isConnected(self):
"""
Check if device is connected
:return: return True if the device is connected
:rtype: bool
"""
return True
def init(self):
"""
Initialize device
:return: return True if the device was properly initialized
:rtype: bool
"""
return super(Debug, self).init()
def loop(self):
"""
Get fresh tracking data
"""
debug_draw(self._offscreen_object, self._width, self._height)
def frameReady(self):
"""
The frame is ready to be send to the device
"""
def quit(self):
"""
Garbage collection
"""
return super(Debug, self).quit()
# ##################
# Debug Debug Debug
# ##################
from bgl import *
global _time
_time = 0
# ##################
# OpenGL generic routines
# ##################
def view_setup():
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_TEXTURE)
glPushMatrix()
glLoadIdentity()
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
glOrtho(-1, 1, -1, 1, -20, 20)
gluLookAt(0.0, 0.0, 1.0, 0.0,0.0,0.0, 0.0,1.0,0.0)
# Get texture info
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_TEXTURE)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
# ##################
# Draw an animated cube on the offscreen object
def debug_draw(offscreen_object, width, height):
"""
draw in the FBO
"""
import time
import math
import gpu
# setup
viewport = Buffer(GL_INT, 4)
glGetIntegerv(GL_VIEWPORT, viewport)
glViewport(0, 0, width, height)
gpu.offscreen_object_bind(offscreen_object, True)
glClearColor(1.0, 1.0, 1.0, 1.0)
glClearDepth(1.0)
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
glDisable(GL_DEPTH_TEST)
glDepthFunc(GL_LESS)
# actual drawing
speed = 0.01
_time, _int = math.modf(_time + speed)
factor = _time * 2.0
if factor > 1.0:
factor = 2.0 - factor;
one = one - factor;
zer = factor - zer;
glMatrixMode(GL_PROJECTION)
glPushMatrix()
glLoadIdentity()
glOrtho(-1.0, 1.0, -1.0, 1.0, 1.0, 20.0)
glMatrixMode(GL_MODELVIEW)
glPushMatrix()
glLoadIdentity()
gluLookAt(0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
current_color = Buffer(GL_FLOAT, 4)
glGetFloatv(GL_CURRENT_COLOR, current_color);
glEnable(GL_COLOR_MATERIAL)
glBegin(GL_QUADS)
glColor3f(one, zer, zer)
glVertex3f(-0.75, -0.75, 0.0)
glColor3f(zer, one, zer)
glVertex3f( 0.75, -0.75, 0.0)
glColor3f(zer, zer, one)
glVertex3f( 0.75, 0.75, 0.0)
glColor3f(one, one, zer)
glVertex3f(-0.75, 0.75, 0.0)
glEnd()
glColor4fv(current_color)
glDisable(GL_COLOR_MATERIAL)
glMatrixMode(GL_PROJECTION)
glPopMatrix()
glMatrixMode(GL_MODELVIEW)
glPopMatrix()
view_reset()
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
# unbinding
gpu.offscreen_object_unbind(offscreen_object, True)