-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlab3-2-solution.py
More file actions
38 lines (26 loc) · 931 Bytes
/
lab3-2-solution.py
File metadata and controls
38 lines (26 loc) · 931 Bytes
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
from OpenGL.GL import *
import math
from app import run, readFile
from matrix import Matrix
from glslprogram import Program
from meshes import setupTriangle
vsCode = readFile('./shaders/lab3-2.vert')
fsCode = readFile('./shaders/lab3.frag')
def init():
global program
global drawCount
program = Program(vsCode, fsCode)
program.use()
drawCount = setupTriangle(program.programId)
projection = Matrix.makePerspective()
invCameraPos = Matrix.makeTranslation(0, 0, -5)
mProjView = projection @ invCameraPos
program.setUniformMat4('mProjView', mProjView)
def render(dt, time):
glClear(GL_COLOR_BUFFER_BIT)
mModel = Matrix.makeTranslation(
math.sin(time*2), 0.0, 0.) @ Matrix.makeRotationX(time)
program.setUniformMat4('mModel', mModel)
program.setUniformFloat('time', time)
glDrawArrays(GL_TRIANGLES, 0, drawCount)
run("2DT904 - Transformations", init, render)