Exemple #1
0
func main() {
	var running bool = true

	if err := glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	if err := glfw.OpenWindow(appWidth, appHeight, 8, 8, 8, 8,
		24, 8, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}
	defer glfw.CloseWindow()

	glfw.SetSwapInterval(1)
	glfw.SetWindowTitle(caption)

	if !horde3d.Init() {
		fmt.Println("Error starting Horde3D. Check Horde3d_log.html for details.")
		horde3d.DumpMessages()
		return
	}

	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)
	// Add resources
	//pipeline
	pipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/hdr.pipeline.xml", 0)

	knightRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/knight/knight.scene.xml", 0)

	//load resources paths separated by |
	horde3d.LoadResourcesFromDisk("../content")

	model := horde3d.RootNode.AddNodes(knightRes)
	model.SetTransform(0, 0, -30, 0, 0, 0, 0.1, 0.1, 0.1)

	// Add light source
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 20, 0, 0, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 50)

	//add camera
	cam = horde3d.RootNode.AddCameraNode("Camera", pipeRes)
	glfw.SetWindowSizeCallback(onResize)

	for running {

		horde3d.Render(cam)
		horde3d.FinalizeFrame()
		horde3d.DumpMessages()
		glfw.SwapBuffers()
		running = glfw.Key(glfw.KeyEsc) == 0 &&
			glfw.WindowParam(glfw.Opened) == 1
	}

	horde3d.Release()
}
Exemple #2
0
func (app *Application) init() bool {
	app.title = "Horde3D Knight Sample - Go Implementation"
	app.contentDir = "../content"
	app.keys = make([]bool, 320)
	app.prevKeys = make([]bool, 320)

	app.x = 5
	app.y = 3
	app.z = 19
	app.rx = 7
	app.ry = 15
	app.velocity = 10.0
	app.curFps = 30

	app.animTime = 0
	app.weight = 1.0
	app.cam = 0

	// Initialize engine
	if !horde3d.Init() {
		horde3d.DumpMessages()
		return false
	}

	// Set options
	horde3d.SetOption(horde3d.Options_LoadTextures, 1)
	horde3d.SetOption(horde3d.Options_TexCompression, 0)
	horde3d.SetOption(horde3d.Options_FastAnimation, 0)
	horde3d.SetOption(horde3d.Options_MaxAnisotropy, 4)
	horde3d.SetOption(horde3d.Options_ShadowMapSize, 2048)
	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)

	// Add resources
	// Pipelines
	app.hdrPipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/hdr.pipeline.xml", 0)
	app.forwardPipeRes = horde3d.AddResource(horde3d.ResTypes_Pipeline, "pipelines/forward.pipeline.xml", 0)
	// Overlays
	app.fontMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/font.material.xml", 0)
	app.panelMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/panel.material.xml", 0)
	app.logoMatRes = horde3d.AddResource(horde3d.ResTypes_Material, "overlays/logo.material.xml", 0)
	// Environment
	envRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/sphere/sphere.scene.xml", 0)
	// Knight
	knightRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "models/knight/knight.scene.xml", 0)
	knightAnim1Res := horde3d.AddResource(horde3d.ResTypes_Animation, "animations/knight_order.anim", 0)
	knightAnim2Res := horde3d.AddResource(horde3d.ResTypes_Animation, "animations/knight_attack.anim", 0)
	// Particle system
	particleSysRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph,
		"particles/particleSys1/particleSys1.scene.xml", 0)
	// Load resources
	horde3d.LoadResourcesFromDisk(app.contentDir)

	// Add scene nodes
	// Add camera
	app.cam = horde3d.RootNode.AddCameraNode("Camera", app.hdrPipeRes)
	app.cam.SetNodeParamI(horde3d.Camera_OccCullingI, 0)
	// Add environment
	env := horde3d.RootNode.AddNodes(envRes)
	env.SetTransform(0, -20, 0, 0, 0, 0, 20, 20, 20)
	// Add knight
	app.knight = horde3d.RootNode.AddNodes(knightRes)
	app.knight.SetTransform(0, 0, 0, 0, 180, 0, 0.1, 0.1, 0.1)
	horde3d.SetupModelAnimStage(app.knight, 0, knightAnim1Res, 0, "", false)
	horde3d.SetupModelAnimStage(app.knight, 1, knightAnim2Res, 0, "", false)
	// Attach particle system to hand joint
	horde3d.FindNodes(app.knight, "Bip01_R_Hand", horde3d.NodeTypes_Joint)
	hand := horde3d.GetNodeFindResult(0)
	app.particleSys = hand.AddNodes(particleSysRes)
	app.particleSys.SetTransform(0, 40, 0, 90, 0, 0, 1, 1, 1)

	// Add light source
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 15, 10, -60, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 30)
	light.SetNodeParamF(horde3d.Light_FovF, 0, 90)
	light.SetNodeParamI(horde3d.Light_ShadowMapCountI, 1)
	light.SetNodeParamF(horde3d.Light_ShadowMapBiasF, 0, 0.01)
	light.SetNodeParamF(horde3d.Light_ColorF3, 0, 1.0)
	light.SetNodeParamF(horde3d.Light_ColorF3, 1, 0.8)
	light.SetNodeParamF(horde3d.Light_ColorF3, 2, 0.7)
	light.SetNodeParamF(horde3d.Light_ColorMultiplierF, 0, 1.0)

	// Customize post processing effects
	matRes := horde3d.FindResource(horde3d.ResTypes_Material, "pipelines/postHDR.material.xml")
	horde3d.SetMaterialUniform(matRes, "hdrExposure", 2.5, 0, 0, 0)
	horde3d.SetMaterialUniform(matRes, "hdrBrightThres", 0.5, 0, 0, 0)
	horde3d.SetMaterialUniform(matRes, "hdrBrightOffset", 0.08, 0, 0, 0)
	return true
}
Exemple #3
0
func main() {
	var running bool = true
	var width int = 800
	var height int = 600
	var t float32

	if sdl.Init(sdl.INIT_VIDEO) != 0 {
		panic(sdl.GetError())
	}

	sdl.WM_SetCaption("Horde3d Go SDL Example", "")

	//set sdl video mode
	if sdl.SetVideoMode(width, height, 32, sdl.OPENGL) == nil {
		panic(sdl.GetError())
	}

	if !horde3d.Init() {
		fmt.Println("Error initializing Horde3D")
		horde3d.DumpMessages()
		return
	}

	//horde3d.SetOption(horde3d.Options_DebugViewMode, 1)
	//horde3d.SetOption(horde3d.Options_WireframeMode, 1)
	fmt.Println("Version: ", horde3d.VersionString())

	//pipeline
	pipeRes := horde3d.AddResource(horde3d.ResTypes_Pipeline, "forward.pipeline.xml", 0)
	modelRes := horde3d.AddResource(horde3d.ResTypes_SceneGraph, "platform.scene.xml", 0)

	horde3d.LoadResourcesFromDisk("../content|" +
		"../content/pipelines|" +
		"../content/models|" +
		"../content/materials|" +
		"../content/shaders|" +
		"../content/textures|" +
		"../content/animations|" +
		"../content/particles|" +
		"../content/models/platform|" +
		"../content/effects")

	//add camera
	cam := horde3d.RootNode.AddCameraNode("Camera", pipeRes)
	//Setup Camera Viewport
	cam.SetNodeParamI(horde3d.Camera_ViewportXI, 0)
	cam.SetNodeParamI(horde3d.Camera_ViewportYI, 0)
	cam.SetNodeParamI(horde3d.Camera_ViewportWidthI, width)
	cam.SetNodeParamI(horde3d.Camera_ViewportHeightI, height)

	//add model
	model := horde3d.RootNode.AddNodes(modelRes)
	model.SetTransform(0, -30, -150, 0, 0, 0, 1, 1, 1)
	//add light
	light := horde3d.RootNode.AddLightNode("Light1", 0, "LIGHTING", "SHADOWMAP")
	light.SetTransform(0, 20, 0, 0, 0, 0, 1, 1, 1)
	light.SetNodeParamF(horde3d.Light_RadiusF, 0, 150)
	light.SetNodeParamF(horde3d.Light_FovF, 0, 90)
	//horde3d.SetNodeParamI(light, horde3d.Light_ShadowMapCountI, 3)
	light.SetNodeParamF(horde3d.Light_ShadowSplitLambdaF, 0, 0.9)
	//horde3d.SetNodeParamF(light, horde3d.Light_ShadowMapBiasF, 0, 0.001)
	light.SetNodeParamF(horde3d.Light_ColorF3, 0, 1.9)
	light.SetNodeParamF(horde3d.Light_ColorF3, 1, 1.7)
	light.SetNodeParamF(horde3d.Light_ColorF3, 2, 1.75)

	for running {
		t = 0
		//increase anim time
		t = t + 10.0*(1/60)
		//process SDL events / input
		switch event := sdl.PollEvent(); event.(type) {
		case *sdl.QuitEvent:
			running = false
			break
		}
		//horde3d.SetNodeTransform(model,
		//t*10, 0, 0,
		//0, 0, 0,
		//1, 1, 1)
		horde3d.Render(cam)
		horde3d.FinalizeFrame()
		horde3d.DumpMessages()
		sdl.GL_SwapBuffers()
	}
	horde3d.Release()
	sdl.Quit()

}