2020-07-19 10:41:08 +02:00
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
|
|
|
|
print('64' if sys.maxsize > 2 ** 32 else '32')
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
from wsgiref.validate import check_errors
|
|
|
|
|
|
|
|
from OpenGL.GL.ARB.vertex_array_object import glDeleteVertexArrays
|
|
|
|
from OpenGL.GL.framebufferobjects import glBindFramebuffer
|
|
|
|
from OpenGL.GLUT import *
|
|
|
|
import OpenGL.GLUT.freeglut
|
|
|
|
from OpenGL.GLU import *
|
|
|
|
from OpenGL.GL import *
|
|
|
|
from ctypes import sizeof, c_float, c_void_p, c_uint
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import math as math
|
|
|
|
from Objects.Cube.Cube import *
|
|
|
|
from Objects.Cuboid.Cuboid import *
|
|
|
|
from Objects.Structure import *
|
|
|
|
from MatrixStuff.Transformations import *
|
|
|
|
from Lights.Lights import *
|
|
|
|
from Lights.LightingManager import *
|
|
|
|
import numpy as np
|
|
|
|
import time
|
|
|
|
|
|
|
|
name = b'ball_glut'
|
|
|
|
|
2017-08-29 16:30:53 +02:00
|
|
|
struct = None
|
2017-10-21 11:10:00 +02:00
|
|
|
cstruct = None
|
2017-08-27 12:51:26 +02:00
|
|
|
program_id = 0
|
|
|
|
program2_id = 0
|
|
|
|
program3_id = 0
|
|
|
|
start = time.time()
|
|
|
|
frames = 0
|
2020-07-19 10:41:08 +02:00
|
|
|
width = 1920
|
|
|
|
height = 1080
|
2017-08-27 12:51:26 +02:00
|
|
|
opening = 45
|
|
|
|
l = Light()
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
def main():
|
|
|
|
lm = LightingManager()
|
2020-07-19 10:41:08 +02:00
|
|
|
# lm.addRenderStep(0,0)
|
|
|
|
# lm.addRenderStep(1,1)
|
|
|
|
# lm.removeRenderStep(0,0)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
glutInit(sys.argv)
|
|
|
|
w = width
|
|
|
|
h = height
|
|
|
|
glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH)
|
2020-07-19 10:41:08 +02:00
|
|
|
glutInitWindowSize(w, h)
|
2017-08-27 12:51:26 +02:00
|
|
|
glutCreateWindow(name)
|
2020-07-19 10:41:08 +02:00
|
|
|
# glutEnterGameMode()
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
print("Vendor:", glGetString(GL_VENDOR))
|
|
|
|
print("Renderer:", glGetString(GL_RENDERER))
|
|
|
|
print("Version:", glGetString(GL_VERSION))
|
|
|
|
print("GLSL:", glGetString(GL_SHADING_LANGUAGE_VERSION))
|
|
|
|
|
|
|
|
c = Cube()
|
|
|
|
cuboid = Cuboid()
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
glClearColor(0., 0., 0., 1.)
|
|
|
|
# glShadeModel(GL_SMOOTH)
|
|
|
|
# glDisable(GL_CULL_FACE)
|
2017-08-27 12:51:26 +02:00
|
|
|
glEnable(GL_CULL_FACE)
|
|
|
|
glCullFace(GL_BACK)
|
|
|
|
glEnable(GL_TEXTURE_2D)
|
|
|
|
glEnable(GL_DEPTH_TEST)
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# glEnable(GL_LIGHTING)
|
2017-08-27 12:51:26 +02:00
|
|
|
'''lightZeroPosition = [10.,4.,10.,1.]
|
|
|
|
lightZeroColor = [0.8,1.0,0.8,1.0] #green tinged
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, lightZeroPosition)
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, lightZeroColor)
|
|
|
|
glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 0.1)
|
|
|
|
glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.05)
|
|
|
|
glEnable(GL_LIGHT0)'''
|
|
|
|
glutDisplayFunc(display)
|
|
|
|
glutReshapeFunc(resize)
|
|
|
|
glutKeyboardFunc(keyboardHandler)
|
|
|
|
glutSpecialFunc(funcKeydHandler)
|
|
|
|
'''glMatrixMode(GL_PROJECTION)
|
|
|
|
gluPerspective(40.,1.,1.,40.)
|
|
|
|
glMatrixMode(GL_MODELVIEW)'''
|
2020-07-19 10:41:08 +02:00
|
|
|
# gluLookAt(0,0,10,
|
2017-08-27 12:51:26 +02:00
|
|
|
# 0,0,0,
|
|
|
|
# 0,1,0)
|
2020-07-19 10:41:08 +02:00
|
|
|
# glPushMatrix()
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
with open('passthroughvertex.glsl', 'r') as f:
|
|
|
|
vertex_shader_string = f.read()
|
|
|
|
passthrough_vertex_shader_id = glCreateShader(GL_VERTEX_SHADER)
|
|
|
|
glShaderSource(passthrough_vertex_shader_id, vertex_shader_string)
|
|
|
|
glCompileShader(passthrough_vertex_shader_id)
|
|
|
|
if glGetShaderiv(passthrough_vertex_shader_id, GL_COMPILE_STATUS) != GL_TRUE:
|
|
|
|
raise RuntimeError(glGetShaderInfoLog(passthrough_vertex_shader_id))
|
|
|
|
|
|
|
|
with open('vertex.glsl', 'r') as f:
|
|
|
|
vertex_shader_string = f.read()
|
|
|
|
vertex_shader_id = glCreateShader(GL_VERTEX_SHADER)
|
|
|
|
glShaderSource(vertex_shader_id, vertex_shader_string)
|
|
|
|
glCompileShader(vertex_shader_id)
|
|
|
|
if glGetShaderiv(vertex_shader_id, GL_COMPILE_STATUS) != GL_TRUE:
|
|
|
|
raise RuntimeError(glGetShaderInfoLog(vertex_shader_id))
|
|
|
|
|
|
|
|
with open('texturefragment.glsl', 'r') as f:
|
|
|
|
fragment_shader_string = f.read()
|
|
|
|
texturefragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER)
|
|
|
|
glShaderSource(texturefragment_shader_id, fragment_shader_string)
|
|
|
|
glCompileShader(texturefragment_shader_id)
|
|
|
|
if glGetShaderiv(texturefragment_shader_id, GL_COMPILE_STATUS) != GL_TRUE:
|
|
|
|
raise RuntimeError(glGetShaderInfoLog(texturefragment_shader_id))
|
|
|
|
|
|
|
|
with open('fragment.glsl', 'r') as f:
|
|
|
|
fragment_shader_string = f.read()
|
|
|
|
fragment_shader_id = glCreateShader(GL_FRAGMENT_SHADER)
|
|
|
|
glShaderSource(fragment_shader_id, fragment_shader_string)
|
|
|
|
glCompileShader(fragment_shader_id)
|
|
|
|
if glGetShaderiv(fragment_shader_id, GL_COMPILE_STATUS) != GL_TRUE:
|
|
|
|
raise RuntimeError(glGetShaderInfoLog(fragment_shader_id))
|
|
|
|
|
|
|
|
global program_id, program2_id, program3_id
|
|
|
|
program_id = glCreateProgram()
|
|
|
|
glAttachShader(program_id, vertex_shader_id)
|
2020-07-19 10:41:08 +02:00
|
|
|
glAttachShader(program_id, Cube.GeometryShaderId)
|
|
|
|
# glAttachShader(program_id, Cuboid.GeometryShaderId)
|
2017-08-27 12:51:26 +02:00
|
|
|
glAttachShader(program_id, fragment_shader_id)
|
2020-07-19 10:41:08 +02:00
|
|
|
# glAttachShader(program_id, l.FragmentShaderId)
|
2017-08-27 12:51:26 +02:00
|
|
|
glLinkProgram(program_id)
|
|
|
|
|
2017-10-21 11:10:00 +02:00
|
|
|
global struct, cstruct
|
2017-08-27 12:51:26 +02:00
|
|
|
struct = Structure()
|
2020-07-19 10:41:08 +02:00
|
|
|
struct.addShape(program_id, Cube().translate(translate(0, 0, 1)).setColor(1, 1, 0))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(1, 1, 0)).setColor(0, 0, 1))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(1, 0, 0)).setColor(0, 1, 0))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(1, -1, 0)).setColor(1, 0, 0))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(0, -1, 0)).setColor(0, 1, 0))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(-1, -1, 0)).setColor(0, 0, 1))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(-1, 0, 0)).setColor(0, 1, 1))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(-1, 1, 0)).setColor(1, 1, 1))
|
|
|
|
# struct.addShape(program_id, Cube().translate(translate(0, 1, 0)).setColor(0, 0, 1))
|
|
|
|
|
|
|
|
for x_pos in range(-10, 10, 1):
|
|
|
|
for y_pos in range(-10, 10):
|
|
|
|
struct.addShape(program_id, Cube().translate(translate(x_pos, y_pos, 0)).setColor(
|
|
|
|
random.randint(0, 100) / 100.0, random.randint(0, 100) / 100.0, random.randint(0, 100) / 100.0))
|
|
|
|
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
struct.buildvertexArrays()
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
# struct.clearVertexArrays()
|
|
|
|
|
2017-10-21 11:10:00 +02:00
|
|
|
cstruct = CompoundStructure()
|
|
|
|
cstruct.addStructure(struct)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
program3_id = l.getDepthProgram(vertex_shader_id, Cube.GeometryShaderId)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
program2_id = glCreateProgram()
|
|
|
|
glAttachShader(program2_id, passthrough_vertex_shader_id)
|
|
|
|
glAttachShader(program2_id, texturefragment_shader_id)
|
|
|
|
glLinkProgram(program2_id)
|
|
|
|
|
|
|
|
if glGetProgramiv(program_id, GL_LINK_STATUS) != GL_TRUE:
|
|
|
|
raise RuntimeError(glGetProgramInfoLog(program_id))
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
global vai, pbi, cbi, vai2, vai3
|
2017-08-27 12:51:26 +02:00
|
|
|
vai, pbi, cbi = create_vertex_buffers(np.array([0, 0, 1,
|
2020-07-19 10:41:08 +02:00
|
|
|
1, 1, 0,
|
2017-08-27 12:51:26 +02:00
|
|
|
1, 0, 0,
|
|
|
|
1, -1, 0,
|
|
|
|
0, -1, 0,
|
|
|
|
-1, -1, 0,
|
|
|
|
-1, 0, 0,
|
|
|
|
-1, 1, 0,
|
2020-07-19 10:41:08 +02:00
|
|
|
0, 1, 0], dtype=np.float32),
|
2017-08-27 12:51:26 +02:00
|
|
|
np.array([1, 1, 0,
|
|
|
|
0, 0, 1,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
0, 0, 1,
|
|
|
|
0, 1, 1,
|
|
|
|
1, 1, 1,
|
2020-07-19 10:41:08 +02:00
|
|
|
0, 0, 1], dtype=np.float32), program_id,
|
2017-08-27 12:51:26 +02:00
|
|
|
sizes=np.array(
|
|
|
|
[0.5, 1.5, 1.5,
|
|
|
|
0.5, 1.5, 1.5,
|
2020-07-19 10:41:08 +02:00
|
|
|
0.5, 1.5, 1.5], dtype=np.float32))
|
2017-08-27 12:51:26 +02:00
|
|
|
v = []
|
|
|
|
color = []
|
2020-07-19 10:41:08 +02:00
|
|
|
for i in range(-11, 12):
|
|
|
|
for j in range(-11, 12):
|
2017-08-27 12:51:26 +02:00
|
|
|
v.append(i)
|
|
|
|
v.append(j)
|
|
|
|
v.append(0)
|
|
|
|
color.append(1)
|
|
|
|
color.append(1)
|
|
|
|
color.append(1)
|
|
|
|
|
|
|
|
'''vai, pbi, cbi = create_vertex_buffers(np.array(v, dtype=np.float32),
|
|
|
|
np.array(color, dtype=np.float32), program_id,
|
|
|
|
sizes=np.array(
|
|
|
|
[0.5, 1.5, 1.5,
|
|
|
|
0.5, 1.5, 1.5,
|
|
|
|
0.5, 1.5, 1.5], dtype=np.float32))'''
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
vai2, _, _ = create_vertex_buffers(np.array([0.4, 0.4, 0,
|
|
|
|
1, 0.4, 0,
|
|
|
|
0.4, 1, 0,
|
|
|
|
0.4, 1, 0,
|
|
|
|
1, 0.4, 0,
|
|
|
|
1, 1, 0], dtype=np.float32),
|
|
|
|
np.array([0, 0, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
1, 1, 0], dtype=np.float32), program2_id)
|
2017-08-27 12:51:26 +02:00
|
|
|
vai3, _, _ = create_vertex_buffers(np.array([-1, -1, 0,
|
|
|
|
1, -1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
-1, 1, 0,
|
|
|
|
1, -1, 0,
|
|
|
|
1, 1, 0], dtype=np.float32),
|
|
|
|
np.array([0, 0, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
0, 1, 0,
|
|
|
|
1, 0, 0,
|
|
|
|
1, 1, 0], dtype=np.float32), program2_id)
|
2020-07-19 10:41:08 +02:00
|
|
|
struct.render(projMatrix, rotate(rx, 0, 0))
|
2017-08-27 12:51:26 +02:00
|
|
|
glutMainLoop()
|
|
|
|
return
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
projMatrix = perspectiveMatrix(45.0, 400 / 400, 0.01, 100.0);
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
def check_error(message):
|
|
|
|
gl_error = glGetError()
|
2020-07-19 10:41:08 +02:00
|
|
|
if gl_error != GL_NO_ERROR:
|
2017-08-27 12:51:26 +02:00
|
|
|
print("Error: " + message)
|
2020-07-19 10:41:08 +02:00
|
|
|
if gluErrorString(gl_error):
|
2017-08-27 12:51:26 +02:00
|
|
|
print(gluErrorString(gl_error))
|
|
|
|
else:
|
|
|
|
print(hex(gl_error))
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
def create_vertex_buffers(positions, colors, program_id, sizes=np.array([])):
|
2017-08-27 12:51:26 +02:00
|
|
|
glEnableClientState(GL_VERTEX_ARRAY)
|
|
|
|
glEnableClientState(GL_TEXTURE_COORD_ARRAY)
|
|
|
|
glEnableClientState(GL_NORMAL_ARRAY)
|
|
|
|
glEnableClientState(GL_COLOR_ARRAY)
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# global vai, pbi, cbi
|
2017-08-27 12:51:26 +02:00
|
|
|
tvai = GLuint(0)
|
|
|
|
tpbi = GLuint(0)
|
|
|
|
tcbi = GLuint(0)
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# test = glGetString(GL_VERSION)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
glGenVertexArrays(1, tvai)
|
2017-08-27 12:51:26 +02:00
|
|
|
glBindVertexArray(tvai)
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
vid = glGetAttribLocation(program_id, "in_position")
|
2017-08-27 12:51:26 +02:00
|
|
|
glEnableVertexAttribArray(vid)
|
|
|
|
|
|
|
|
tpbi = glGenBuffers(1)
|
2020-07-19 10:41:08 +02:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, tpbi)
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, positions, GL_STATIC_DRAW)
|
|
|
|
glVertexAttribPointer(vid, 3, GL_FLOAT, GL_FALSE, 0, None)
|
2017-08-27 12:51:26 +02:00
|
|
|
check_error("Could not create position buffer")
|
|
|
|
|
|
|
|
tcbi = glGenBuffers(1)
|
2020-07-19 10:41:08 +02:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, tcbi)
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, colors, GL_STATIC_DRAW)
|
2017-08-27 12:51:26 +02:00
|
|
|
vc = glGetAttribLocation(program_id, "MyInColor")
|
|
|
|
if vc != -1:
|
|
|
|
glEnableVertexAttribArray(vc)
|
|
|
|
glVertexAttribPointer(vc, 3, GL_FLOAT, GL_FALSE, 0, None)
|
|
|
|
check_error("Could not create color buffer")
|
|
|
|
|
|
|
|
if len(sizes) > 0:
|
|
|
|
sbi = glGenBuffers(1)
|
2020-07-19 10:41:08 +02:00
|
|
|
glBindBuffer(GL_ARRAY_BUFFER, sbi)
|
|
|
|
glBufferData(GL_ARRAY_BUFFER, sizes, GL_STATIC_DRAW)
|
2017-08-27 12:51:26 +02:00
|
|
|
vs = glGetAttribLocation(program_id, "MyInSize")
|
|
|
|
if vs != -1:
|
|
|
|
glEnableVertexAttribArray(vs)
|
2020-07-19 10:41:08 +02:00
|
|
|
glVertexAttribPointer(vs, 3, GL_FLOAT, GL_FALSE, 0, None)
|
2017-08-27 12:51:26 +02:00
|
|
|
check_error("Could not create size buffer")
|
|
|
|
|
|
|
|
glBindVertexArray(0)
|
|
|
|
return tvai, tpbi, tcbi
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
def clear_buffer(buffer_id):
|
|
|
|
glDisableVertexAttribArray(buffer_id)
|
2020-07-19 10:41:08 +02:00
|
|
|
glDeleteBuffers(1, [buffer_id])
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
def clear_vertex_array(va_id):
|
2020-07-19 10:41:08 +02:00
|
|
|
glDeleteVertexArrays(1, va_id)
|
2017-08-27 12:51:26 +02:00
|
|
|
check_error("Could not destroy vertex array")
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
vai, pbi, cbi = 0, 0, 0
|
|
|
|
vai2, pbi2, cbi2 = 0, 0, 0
|
|
|
|
vai3, pbi3, cbi3 = 0, 0, 0
|
2017-08-27 12:51:26 +02:00
|
|
|
rx = 0
|
|
|
|
ry = 0
|
|
|
|
|
2017-08-29 16:30:53 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
def render(program_id, projMatrix, vai, x, y, z, alternateprograms=None):
|
2017-10-21 11:10:00 +02:00
|
|
|
global struct, cstruct
|
2017-08-29 16:30:53 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
cstruct.render(translate(x, y, z) * rotate(0, ry, 0, True) * projMatrix, rotate(rx, 0, 0), alternateprograms)
|
|
|
|
'''
|
|
|
|
glUseProgram(program_id)
|
2017-08-27 12:51:26 +02:00
|
|
|
check_error("Renderingprogram is not initialized!")
|
|
|
|
|
|
|
|
projection = glGetUniformLocation(program_id, 'projModelViewMatrix')
|
|
|
|
rot = glGetUniformLocation(program_id, 'rotMatrix')
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
glUniformMatrix4fv(projection, 1, GL_FALSE, np.array(translate(x, y, z) * rotate(rx, 0, 0, True) * projMatrix, dtype=np.float32))
|
|
|
|
glUniformMatrix3fv(rot, 1, GL_FALSE, np.array(rotate(rx, 0, 0), dtype=np.float32))
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
glBindVertexArray(vai)
|
|
|
|
glDrawArrays(GL_POINTS, 0, 9)#529
|
|
|
|
check_error("Rendering problem")
|
|
|
|
|
|
|
|
glBindVertexArray(0)
|
2020-07-19 10:41:08 +02:00
|
|
|
glUseProgram(0)
|
|
|
|
'''
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
def display():
|
|
|
|
'''if time.time() - start >= 1:
|
|
|
|
print(frames+1)
|
|
|
|
global start, frames
|
|
|
|
frames = 0
|
|
|
|
start = time.time()
|
|
|
|
else:
|
|
|
|
global frames
|
|
|
|
frames += 1'''
|
2020-07-19 10:41:08 +02:00
|
|
|
glClearColor(0, 0, 0, 0)
|
2017-08-27 12:51:26 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
|
|
|
|
global l
|
|
|
|
l.prepareForDepthMapping()
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# newMat = orthogonalMatrix(10, -10, 10, -10, 10, -10) * lookAt(cx, cy, 5, 0, 0, 0, 0, 1,0) * np.identity(4)
|
|
|
|
# newMat = translate(0, 0, -10) * newMat
|
|
|
|
|
|
|
|
global projMatrix
|
|
|
|
projMatrix = perspectiveMatrix(45, float(width) / float(height), 0.01, 100.0)
|
|
|
|
|
|
|
|
newMat = translate(-cx, -cy, -2) * lookAt(cx, cy, 2, 0, 0, 0, 0, 1, 0) * perspectiveMatrix(opening,
|
|
|
|
float(l.map_size) /
|
|
|
|
float(l.map_size),
|
|
|
|
0.01, 100.0)
|
|
|
|
l.pos = [-cx, -cy, -2]
|
|
|
|
l.ModelviewProjectionMatrix = newMat
|
|
|
|
l.lightColor = [1, 1, 1]
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
glUseProgram(program3_id)
|
|
|
|
widthid = glGetUniformLocation(program3_id, 'width')
|
|
|
|
heightid = glGetUniformLocation(program3_id, 'height')
|
|
|
|
nearid = glGetUniformLocation(program3_id, 'near')
|
|
|
|
farid = glGetUniformLocation(program3_id, 'far')
|
|
|
|
glUniform1f(nearid, 0.01)
|
|
|
|
glUniform1f(farid, 100)
|
|
|
|
glUniform1f(widthid, width)
|
|
|
|
glUniform1f(heightid, height)
|
2017-09-03 20:33:22 +02:00
|
|
|
|
|
|
|
altPrId = {}
|
|
|
|
altPrId[program_id] = program3_id
|
2020-07-19 10:41:08 +02:00
|
|
|
render(program3_id, newMat, vai, 0, 0, 0, altPrId)
|
2017-08-27 12:51:26 +02:00
|
|
|
glFlush()
|
|
|
|
l.finishDepthMapping()
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
glClearColor(1, 0, 0, 0)
|
2017-08-27 12:51:26 +02:00
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
|
|
|
|
glUseProgram(program_id)
|
|
|
|
widthid = glGetUniformLocation(program_id, 'width')
|
|
|
|
heightid = glGetUniformLocation(program_id, 'height')
|
|
|
|
nearid = glGetUniformLocation(program_id, 'near')
|
|
|
|
farid = glGetUniformLocation(program_id, 'far')
|
|
|
|
glUniform1f(nearid, 0.01)
|
|
|
|
glUniform1f(farid, 100)
|
2020-07-19 10:41:08 +02:00
|
|
|
glUniform1f(widthid, width)
|
2017-08-27 12:51:26 +02:00
|
|
|
glUniform1f(heightid, height)
|
|
|
|
|
|
|
|
lightProjModelViewMatrix = glGetUniformLocation(program_id, 'lightProjModelViewMatrix')
|
|
|
|
numLights = glGetUniformLocation(program_id, 'numLights')
|
|
|
|
lightpos = glGetUniformLocation(program_id, 'lightpos')
|
|
|
|
lightcolorid = glGetUniformLocation(program_id, 'lightColor')
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
glUniformMatrix4fv(lightProjModelViewMatrix, 1, GL_FALSE, np.array(l.ModelviewProjectionMatrix))
|
2017-08-27 12:51:26 +02:00
|
|
|
glUniform1iv(numLights, 1, 1)
|
2017-12-09 11:27:23 +01:00
|
|
|
glUniform3fv(lightpos, 1, l.pos)
|
|
|
|
glUniform3fv(lightcolorid, 1, l.lightColor)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
texID = glGetUniformLocation(program_id, 'ShadowMaps')
|
|
|
|
glActiveTexture(GL_TEXTURE0)
|
|
|
|
glBindTexture(GL_TEXTURE_2D, l.DepthBuffer)
|
2020-07-19 10:41:08 +02:00
|
|
|
glUniform1iv(texID, 1, 0)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
glViewport(0, 0, width, height)
|
|
|
|
render(program_id, translate(0, 0, -10) * lookAt(0, 0, 10, 0, 0, 0, 0, 1, 0) * projMatrix, vai, 0, 0, 0)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# temp, _, _ = create_vertex_buffers(np.array([cx, cy, 5], dtype=np.float32),
|
|
|
|
# np.array([1, 1, 0], dtype=np.float32), program_id)
|
|
|
|
# render(program_id, projMatrix, temp, 0, 0, -10)
|
|
|
|
# ry += 0.05
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
glUseProgram(program2_id)
|
|
|
|
check_error("Renderingprogram is not initialized!")
|
|
|
|
|
|
|
|
texID = glGetUniformLocation(program2_id, "Tex")
|
|
|
|
glActiveTexture(GL_TEXTURE0)
|
|
|
|
glBindTexture(GL_TEXTURE_2D, l.DepthBuffer)
|
|
|
|
glUniform1i(texID, 0)
|
|
|
|
|
|
|
|
glBindVertexArray(vai2)
|
|
|
|
glDrawArrays(GL_TRIANGLES, 0, 6)
|
|
|
|
check_error("Rendering problem")
|
2020-07-19 10:41:08 +02:00
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
glBindVertexArray(0)
|
|
|
|
glUseProgram(0)
|
|
|
|
glFlush()
|
|
|
|
|
|
|
|
glutSwapBuffers()
|
|
|
|
global rx
|
2020-07-19 10:41:08 +02:00
|
|
|
# rx += 0.025
|
2017-08-27 12:51:26 +02:00
|
|
|
global ry
|
|
|
|
glutPostRedisplay()
|
|
|
|
return
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
cx = 0
|
|
|
|
cy = 0
|
|
|
|
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
# def display2():
|
|
|
|
# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
# global l
|
|
|
|
# l.prepareForDepthMapping()
|
|
|
|
# glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
|
|
|
|
#
|
|
|
|
# newMat = orthogonalMatrix(10, -10, 10, -10, 20, 0.01) * lookAt(-cx, -cy, 1, 0, 0, 0, 0, 1, 0) * np.identity(4)
|
|
|
|
# newMat = translate(5, 0, -10) * lookAt(-5, 0, 10, 0, 0, 0, 0, 1, 0) * projMatrix
|
|
|
|
# oldMat = rotate(0, -0.5, 0, True) * projMatrix
|
|
|
|
# glUseProgram(program3_id)
|
|
|
|
# widthid = glGetUniformLocation(program3_id, 'width')
|
|
|
|
# heightid = glGetUniformLocation(program3_id, 'height')
|
|
|
|
# nearid = glGetUniformLocation(program3_id, 'near')
|
|
|
|
# farid = glGetUniformLocation(program3_id, 'far')
|
|
|
|
# glUniform1f(nearid, 0.01)
|
|
|
|
# glUniform1f(farid, 100)
|
|
|
|
# glUniform1f(widthid, width)
|
|
|
|
# glUniform1f(heightid, height)
|
|
|
|
# render(program3_id, newMat, vai, 0, 0, 0)
|
|
|
|
# glFlush()
|
|
|
|
# l.finishDepthMapping()
|
|
|
|
#
|
|
|
|
# glUseProgram(program2_id)
|
|
|
|
# check_error("Renderingprogram is not initialized!")
|
|
|
|
#
|
|
|
|
# texID = glGetUniformLocation(program2_id, "Tex")
|
|
|
|
# glActiveTexture(GL_TEXTURE0)
|
|
|
|
# glBindTexture(GL_TEXTURE_2D, l.DepthBuffer)
|
|
|
|
# glUniform1i(texID, 0)
|
|
|
|
#
|
|
|
|
# glBindVertexArray(vai3)
|
|
|
|
# glDrawArrays(GL_TRIANGLES, 0, 6)
|
|
|
|
# check_error("Rendering problem")
|
|
|
|
# glBindVertexArray(0)
|
|
|
|
# glUseProgram(0)
|
|
|
|
# glFlush()
|
|
|
|
# glutSwapBuffers()
|
|
|
|
# glutPostRedisplay()
|
|
|
|
|
|
|
|
|
|
|
|
def resize(w, h):
|
|
|
|
w = max(w, 1)
|
|
|
|
h = max(h, 1)
|
|
|
|
glViewport(0, 0, w, h)
|
2017-08-27 12:51:26 +02:00
|
|
|
global projMatrix
|
2020-07-19 10:41:08 +02:00
|
|
|
projMatrix = perspectiveMatrix(45.0, float(w) / float(h), 0.01, 100.0)
|
2017-08-27 12:51:26 +02:00
|
|
|
global width, height
|
|
|
|
width = w
|
|
|
|
height = h
|
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
def keyboardHandler(key: int, x: int, y: int):
|
2017-08-27 12:51:26 +02:00
|
|
|
if key == b'\x1b':
|
|
|
|
exit()
|
2020-07-19 10:41:08 +02:00
|
|
|
global rx
|
|
|
|
global cx
|
|
|
|
global cy
|
|
|
|
global opening
|
2017-08-27 12:51:26 +02:00
|
|
|
|
|
|
|
if key == b'+':
|
|
|
|
rx += 0.25
|
|
|
|
if key == b'-':
|
|
|
|
rx -= 0.25
|
|
|
|
|
|
|
|
if key == b'w':
|
|
|
|
cy += 0.25
|
|
|
|
if key == b's':
|
|
|
|
cy -= 0.25
|
|
|
|
|
|
|
|
if key == b'a':
|
|
|
|
cx -= 0.25
|
|
|
|
if key == b'd':
|
|
|
|
cx += 0.25
|
|
|
|
|
|
|
|
if key == b'q':
|
|
|
|
opening -= 0.25
|
|
|
|
if key == b'e':
|
|
|
|
opening += 0.25
|
|
|
|
|
|
|
|
if key == b'r':
|
2020-07-19 10:41:08 +02:00
|
|
|
print(cx, cy, opening)
|
2017-08-27 12:51:26 +02:00
|
|
|
glutPostRedisplay()
|
2020-07-19 10:41:08 +02:00
|
|
|
# print(key,x,y)
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
|
|
|
|
def funcKeydHandler(key: int, x: int, y: int):
|
2017-08-27 12:51:26 +02:00
|
|
|
if key == 11:
|
|
|
|
glutFullScreenToggle()
|
2020-07-19 10:41:08 +02:00
|
|
|
# print(key)
|
|
|
|
|
2017-08-27 12:51:26 +02:00
|
|
|
|
2020-07-19 10:41:08 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
rx = 0
|
|
|
|
ry = 0
|
|
|
|
main()
|