예제 #1
0
    def __init__(self, plus):
        renderer = plus.GetRenderer()

        # create primitive index buffer
        data = hg.BinaryData()
        data.WriteInt16s([0, 1, 2, 0, 2, 3])

        self.indices = renderer.NewBuffer()
        renderer.CreateBuffer(self.indices, data, hg.GpuBufferIndex)

        # create primitive vertex buffer
        self.vertex_layout = hg.VertexLayout()
        self.vertex_layout.AddAttribute(hg.VertexPosition, 3, hg.VertexFloat)
        self.vertex_layout.AddAttribute(
            hg.VertexUV0, 2, hg.VertexUByte, True
        )  # UVs are sent as normalized 8 bit unsigned integer (range [0;255])

        data = hg.BinaryData()
        x, y = 1, 1
        data.WriteFloats([-x, -y, 0])
        data.WriteUInt8s([0, 0])

        data.WriteFloats([-x, y, 0])
        data.WriteUInt8s([0, 255])

        data.WriteFloats([x, y, 0])
        data.WriteUInt8s([255, 255])

        data.WriteFloats([x, -y, 0])
        data.WriteUInt8s([255, 0])

        self.vertex = renderer.NewBuffer()
        renderer.CreateBuffer(self.vertex, data, hg.GpuBufferVertex)
예제 #2
0
def setup():
    global uvdens_tex, uvdens_render_target, uvdens_tex_prev, uvdens_render_target_prev
    global idx, vtx, vtx_layout
    global shader, shader_set_inputs, shader_add_sources, shader_draw_uvdens, shader_lin_solve, shader_advect, shader_projectA, shader_projectB

    renderer = plus.GetRenderer()

    # create the 2 render target
    def create_tex_and_render_target():
        tex = renderer.NewTexture()
        pic = hg.Picture(size, size, hg.PictureRGBAF)
        renderer.CreateTexture(
            tex, pic, hg.TextureIsRenderTarget | hg.TextureIsShaderResource)

        render_target = renderer.NewRenderTarget()
        renderer.CreateRenderTarget(render_target)
        renderer.SetRenderTargetColorTexture(render_target, tex)

        return tex, render_target

    uvdens_tex, uvdens_render_target = create_tex_and_render_target()
    uvdens_tex_prev, uvdens_render_target_prev = create_tex_and_render_target()

    # Create index buffer
    data = hg.BinaryData()
    data.WriteInt16s([0, 1, 2, 0, 2, 3])
    idx = renderer.NewBuffer()
    renderer.CreateBuffer(idx, data, hg.GpuBufferIndex)

    # Create vertex buffer
    vtx_layout = hg.VertexLayout()
    vtx_layout.AddAttribute(hg.VertexPosition, 3, hg.VertexFloat)
    vtx_layout.AddAttribute(hg.VertexUV0, 2, hg.VertexUByte)

    data = hg.BinaryData()
    x, y = 1, 1
    data.WriteFloats([-x, -y, 0.5])
    data.WriteUInt8s([0, 0])
    data.WriteFloats([-x, y, 0.5])
    data.WriteUInt8s([0, 1])
    data.WriteFloats([x, y, 0.5])
    data.WriteUInt8s([1, 1])
    data.WriteFloats([x, -y, 0.5])
    data.WriteUInt8s([1, 0])

    vtx = renderer.NewBuffer()
    renderer.CreateBuffer(vtx, data, hg.GpuBufferVertex)

    # Load shader.
    shader = renderer.LoadShader("@assets/vel.isl")
    shader_set_inputs = renderer.LoadShader("@assets/set_inputs.isl")
    shader_add_sources = renderer.LoadShader("@assets/add_source.isl")
    shader_draw_uvdens = renderer.LoadShader("@assets/draw_uvdens.isl")
    shader_lin_solve = renderer.LoadShader("@assets/lin_solve.isl")
    shader_advect = renderer.LoadShader("@assets/advect.isl")
    shader_projectA = renderer.LoadShader("@assets/projectA.isl")
    shader_projectB = renderer.LoadShader("@assets/projectB.isl")
예제 #3
0
import harfang as hg
import math

hg.LoadPlugins()

# create a few bench objects
bench_fill_field = []
bench_polygonise = []
bench_create_geo = []

# setup iso field
w, h, d = 100, 60, 30

field = hg.BinaryData()
field.Grow(w * h * d)
for i in range(w * h * d):
	field.WriteFloat(0)

iso = hg.IsoSurface()


def draw_bench(perf_hist, color):
	size = len(perf_hist)

	while size > (257):
		perf_hist.pop(0)
		size -= 1

	k_x = 1280 / 256  # display all values on screen
	k_y = 720 / (16 * 1000)  # y goes up to 16ms
	for i in range(size - 1):
예제 #4
0
renderer = hg.CreateRenderer()
renderer.Open()

# open a new window
win = hg.NewWindow(480, 240)

# create a new output surface for the newly opened window
surface = renderer.NewOutputSurface(win)
renderer.SetOutputSurface(surface)

#  load 2d shader and retrieve variables
shader_color = renderer.LoadShader("_data/shader_2d_color.isl")
shader_texture = renderer.LoadShader("_data/shader_2d_single_texture.isl")

# create primitive index buffer
data = hg.BinaryData()
data.WriteUInt16s([0, 1, 2])

idx = renderer.NewBuffer()
renderer.CreateBuffer(idx, data, hg.GpuBufferIndex)

# create primitive vertex buffer
vtx_layout = hg.VertexLayout()
vtx_layout.AddAttribute(hg.VertexPosition, 3, hg.VertexFloat)
vtx_layout.AddAttribute(
    hg.VertexUV0, 2, hg.VertexUByte,
    True)  # UVs are sent as normalized 8 bit unsigned integer (range [0;255])

data = hg.BinaryData()

x, y = 0.5, 0.5
예제 #5
0
# Convert from any supported audio file format to a PCM file

import harfang as hg
import os

hg.LoadPlugins()

hg.MountFileDriver(hg.StdFileDriver())

# open input file as an audio data source
src = hg.GetAudioIO().Open('_data/skaven.it')

# open output file
out = hg.GetFilesystem().Open('skaven.pcm', hg.FileWrite)

pcm = hg.BinaryData()

while src.GetState() != hg.AudioDataEnded:
    # get PCM frame to the binary blob
    size, timestamp = src.GetFrame(pcm)
    # output PCM frame to the file handle
    out.Write(pcm)
    # reset the binary blob, do not free storage
    pcm.Reset()

# - or - extract all PCM data to a huge binary blob and save it to file (consumes much more memory)
"""
# extract all PCM data from the source as a binary blob
sze = hg.ExtractAudioData(src, pcm)

# save the complete PCM binary blob to a file