Пример #1
0
        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()
Пример #2
0
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()
Пример #4
0
cubePosData = []
for inx in cubeHlpInx: AddToBuffer( cubePosData, cubePts[inx] )
cubeNVData = []
for inx_nv in range(len(cubeHlpInx) // 4):
    nv = [0.0, 0.0, 0.0]
    for inx_p in range(4):
        for inx_s in range(0, 3): nv[inx_s] += cubePts[ cubeHlpInx[inx_nv*4 + inx_p] ][inx_s]
    AddToBuffer( cubeNVData, nv, 4 )
cubeColFaceData = []
for inx_col in range(6):
    for inx_c in range(0, 4): cubeColFaceData.append( cubeCol[inx_col][inx_c] )
    for inx_c in range(0, 4): cubeColFaceData.append( cubeCol[inx_col][inx_c] ) 
cubeIndices = []
for inx in range(6):
    for inx_s in [0, 1, 2, 0, 2, 3]: cubeIndices.append( inx * 4 + inx_s )
cubeVAO = vertex.VAObject( [ (3, cubePosData), (3, cubeNVData) ], cubeIndices )

# Shader Storage Buffer Object [https://www.khronos.org/opengl/wiki/Shader_Storage_Buffer_Object]
ssbo = glGenBuffers( 1 )
glBindBuffer( GL_SHADER_STORAGE_BUFFER, ssbo ) # OpenGL 4.3
glBufferData( GL_SHADER_STORAGE_BUFFER, numpy.array( cubeColFaceData, dtype=numpy.float32 ), GL_STATIC_DRAW )
glBindBufferBase( GL_SHADER_STORAGE_BUFFER, 1, ssbo )
glBindBuffer(GL_SHADER_STORAGE_BUFFER, 0)

# 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()
Пример #5
0
            buffer.append(data[inx_s])


#window.printExtensions = True
#shader.printShaderCode = shader.PrintShaderCode.ALWAYS

# create window
wnd = MyWindow(800, 600, True)

# crate framebuffer
fbX = framebuffer.FrameBuffer(800, 600, [(GL_RGBA8, GL_RGBA)], True, True,
                              False)
fbY = framebuffer.FrameBuffer(800, 600, [(GL_RGBA8, GL_RGBA)], False)

# define screenspace quad vertex array opject
quadVAO = vertex.VAObject([(2, [-1.0, -1.0, 1.0, -1.0, 1.0, 1.0, -1.0, 1.0])],
                          [0, 1, 2, 0, 2, 3])

# define tetrahedron 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):
Пример #6
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 )
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 )
Пример #7
0
        progGeo.SetUniformM44(b"u_projectionMat44", prjMat)
        progGeo.SetUniformM44(b"u_viewMat44", viewMat)
        lightSourceBuffer.BindToTarget()

        # draw point
        progGeo.SetUniformM44(b"u_modelMat44", modelMat)
        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
    AddToBuffer(planeColData, planeCol[inx_col % len(planeCol)], 4)
planeUVData = []
for inx in range(0, 6):
    planeUVData += [0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0]
planeTVData = []
for inx_tv in range(0, len(planeHlpInx) // 4):
    p0 = planePts[planeHlpInx[inx_tv * 4 + 0]]
    p1 = planePts[planeHlpInx[inx_tv * 4 + 1]]
    tv = [p1[0] - p0[0], p1[1] - p0[1], p1[2] - p0[2]]
    AddToBuffer(planeTVData, tv, 4)
planeIndices = []
for inx in range(0, 6):
    for inx_s in [0, 1, 2, 0, 2, 3]:
        planeIndices.append(inx * 4 + inx_s)
planeVAO = vertex.VAObject([(3, planePosData), (3, planeNVData),
                            (3, planeTVData), (3, planeColData),
                            (2, planeUVData)], planeIndices)

# 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_heightmap_normalmap.bmp', 1)

# start main loop
wnd.Run()
Пример #9
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()
Пример #10
0
icoIndices = [
    2, 0, 1, 3, 0, 2, 4, 0, 3, 5, 0, 4, 1, 0, 5, 11, 7, 6, 11, 8, 7, 11, 9, 8,
    11, 10, 9, 11, 6, 10, 1, 6, 2, 2, 7, 3, 3, 8, 4, 4, 9, 5, 5, 10, 1, 2, 6,
    7, 3, 7, 8, 4, 8, 9, 5, 9, 10, 1, 10, 6
]
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