Newer
Older
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
"""
Viewport Preview Drawing
************************
Routines to draw in the viewport the result
that is projected in the HMD
"""
from .opengl_helper import (
draw_rectangle,
view_reset,
view_setup,
)
from bgl import *
TODO = True
class Preview:
__slots__ = {
"_texture",
"_width",
"_height",
}
def init(self, width, height, texture):
"""
Initialize preview window
:param width: Horizontal dimension of preview window
:type width: int
:param height: Vertical dimension of preview window
:type height: int
:param texture: 2D Texture binding ID (bind to the Framebuffer Object)
:type texture: bgl.GLint
"""
self._texture = texture
self.update(width, height)
def quit(self):
"""
Destroy preview window
"""
def _delete(self):
"""
OpenGL garbage collector
"""
id_buf = Buffer(GL_INT, 1)
id_buf.to_list()[0] = self._texture
glDeleteTextures(1, id_buf)
self.delete()
def update(self, width, height):
"""
Resize preview window
:param width: Horizontal dimension of preview window
:type width: int
:param height: Vertical dimension of preview window
:type height: int
"""
self._width = width
self._height = height
def loop(self):
"""
Draw in the preview window
"""
texture = self._texture
width = self._width
height = self._height
offset = (600, 200)
act_tex = Buffer(GL_INT, 1)
glGetIntegerv(GL_ACTIVE_TEXTURE, act_tex)
viewport = Buffer(GL_INT, 4)
glGetIntegerv(GL_VIEWPORT, viewport)
glScissor(offset[0], offset[1], width, height)
glEnable(GL_DEPTH_TEST)
glDepthFunc(GL_LESS)
view_setup()
glEnable(GL_TEXTURE_2D)
glActiveTexture(GL_TEXTURE0)
glBindTexture(GL_TEXTURE_2D, texture)
draw_rectangle()
glBindTexture(GL_TEXTURE_2D, act_tex[0])
glDisable(GL_TEXTURE_2D)
glDisable(GL_DEPTH_TEST)
view_reset(viewport)
glViewport(viewport[0], viewport[1], viewport[2], viewport[3])
glScissor(viewport[0], viewport[1], viewport[2], viewport[3])