tubeY = math.sin(2 * math.pi * i_t / tube_size) pt = [ center[0] * (rad_circum + tubeX * rad_tube), center[1] * (rad_circum + tubeX * rad_tube), tubeY * rad_tube ] nv = [ pt[0] - center[0] * rad_tube, pt[1] - center[1] * rad_tube, tubeY * rad_tube ] torus_pts.extend(pt) torus_nv.extend(nv) torus_col.extend(col) i_cn = (i_c + 1) % circum_size i_tn = (i_t + 1) % tube_size i_c0 = i_c * tube_size i_c1 = i_cn * tube_size torus_inx.extend([ i_c0 + i_t, i_c0 + i_tn, i_c1 + i_t, i_c0 + i_tn, i_c1 + i_t, i_c1 + i_tn ]) torusVAO = vertex.VAObject([(3, torus_pts), (3, torus_nv), (3, torus_col)], torus_inx) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/blinn_phong.vert', GL_VERTEX_SHADER), ('resource/shader/blinn_phong.frag', GL_FRAGMENT_SHADER) ]) # start main loop wnd.Run()
cache.AddVertex(icosVertices, (-1, t, 0)) cache.AddVertex(icosVertices, (1, t, 0)) cache.AddVertex(icosVertices, (-1, -t, 0)) cache.AddVertex(icosVertices, (1, -t, 0)) cache.AddVertex(icosVertices, (0, -1, t)) cache.AddVertex(icosVertices, (0, 1, t)) cache.AddVertex(icosVertices, (0, -1, -t)) cache.AddVertex(icosVertices, (0, 1, -t)) cache.AddVertex(icosVertices, (t, 0, -1)) cache.AddVertex(icosVertices, (t, 0, 1)) cache.AddVertex(icosVertices, (-t, 0, -1)) cache.AddVertex(icosVertices, (-t, 0, 1)) icosIndices = [ 0, 11, 5, 0, 5, 1, 0, 1, 7, 0, 7, 10, 0, 10, 11, 1, 5, 9, 5, 11, 4, 11, 10, 2, 10, 7, 6, 7, 1, 8, 3, 9, 4, 3, 4, 2, 3, 2, 6, 3, 6, 8, 3, 8, 9, 4, 9, 5, 2, 4, 11, 6, 2, 10, 8, 6, 7, 9, 8, 1 ] splitCount = 2 for i in range(0, splitCount): icosIndices = cache.Split(icosVertices, icosIndices) icosahedronVAO = vertex.VAObject([(3, icosVertices)], icosIndices) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/icosahedron.vert', GL_VERTEX_SHADER), ('resource/shader/icosahedron.frag', GL_FRAGMENT_SHADER) ]) # start main loop wnd.Run()
for inx_p in range(0, 4): for inx_s in range(0, 3): nv[inx_s] += cubePts[ cubeHlpInx[inx_nv*4 + inx_p] ][inx_s] AddToBuffer( cubeNVData, nv, 4 ) cubeColData = [] for inx_col in range(0, 6): AddToBuffer( cubeColData, cubeCol[inx_col % len(cubeCol)], 4 ) cubeUVData = [] for inx in range(0, 6): cubeUVData += [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0] cubeTVData = [] for inx_tv in range(0, len(cubeHlpInx) // 4): p0 = cubePts[ cubeHlpInx[inx_tv*4 + 0 ]] p1 = cubePts[ cubeHlpInx[inx_tv*4 + 1 ]] tv = [p1[0]-p0[0], p1[1]-p0[1], p1[2]-p0[2]] AddToBuffer( cubeTVData, tv, 4 ) cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 0, 2, 3]: cubeIndices.append( inx * 4 + inx_s ) cubeVAO = vertex.VAObject( [ (3, cubePosData), (3, cubeNVData), (3, cubeTVData), (3, cubeColData), (2, cubeUVData) ], cubeIndices ) # load, compile and link shader progDraw = shader.ShaderProgram( [ ('resource/shader/cube_normalmap.vert', GL_VERTEX_SHADER), ('resource/shader/cube_normalmap.frag', GL_FRAGMENT_SHADER) ] ) #texture objects texObj = ReadTexture('../../resource/texture/test1_texture.bmp', 0) nmTexObj = texObj = ReadTexture('../../resource/texture/test1_normalmap.bmp', 1); # start main loop wnd.Run()
cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 0, 2, 3]: cubeIndices.append(inx * 4 + inx_s) cubeVAO = vertex.MeshBuffer() cubeVAO.DefineVA([ ([(0, 3, 0)], 0, cubePosData), ([(1, 3, 0)], 0, cubeNVData), ([(2, 3, 0)], 0, cubeColData), ([(3, 2, 0)], 0, cubeUVData), ]) cubeVAO.DefineIB(cubeIndices) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/displacement_map.vert', GL_VERTEX_SHADER), ('resource/shader/displacement_map.frag', GL_FRAGMENT_SHADER) ]) #texture objects textureObj = CreateTextureFromFile( '../../../../resource/texture/example_1_texture.bmp', 0) displacementmapObj = CreateHeightMapFromFile( '../../../../resource/texture/example_1_heightmap.bmp', 1) # start main loop wnd.Run() # clean up del cubeVAO
for inx_s in range(0, 3): nv[inx_s] += cubePts[cubeHlpInx[inx_nv * 4 + inx_p]][inx_s] AddToBuffer(cubeNVData, nv, 4) cubeColData = [] for inx_col in range(0, 6): AddToBuffer(cubeColData, cubeCol[inx_col % len(cubeCol)], 4) cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 0, 2, 3]: cubeIndices.append(inx * 4 + inx_s) objVAO = vertex.VAObject([(3, cubePosData), (3, cubeNVData), (3, cubeColData)], cubeIndices) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/glow.vert', GL_VERTEX_SHADER), ('resource/shader/glow.frag', GL_FRAGMENT_SHADER) ]) progBlurX = shader.ShaderProgram([ ('resource/shader/gauss.vert', GL_VERTEX_SHADER), ('resource/shader/gaussX.frag', GL_FRAGMENT_SHADER) ]) progBlurY = shader.ShaderProgram([ ('resource/shader/gauss.vert', GL_VERTEX_SHADER), ('resource/shader/gaussY.frag', GL_FRAGMENT_SHADER) ]) # start main loop wnd.Run()
for inx_p in range(0, 4): for inx_s in range(0, 3): nv[inx_s] += cubePts[ cubeHlpInx[inx_nv*4 + inx_p] ][inx_s] AddToBuffer( cubeNVData, nv, 4 ) cubeColData = [] for inx_col in range(0, 6): AddToBuffer( cubeColData, cubeCol[inx_col % len(cubeCol)], 4 ) cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 3]: cubeIndices.append( inx * 4 + inx_s ) transformVAO = vertex.VAObject( [ (3, cubePosData), (3, cubeNVData), (3, cubeColData) ], cubeIndices, GL_PATCHES, 4 ) cubeVAO = vertex.VAObject( [ (3, cubePosData), (3, cubeNVData), (3, cubeColData) ], cubeIndices, GL_QUADS ) # load, compile and link shader progDraw = shader.ShaderProgram( [ ('resource/shader/blinn_phong.vert', GL_VERTEX_SHADER), ('resource/shader/blinn_phong.frag', GL_FRAGMENT_SHADER) ] ) print( "error:", glGetError() ) # load, compile and link transform feedback shader progTransform = shader.ShaderProgram( [ ('resource/shader/quad_triangle.vert', GL_VERTEX_SHADER), #('resource/shader/quad_triangle.tesc', GL_TESS_CONTROL_SHADER), ('resource/shader/quad_triangle.tese', GL_TESS_EVALUATION_SHADER) ], [ b"out_pos", b"out_nv", b"out_col" ], GL_INTERLEAVED_ATTRIBS ) print( "error:", glGetError() ) # create trasnform feedback buffer # https://www.opengl.org/discussion_boards/showthread.php/181664-Tessellation-with-Transform-Feedback transform_attr_size = 6*6 transform_elem_size = transform_attr_size * (3+3+3)
torus_nv.extend( nv ) torus_col.extend( col ) i_cn = (i_c+1) % circum_size i_tn = (i_t+1) % tube_size i_c0 = i_c * tube_size; i_c1 = i_cn * tube_size; torus_inx.extend( [i_c0+i_t, i_c0+i_tn, i_c1+i_t, i_c0+i_tn, i_c1+i_t, i_c1+i_tn] ) torusVAO = vertex.DrawBuffer() torusVAO.DefineVAO( [ 0, 3, 0, 0, 1, 0, 3, vertex.TYPE_float32, 0, 1, 0, 1, 1, 3, vertex.TYPE_float32, 0, 2, 0, 1, 2, 3, vertex.TYPE_float32, 0], [torus_pts, torus_nv, torus_col], torus_inx ) # load, compile and link shader progDraw = shader.ShaderProgram( [ ('resource/shader/blinn_phong.vert', GL_VERTEX_SHADER), ('resource/shader/blinn_phong.frag', GL_FRAGMENT_SHADER) ] ) progSSAO = shader.ShaderProgram( [ ('resource/shader/ssao.vert', GL_VERTEX_SHADER), ('resource/shader/ssao.frag', GL_FRAGMENT_SHADER) ] ) progBlur = shader.ShaderProgram( [ ('resource/shader/blur.vert', GL_VERTEX_SHADER), ('resource/shader/blur.frag', GL_FRAGMENT_SHADER) ] ) # start main loop wnd.Run()
materialBuffer.BindToTarget() pointVAObj.Draw() # create window rotateCamera = False wnd = MyWindow(800, 600, True) # define location vertex array opject pointVAObj = vertex.VAObject([(3, [(0.0, 0.0, 0.0)]), (3, [(0.0, 0.0, -1.0)]), (3, [(1.0, 0.0, 0.0)])], [], GL_POINTS) # load, compile and link shader progGeo = shader.ShaderProgram([ ('resource/shader/geo.vert', GL_VERTEX_SHADER), ('resource/shader/geo.geom', GL_GEOMETRY_SHADER), ('resource/shader/geo.frag', GL_FRAGMENT_SHADER) ]) # linke uniform blocks ubMaterial = uniform.UniformBlock(progGeo.Prog(), "UB_material") ubLightSource = uniform.UniformBlock(progGeo.Prog(), "UB_lightSource") ubMaterial.Link(1) ubLightSource.Link(2) # create uniform block buffers lightSourceBuffer = uniform.UniformBlockBuffer(ubLightSource) lightSourceBuffer.BindDataFloat(b'u_lightSource.ambient', [0.2, 0.2, 0.2, 1.0]) lightSourceBuffer.BindDataFloat(b'u_lightSource.diffuse', [0.2, 0.2, 0.2, 1.0]) lightSourceBuffer.BindDataFloat(b'u_lightSource.specular', [1.0, 1.0, 1.0, 1.0])
0, 1, 2, 3, 1, 5, 6, 2, 5, 4, 7, 6, 4, 0, 3, 7, 3, 2, 6, 7, 1, 0, 4, 5 ] cubePosData = [] for inx in cubeHlpInx: AddToBuffer(cubePosData, cubePts[inx]) cubeNVData = [] for inx_nv in range(0, len(cubeHlpInx) // 4): nv = [0.0, 0.0, 0.0] for inx_p in range(0, 4): for inx_s in range(0, 3): nv[inx_s] += cubePts[cubeHlpInx[inx_nv * 4 + inx_p]][inx_s] AddToBuffer(cubeNVData, nv, 4) cubeColData = [] for inx_col in range(0, 6): AddToBuffer(cubeColData, cubeCol[inx_col % len(cubeCol)], 4) cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 3]: cubeIndices.append(inx * 4 + inx_s) cubeVAO = vertex.VAObject([(3, cubePosData), (3, cubeNVData), (3, cubeColData)], cubeIndices, GL_LINES_ADJACENCY) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/blinn_phong.vert', GL_VERTEX_SHADER), ('resource/shader/quad_triangle.geom', GL_GEOMETRY_SHADER), ('resource/shader/blinn_phong.frag', GL_FRAGMENT_SHADER) ]) # start main loop wnd.Run()
cubeNVData = [] for inx_nv in range(0, len(cubeHlpInx) // 4): nv = [0.0, 0.0, 0.0] for inx_p in range(0, 4): for inx_s in range(0, 3): nv[inx_s] += cubePts[cubeHlpInx[inx_nv * 4 + inx_p]][inx_s] AddToBuffer(cubeNVData, nv, 4) cubeColData = [] for inx_col in range(0, 6): AddToBuffer(cubeColData, cubeCol[inx_col % len(cubeCol)], 4) cubeUVData = [] for inx in range(0, 6): cubeUVData += [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0] cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 0, 2, 3]: cubeIndices.append(inx * 4 + inx_s) cubeVAO = vertex.VAObject([(3, cubePosData), (3, cubeNVData), (3, cubeColData), (2, cubeUVData)], cubeIndices) # load, compile and link shader progDraw = shader.ShaderProgram([ ('resource/shader/cube_texture.vert', GL_VERTEX_SHADER), ('resource/shader/cube_texture.frag', GL_FRAGMENT_SHADER) ]) #texture objects texObj = ReadTexture('../../../../resource/texture/supermario.jpg', 0) # start main loop wnd.Run()
# define cube vertex array opject cubePts = [ (-1.0, -1.0, 1.0), ( 1.0, -1.0, 1.0), ( 1.0, 1.0, 1.0), (-1.0, 1.0, 1.0), (-1.0, -1.0, -1.0), ( 1.0, -1.0, -1.0), ( 1.0, 1.0, -1.0), (-1.0, 1.0, -1.0) ] cubeCol = [ [1.0, 0.0, 0.0], [1.0, 0.5, 0.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0] ] cubeHlpInx = [ 0, 1, 2, 3, 1, 5, 6, 2, 5, 4, 7, 6, 4, 0, 3, 7, 3, 2, 6, 7, 1, 0, 4, 5 ] cubePosData = [] for inx in cubeHlpInx: AddToBuffer( cubePosData, cubePts[inx] ) cubeNVData = [] for inx_nv in range(0, len(cubeHlpInx) // 4): nv = [0.0, 0.0, 0.0] for inx_p in range(0, 4): for inx_s in range(0, 3): nv[inx_s] += cubePts[ cubeHlpInx[inx_nv*4 + inx_p] ][inx_s] AddToBuffer( cubeNVData, nv, 4 ) cubeColData = [] for inx_col in range(0, 6): AddToBuffer( cubeColData, cubeCol[inx_col % len(cubeCol)], 4 ) cubeIndices = [] for inx in range(0, 6): for inx_s in [0, 1, 2, 3]: cubeIndices.append( inx * 4 + inx_s ) cubeVAO = vertex.VAObject( [ (3, cubePosData), (3, cubeNVData), (3, cubeColData) ], cubeIndices, GL_PATCHES, 4 ) # load, compile and link shader progDraw = shader.ShaderProgram( [ ('resource/shader/blinn_phong.vert', GL_VERTEX_SHADER), #('resource/shader/quad_triangle.tesc', GL_TESS_CONTROL_SHADER), ('resource/shader/quad_triangle.tese', GL_TESS_EVALUATION_SHADER), ('resource/shader/blinn_phong.frag', GL_FRAGMENT_SHADER) ] ) # start main loop wnd.Run()
icoPosData = [] for inx in icoIndices: AddToBuffer(icoPosData, icoPts[inx]) icoNVData = [] for inx_nv in range(0, len(icoIndices) // 3): nv = [0.0, 0.0, 0.0] for inx_p in range(0, 3): for inx_s in range(0, 3): nv[inx_s] += icoPts[icoIndices[inx_nv * 3 + inx_p]][inx_s] AddToBuffer(icoNVData, nv, 3) icoVAO = vertex.VAObject([(3, icoPosData), (3, icoNVData)], [], GL_PATCHES, 3) # load, compile and link shader progTess = shader.ShaderProgram([ ('resource/shader/tess.vert', GL_VERTEX_SHADER), ('resource/shader/tess.tesc', GL_TESS_CONTROL_SHADER), ('resource/shader/tess.tese', GL_TESS_EVALUATION_SHADER), ('resource/shader/tess.frag', GL_FRAGMENT_SHADER) ]) # linke uniform blocks ubMaterial = uniform.UniformBlock(progTess.Prog(), "UB_material") ubLightSource = uniform.UniformBlock(progTess.Prog(), "UB_lightSource") ubMaterial.Link(1) ubLightSource.Link(2) # create uniform block buffers lightSourceBuffer = uniform.UniformBlockBuffer(ubLightSource) lightSourceBuffer.BindDataFloat(b'u_lightSource.ambient', [0.2, 0.2, 0.2, 1.0]) lightSourceBuffer.BindDataFloat(b'u_lightSource.diffuse', [0.2, 0.2, 0.2, 1.0]) lightSourceBuffer.BindDataFloat(b'u_lightSource.specular', [1.0, 1.0, 1.0, 1.0])