-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from harfang3d/3-2-4
3.2.4 update.
- Loading branch information
Showing
54 changed files
with
2,534 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
/resources_compiled | ||
/_bin | ||
/assetc-ubuntu-x64-2.3.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
hg.AddAssetsFolder("resources_compiled") | ||
|
||
snd_ref := hg.LoadWAVSoundAsset("sounds/metro_announce.wav") | ||
src_ref := hg.PlaySpatialized(hg.SoundRef(snd_ref), hg.NewSpatializedSourceStateWithMtxVolumeRepeat(hg.Mat4GetIdentity(), 1, hg.SRLoop)) | ||
|
||
angle := 0.0 | ||
|
||
for !hg.ReadKeyboard().Key(hg.KEscape) { | ||
dt := hg.TickClock() | ||
dt_sec_f := hg.TimeToSecF(dt) // delta frame in seconds | ||
|
||
// compute the source old and new position in world | ||
src_old_pos := hg.NewVec3WithXYZ(float32(math.Sin(angle)), 0, float32(math.Cos(angle))).MulWithK(5.0) | ||
angle += float64(hg.TimeToSecF(hg.TickClock())) * 45.0 | ||
src_new_pos := hg.NewVec3WithXYZ(float32(math.Sin(angle)), 0, float32(math.Cos(angle))).MulWithK(5.0) | ||
|
||
// source velocity in m.s-1 | ||
src_vel := (src_new_pos.Sub(src_old_pos)).DivWithK(dt_sec_f) | ||
|
||
// update source properties | ||
hg.SetSourceTransform(hg.SourceRef(src_ref), hg.TranslationMat4(src_new_pos), src_vel) | ||
} | ||
hg.AudioShutdown() | ||
hg.InputShutdown() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
snd_ref := hg.LoadWAVSoundFile("resources_compiled/sounds/metro_announce.wav") // WAV 44.1kHz 16bit mono | ||
src_ref := hg.PlayStereo(hg.SoundRef(snd_ref), hg.NewStereoSourceStateWithVolumeRepeat(1, hg.SRLoop)) | ||
|
||
angle := 0.0 | ||
|
||
for !hg.ReadKeyboardWithName("raw").Key(hg.KEscape) { | ||
angle += float64(hg.TimeToSecF(hg.TickClock())) * 0.5 | ||
hg.SetSourcePanning(hg.SourceRef(src_ref), float32(math.Sin(angle))) // panning left = -1, panning right = 1 | ||
} | ||
hg.AudioShutdown() | ||
hg.InputShutdown() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.AudioInit() | ||
|
||
src_ref := hg.StreamOGGFileStereo("resources_compiled/sounds/metro_announce.ogg", hg.NewStereoSourceStateWithVolumeRepeat(1, hg.SRLoop)) // OGG 44.1kHz 16bit mono | ||
|
||
angle := 0.0 | ||
|
||
for !hg.ReadKeyboardWithName("raw").Key(hg.KEscape) { | ||
angle += float64(hg.TimeToSecF(hg.TickClock())) * 0.5 | ||
hg.SetSourcePanning(hg.SourceRef(src_ref), float32(math.Sin(angle))) // panning left = -1, panning right = 1 | ||
} | ||
hg.AudioShutdown() | ||
hg.InputShutdown() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package main | ||
|
||
import ( | ||
"runtime" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height := int32(1280), int32(720) | ||
|
||
window := hg.RenderInitWithWindowTitleWidthHeightResetFlags("Harfang - Basic Loop", width, height, hg.RFVSync) | ||
|
||
for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(window) { | ||
hg.SetViewClearWithColDepthStencil(0, hg.CFColor|hg.CFDepth, hg.ColorGetGreen(), 1, 0) | ||
hg.SetViewRect(0, 0, 0, uint16(width), uint16(height)) | ||
|
||
hg.Touch(0) // force the view to be processed as it would be ignored since nothing is drawn to it (a clear does not count) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
runtime.GC() | ||
} | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package main | ||
|
||
import ( | ||
"math" | ||
"runtime" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
resX, resY := int32(1280), int32(720) | ||
|
||
window := hg.RenderInitWithWindowTitleWidthHeightResetFlags("Harfang - Draw Lines", resX, resY, hg.RFVSync|hg.RFMSAA4X) | ||
|
||
lineCount := int32(1000) | ||
|
||
shader := hg.LoadProgramFromFile("resources_compiled/shaders/white") | ||
|
||
// vertices | ||
vtxLayout := hg.NewVertexLayout() | ||
vtxLayout.Begin() | ||
vtxLayout.Add(hg.APosition, 3, hg.ATFloat) | ||
vtxLayout.End() | ||
|
||
vtx := hg.NewVertices(vtxLayout, lineCount*2) | ||
|
||
// main loop | ||
angle := 0.0 | ||
|
||
for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(window) { | ||
hg.SetViewClearWithColDepthStencil(0, hg.CFColor|hg.CFDepth, hg.ColorI(64, 64, 64), 1.0, 0) | ||
hg.SetViewRect(0, 0, 0, uint16(resX), uint16(resY)) | ||
|
||
vtx.Clear() | ||
for i := 0.0; i < float64(lineCount); i++ { | ||
vtx.Begin(int32(2 * i)).SetPos(hg.NewVec3WithXYZ(float32(math.Sin(angle+i*0.005)), float32(math.Cos(angle+i*0.01)), 0.0)).End() | ||
vtx.Begin(int32(2*i + 1)).SetPos(hg.NewVec3WithXYZ(float32(math.Sin(angle+i*-0.005)), float32(math.Cos(angle+i*0.005)), 0.0)).End() | ||
} | ||
|
||
hg.DrawLines(0, vtx, shader) // submit all lines in a single call | ||
|
||
angle = angle + float64(hg.TimeToSecF(hg.TickClock())) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
runtime.GC() | ||
} | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package main | ||
|
||
import ( | ||
"runtime" | ||
|
||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
width, height := int32(1280), int32(720) | ||
window := hg.RenderInitWithWindowTitleWidthHeightResetFlags("Harfang - Starfield", width, height, hg.RFVSync|hg.RFMSAA4X) | ||
|
||
// vertex layout | ||
vtxLayout := hg.NewVertexLayout() | ||
vtxLayout.Begin() | ||
vtxLayout.Add(hg.APosition, 3, hg.ATFloat) | ||
vtxLayout.Add(hg.AColor0, 3, hg.ATFloat) | ||
vtxLayout.End() | ||
|
||
// simple shader program | ||
shader := hg.LoadProgramFromFile("resources_compiled/shaders/pos_rgb") | ||
|
||
// initialize stars | ||
starfieldSize := float32(10.0) | ||
|
||
maxStars := 1000 | ||
vtx := hg.NewVertices(vtxLayout, int32(maxStars*2)) | ||
|
||
var stars []*hg.Vec3 | ||
for i := 0; i < maxStars; i++ { | ||
stars = append(stars, hg.RandomVec3(-starfieldSize, starfieldSize)) | ||
} | ||
|
||
for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(window) { | ||
hg.SetViewClearWithColDepthStencil(0, hg.CFColor|hg.CFDepth, hg.ColorGetBlack(), 1.0, 0) | ||
hg.SetViewRect(0, 0, 0, uint16(width), uint16(height)) | ||
|
||
dt := hg.TickClock() | ||
dt_f := hg.TimeToSecF(dt) | ||
|
||
// update stars | ||
vtx.Clear() | ||
for i, star := range stars { | ||
star.SetZ(star.GetZ() - float32(2.0*dt_f)) | ||
if star.GetZ() < starfieldSize { | ||
star.SetZ(star.GetZ() + starfieldSize) | ||
} | ||
|
||
// draw stars | ||
vtx.Begin(int32(2 * i)).SetPos(star.Mul(hg.NewVec3WithXYZ(1.0/star.GetZ(), 1.0/star.GetZ(), 0.0))).SetColor0(hg.ColorGetBlack()).End() | ||
vtx.Begin(int32(2*i + 1)).SetPos(star.Mul(hg.NewVec3WithXYZ(1.04/star.GetZ(), 1.04/star.GetZ(), 0.0))).SetColor0(hg.ColorGetWhite()).End() | ||
} | ||
|
||
hg.DrawLines(0, vtx, shader) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
runtime.GC() | ||
} | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package main | ||
|
||
import ( | ||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
resX, resY := int32(1280), int32(720) | ||
|
||
window := hg.RenderInitWithWindowTitleWidthHeightResetFlags("Harfang - Draw Models no Pipeline", resX, resY, hg.RFVSync|hg.RFMSAA4X) | ||
|
||
// vertex layout and models | ||
vtxLayout := hg.VertexLayoutPosFloatNormUInt8() | ||
|
||
cubeMdl := hg.CreateCubeModel(vtxLayout, 1, 1, 1) | ||
groundMdl := hg.CreatePlaneModel(vtxLayout, 5, 5, 1, 1) | ||
|
||
shader := hg.LoadProgramFromFile("resources_compiled/shaders/mdl") | ||
|
||
// main loop | ||
angle := float32(0.0) | ||
|
||
for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(window) { | ||
dt := hg.TickClock() | ||
angle = angle + hg.TimeToSecF(dt) | ||
|
||
viewpoint := hg.TranslationMat4(hg.NewVec3WithXYZ(0, 1, -3)) | ||
hg.SetViewPerspective(0, 0, 0, resX, resY, viewpoint) | ||
|
||
hg.DrawModelWithSliceOfValuesSliceOfTextures(0, cubeMdl, shader, hg.GoSliceOfUniformSetValue{}, hg.GoSliceOfUniformSetTexture{}, hg.TransformationMat4(hg.NewVec3WithXYZ(0.0, 1, 0.0), hg.NewVec3WithXYZ(angle, angle, angle))) | ||
hg.DrawModelWithSliceOfValuesSliceOfTextures(0, groundMdl, shader, hg.GoSliceOfUniformSetValue{}, hg.GoSliceOfUniformSetTexture{}, hg.TranslationMat4(hg.NewVec3WithXYZ(0.0, 0.0, 0.0))) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(window) | ||
} | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(window) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
hg "github.com/harfang3d/harfang-go/v3" | ||
) | ||
|
||
func main() { | ||
hg.InputInit() | ||
hg.WindowSystemInit() | ||
|
||
resX, resY := int32(1280), int32(720) | ||
win := hg.RenderInitWithWindowTitleWidthHeightResetFlags("Harfang - Draw Text", resX, resY, hg.RFVSync) | ||
|
||
// load font and shader program | ||
font := hg.LoadFontFromFileWithSize("resources_compiled/font/default.ttf", 96) | ||
font_prg := hg.LoadProgramFromFile("resources_compiled/core/shader/font") | ||
|
||
// text uniforms and render state | ||
text_uniform_values := hg.GoSliceOfUniformSetValue{hg.MakeUniformSetValueWithVec4V("u_color", hg.NewVec4WithXYZ(1, 1, 0))} | ||
text_render_state := hg.ComputeRenderStateWithDepthTestCulling(hg.BMAlpha, hg.DTAlways, hg.FCDisabled) | ||
|
||
// main loop | ||
for !hg.ReadKeyboard().Key(hg.KEscape) && hg.IsWindowOpen(win) { | ||
hg.SetView2DWithZnearZfarFlagsColorDepthStencil(0, 0, 0, resX, resY, -1, 1, hg.CFColor|hg.CFDepth, hg.ColorI(32, 32, 32), 0, 1) | ||
|
||
hg.DrawTextWithPosHalignValignSliceOfValuesSliceOfTexturesState(0, font, "Hello world!", font_prg, "u_tex", 0, hg.Mat4GetIdentity(), hg.NewVec3WithXYZ(float32(resX/2), float32(resY/2), 0), hg.DTHACenter, hg.DTVACenter, text_uniform_values, hg.GoSliceOfUniformSetTexture{}, text_render_state) | ||
|
||
hg.Frame() | ||
hg.UpdateWindow(win) | ||
} | ||
|
||
hg.RenderShutdown() | ||
hg.DestroyWindow(win) | ||
} |
Oops, something went wrong.