示例#1
0
文件: player.go 项目: drasich/malus
func (c ControlComponent) Update() {
	o := c.owner
	if glfw.Key('E') == glfw.KeyPress {
		o.Position.Z -= 0.1
	} else if glfw.Key('D') == glfw.KeyPress {
		o.Position.Z += 0.1
	} else if glfw.Key('S') == glfw.KeyPress {
		o.Position.X -= 0.1
	} else if glfw.Key('F') == glfw.KeyPress {
		o.Position.X += 0.1
	}
}
示例#2
0
文件: window.go 项目: glenn-brown/vu
// Render draws the contents of the window, but no more than 30
// times per second.
func (w *Window) Render() {
	// Don't render more than 30 times per second.
	t := time.Now()
	if time.Since(w.lastRender).Seconds() < 1.0/30.0 {
		return
	}
	w.lastRender = t

	// Retrieve the view width and height, in pixels.
	params := make([]int32, 4)
	gl.GetIntegerv(gl.VIEWPORT, params)

	// Infer the rendering volume from the viewport size, so the
	// the rendering code can assume that the width of a pixel is
	// ~1.0.  This is important when rendering text.  This must
	// match the gl.Frustum configuration.
	width := float64(params[2])
	height := float64(params[3])
	depth := (width + height) / 2

	// Redraw the window, but not too often.
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	w.renderer.Render(width, height, depth)
	glfw.SwapBuffers()

	// Exit if the user presses escape or the window was closed.
	if glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0 {
		os.Exit(0)
	}
}
示例#3
0
文件: glfw.go 项目: floffel03/gohorde
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()
}
示例#4
0
文件: main.go 项目: andrebq/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	// Ensure glfw is cleanly terminated on exit.
	defer glfw.Terminate()

	if err = glfw.OpenWindow(256, 256, 8, 8, 8, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	// Ensure window is cleanly closed on exit.
	defer glfw.CloseWindow()

	// Enable vertical sync on cards that support it.
	glfw.SetSwapInterval(1)

	// Set window title
	glfw.SetWindowTitle("Simple GLFW window")

	// Hook some events to demonstrate use of callbacks.
	// These are not necessary if you don't need them.
	glfw.SetWindowSizeCallback(onResize)
	glfw.SetWindowCloseCallback(onClose)
	glfw.SetMouseButtonCallback(onMouseBtn)
	glfw.SetMouseWheelCallback(onMouseWheel)
	glfw.SetKeyCallback(onKey)
	glfw.SetCharCallback(onChar)

	// Start loop
	running := true
	for running {
		// OpenGL rendering goes here.

		// Swap front and back rendering buffers. This also implicitly calls
		// glfw.PollEvents(), so we have valid key/mouse/joystick states after
		// this. This behavior can be disabled by calling glfw.Disable with the
		// argument glfw.AutoPollEvents. You must be sure to manually call
		// PollEvents() or WaitEvents() in this case.
		glfw.SwapBuffers()

		// Break out of loop when Escape key is pressed, or window is closed.
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) == 1
	}
}
示例#5
0
func (this *Listener) KeyPressed(key int) bool { //just once
	if glfw.Key(key) == glfw.KeyRelease {
		return false
	}
	_, found := this.mKeys[key]
	if !found {
		this.mKeys[key] = keyDown
		return true
	}
	if this.mKeys[key] == keyPressed {
		this.mKeys[key] = keyDown
		return true
	}
	return false
}
示例#6
0
func main() {

	flag.Parse()

	var done bool

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

	defer glfw.Terminate()

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

	if gl.Init() != 0 {
		panic("gl error")
	}

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("gears")

	glfw.SetWindowSizeCallback(reshape)

	init_()
	reshape(300, 300)
	done = false
	for !done {
		idle()
		draw()
		done = glfw.Key(glfw.KeyEsc) != 0 || glfw.WindowParam(glfw.Opened) == 0
	}

}
示例#7
0
文件: main.go 项目: skelterjohn/glfw
func main() {
	var err os.Error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Ensure glfw is cleanly terminated on exit.
	defer glfw.Terminate()

	if err = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	// Ensure window is cleanly closed on exit.
	defer glfw.CloseWindow()

	// Enable vertical sync on cards that support it.
	glfw.SetSwapInterval(1)

	// Set window title
	glfw.SetWindowTitle("Simple GLFW window")

	running := true
	for running {
		// OpenGL rendering goes here.

		// Swap front and back rendering buffers. This also implicitly calls
		// glfw.PollEvents(), so we have valid key/mouse/joystick states after
		// this. This behavior can be disabled by calling glfw.Disable with the
		// argument glfw.AutoPollEvents. You must be sure to manually call
		// PollEvents() or WaitEvents() in this case.
		glfw.SwapBuffers()

		// Break out of loop when Escape key is pressed, or window is closed.
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) == 1
	}
}
示例#8
0
func main() {
	// Initialize GLFW
	glfw.Init()
	glfw.Enable(glfw.StickyKeys)
	if !setupWindow(appWidth, appHeight, fullScreen) {
		return
	}

	// Initialize application and engine
	app = new(Application)
	if !app.init() {
		fmt.Println("Error starting Horde3d")
		horde3d.DumpMessages()
	}
	if !fullScreen {
		glfw.SetWindowTitle(app.title)
	}

	app.resize(appWidth, appHeight)

	glfw.Disable(glfw.MouseCursor)

	var frames float32 = 0
	var fps float32 = 30.0
	t0 = glfw.Time()
	running = true

	// Game loop
	for running {
		// Calc FPS
		frames++
		if frames >= 3 {
			t := glfw.Time()
			fps = frames / float32(t-t0)
			if fps < 5 {
				fps = 30 // Handle breakpoints
			}
			frames = 0
			t0 = t
		}

		// Update key states
		for i := 0; i < 320; i++ {
			app.setKeyState(i, glfw.Key(i) == glfw.KeyPress)
		}
		app.keyStateHandler()

		// Render
		app.mainLoop(fps)
		glfw.SwapBuffers()

	}

	glfw.Enable(glfw.MouseCursor)

	// Quit
	app.release()
	glfw.Terminate()

	return
}
示例#9
0
// Key returns true if the given key k is held down, or false otherwise.
func (w *window) Key(k Key) bool {
	if glfw.Key(int(k)) == glfw.KeyPress {
		return true
	}
	return false
}
示例#10
0
func (this *Listener) KeyUp(key int) bool {
	return glfw.Key(key) == glfw.KeyRelease
}
示例#11
0
func (this *Listener) KeyDown(key int) bool {
	return glfw.Key(key) == glfw.KeyPress
}
示例#12
0
文件: main.go 项目: esnowkropla/dep
func main() {
	w := 500
	h := 500
	fov := 45.0
	clip_min := 0.1
	clip_max := 1000.0

	aspect_ratio := float64(w) / float64(h)

	glfw.Init()
	glfw.OpenWindow(w, h, 8, 8, 8, 8, 8, 0, glfw.Windowed)

	glfw.SetWindowTitle("Shader Test")
	glfw.SetWindowSizeCallback(resize_window)
	glfw.SetKeyCallback(key_callback)

	gl.ClearColor(0.3, 0.3, 0.3, 1.0)
	gl.ShadeModel(gl.SMOOTH)

	size_window(w, h, fov, aspect_ratio, clip_min, clip_max)

	//Testing sprites
	test_sprite := sprite{height: 1.0, width: 1.0}
	test_sprite.tex = texture("./assets/hedge.gif")
	test_sprite.Y = 3

	new_guy := sprite{height: 0.5, width: 0.5}
	new_guy.tex = texture("./assets/red2.png")
	new_guy.Y = 5

	renderees := new(list.List)
	renderees.PushBack(&new_guy)
	renderees.PushBack(&test_sprite)

	my_camera.init(Vector{0.0, -1.0, 0.0})
	my_camera.front = Vector{0.0, 1.0, 0.0}
	my_camera.top = Vector{0.0, 0.0, 1.0}
	//End testing sprites

	physics_objects := new(list.List)
	physics_objects.PushBack(my_camera)

	dt, err := time.ParseDuration("16.67ms")
	if err != nil {
		die(err)
	}

	fmt.Println("Timestep: ", dt)
	var t float64 = 0
	running := true
	for running {
		t0 := time.Now()
		update(physics_objects, float64(dt.Nanoseconds())/1e6)
		t += 0.025
		new_guy.X = math.Cos(t)
		new_guy.Y = math.Sin(t) + 3.0

		//my_camera.point_at(Vector{new_guy.X, new_guy.Y, new_guy.Z})

		general_render(renderees, my_camera)
		glfw.SwapBuffers()

		dt = time.Since(t0)
		rate := time.Microsecond * 16670
		if dt < rate {
			time.Sleep((rate - dt))
			//fmt.Println("This frame took", float64(dt.Nanoseconds())/1000000, "ms to render.")
		}
		running = glfw.Key(glfw.KeyEsc) == 0 && glfw.WindowParam(glfw.Opened) != 0
	}
}