-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
73 lines (52 loc) · 2.02 KB
/
view.py
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
import glfw
from OpenGL.GL import *
import numpy as np
import sys
import transformations2 as tr2
import basic_shapes as bs
import easy_shaders as es
from model import *
from controller import *
if __name__ == "__main__":
# Initialize glfw
if not glfw.init():
sys.exit()
width = 600
height = 600
window = glfw.create_window(width, height, "EPIC TPOSE VIEWER", None, None)
if not window:
glfw.terminate()
sys.exit()
glfw.make_context_current(window)
controller = Controller()
# Connecting the callback function 'on_key' to handle keyboard events
glfw.set_key_callback(window, controller.on_key)
# Creating shader programs for textures and for colores
textureShaderProgram = es.SimpleTextureModelViewProjectionShaderProgram() # TEXTURAS
colorShaderProgram = es.SimpleModelViewProjectionShaderProgram() # COLORES
# Setting up the clear screen color
glClearColor(0.15, 0.15, 0.15, 1.0)
# As we work in 3D, we need to check which part is in front,
# and which one is at the back
glEnable(GL_DEPTH_TEST)
# crear la camara y la proyeccion son usadas por el shader
projection = tr2.ortho(-1, 1, -1, 1, 0.1, 100) # volumen de visualizacion
view = tr2.lookAt( # hacia donde apunto y donde está la camara
np.array([10, 10, 5]),
np.array([0, 0, 0]),
np.array([0, 0, 1])
)
tpose = Tpose('img/ricardo.png')
axis = Axis()
# Definimos las referencias cruzadas
controller.set_tpose(tpose)
while not glfw.window_should_close(window):
# Using GLFW to check for input events
glfw.poll_events()
# Clearing the screen in both, color and depth
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
tpose.draw(colorShaderProgram, textureShaderProgram, projection, view)
axis.draw(colorShaderProgram, projection, view)
# Once the drawing is rendered, buffers are swap so an uncomplete drawing is never seen.
glfw.swap_buffers(window)
glfw.terminate()