当前位置: 首页>>代码示例>>Golang>>正文


Golang glfw.GetTime函数代码示例

本文整理汇总了Golang中github.com/go-gl/glfw/v3/1/glfw.GetTime函数的典型用法代码示例。如果您正苦于以下问题:Golang GetTime函数的具体用法?Golang GetTime怎么用?Golang GetTime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了GetTime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Loop

func (wnd *Window) Loop() {
	for !wnd.Closed() {
		t := glfw.GetTime()
		dt := float32(t - wnd.lastFrameTime)
		wnd.lastFrameTime = t

		UpdateMouse(dt)
		if MouseDown(MouseButton1) {
			wnd.LockCursor()
		} else {
			wnd.ReleaseCursor()
		}

		if wnd.updateCb != nil {
			wnd.updateCb(dt)
		}

		if wnd.renderCb != nil {
			wnd.renderCb(wnd, dt)
		}

		wnd.EndFrame()
		if wnd.maxFrameTime > 0 {
			elapsed := glfw.GetTime() - t
			dur := wnd.maxFrameTime - elapsed
			time.Sleep(time.Duration(dur) * time.Second)
		}
	}
}
开发者ID:johanhenriksson,项目名称:goworld,代码行数:29,代码来源:window.go

示例2: Run

func Run(g *Game) error {
	if g.Scene == nil {
		return fmt.Errorf("Scene property of given Game struct is empty")
	}

	// GLFW event handling must run on the main OS thread
	runtime.LockOSThread()
	if err := glfw.Init(); err != nil {
		return fmt.Errorf("glfw.Init failed: %s", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.ContextVersionMajor, OpenGLVerMinor)
	glfw.WindowHint(glfw.ContextVersionMinor, OpenGLVerMinor)

	glfw.WindowHint(glfw.Resizable, glfw.False)
	if g.Resizable {
		glfw.WindowHint(glfw.Resizable, glfw.True)
	}

	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	window, err := glfw.CreateWindow(int(g.Width), int(g.Height), g.Title, nil, nil)
	if err != nil {
		return fmt.Errorf("glfw.CreateWindow failed: %s", err)
	}
	window.MakeContextCurrent()

	// Initialize Glow
	if err := gl.Init(); err != nil {
		return fmt.Errorf("gl.Init failed:", err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	log.Println("gl.Init successful, OpenGL version:", version)

	var previousTime, deltaTime, time float32
	previousTime = float32(glfw.GetTime()) - 1.0/60.0

	g.Scene.Setup()

	for !window.ShouldClose() {
		time = float32(glfw.GetTime())
		deltaTime = time - previousTime

		glfw.PollEvents()

		gl.ClearColor(0.2, 0.3, 0.3, 0.5)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		g.Scene.Update(deltaTime)
		g.Scene.Draw(deltaTime)
		previousTime = time

		window.SwapBuffers()
	}

	return nil
}
开发者ID:vinzBad,项目名称:grid,代码行数:60,代码来源:grid.go

示例3: StartLoop

//
// Start Loop
// this starts the event loop which runs until the program ends
//
func (glw *Glw) StartLoop() {
	optimalTime := 1000.0 / float64(glw.fps)
	previousTime := glfw.GetTime()

	// If the Window is open keep looping
	for !glw.GetWindow().ShouldClose() {
		// Update
		time := glfw.GetTime()
		elapsed := time - previousTime
		delta := elapsed / optimalTime
		previousTime = time

		// Calls the Render Callback
		glw.renderer(glw, delta)

		// Triggers window refresh
		glw.GetWindow().SwapBuffers()

		// Triggers events
		glfw.PollEvents()
	}

	// Called at the end of the program, and terminates the window system
	glw.Terminate()
}
开发者ID:YagoCarballo,项目名称:Go-GL-Assignment-2,代码行数:29,代码来源:wrapper.go

示例4: StartFrame

// StartFrame sets everything up to start rendering a new frame.
// This includes swapping in last rendered buffer, polling for window events,
// checkpointing cursor tracking, and updating the time since last frame.
func (w *Window) StartFrame() {
	// swap in the previous rendered buffer
	w.glfw.SwapBuffers()

	// poll for UI window events
	glfw.PollEvents()

	if w.inputManager.IsActive(PROGRAM_QUIT) {
		w.glfw.SetShouldClose(true)
	}

	// base calculations of time since last frame (basic program loop idea)
	// For better advanced impl, read: http://gafferongames.com/game-physics/fix-your-timestep/
	curFrameTime := glfw.GetTime()

	if w.firstFrame {
		w.lastFrameTime = curFrameTime
		w.firstFrame = false
	}

	w.dTime = curFrameTime - w.lastFrameTime
	w.lastFrameTime = curFrameTime

	w.inputManager.CheckpointCursorChange()
}
开发者ID:cstegel,项目名称:opengl-samples-golang,代码行数:28,代码来源:window.go

示例5: RunVisualization

// Runs the visualization with a set of DelayedNoteData. The DelayedNote data is
// used to push information to the synth as well as represent the data visually.
func RunVisualization(notes *synth.NoteArrangement, oNoteChannel chan synth.DelayedNoteData) error {
	window, assets, err := initialize()
	if err != nil {
		return err
	}
	defer destroy(window, assets)

	// The main update loop.
	ct, lt, dt := 0.0, 0.0, 0.0
	for !window.ShouldClose() {
		// Keeping the current time.
		lt = ct
		ct = glfw.GetTime()
		dt = ct - lt

		// Real render loop.
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		if config.DebugMode {
			glErr := gl.GetError()
			if glErr != gl.NO_ERROR {
				fmt.Printf("OpenGL error: %d\n", glErr)
			}
		}

		window.SwapBuffers()
		glfw.PollEvents()

		if dt < 1/1000.0 {
			// Delay the thread to keep up w/ updating?
		}
	}

	return nil
}
开发者ID:crockeo,项目名称:go-tuner,代码行数:37,代码来源:main.go

示例6: GetVAO

func (s *Sprite) GetVAO() (VAO uint32) {

	gl.GenVertexArrays(1, &VAO)
	gl.BindVertexArray(VAO)

	gl.GenBuffers(1, &s.vbo)
	gl.BindBuffer(gl.ARRAY_BUFFER, s.vbo)

	gl.BufferData(gl.ARRAY_BUFFER, len(s.vertexData)*4, gl.Ptr(&s.vertexData[0]), gl.STATIC_DRAW)

	attrib_loc := uint32(gl.GetAttribLocation(s.program, gl.Str("vert\x00")))
	color_loc := uint32(gl.GetAttribLocation(s.program, gl.Str("vertColor\x00")))
	gl.EnableVertexAttribArray(attrib_loc)
	gl.VertexAttribPointer(attrib_loc, 3, gl.FLOAT, false, int32(unsafe.Sizeof(s.vertexData[0]))*7, nil)

	gl.EnableVertexAttribArray(color_loc)
	gl.VertexAttribPointer(color_loc, 4, gl.FLOAT, false, int32(unsafe.Sizeof(s.vertexData[0]))*7, gl.PtrOffset(3*4))

	time_loc := gl.GetUniformLocation(s.program, gl.Str("time\x00"))

	gl.Uniform1f(time_loc, s.runtime)

	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	gl.BindVertexArray(0)

	//Update
	time := glfw.GetTime()
	elapsed := float32(time) - s.previousTime
	s.previousTime = float32(time)
	s.runtime = s.runtime + elapsed
	return
}
开发者ID:Ozzadar,项目名称:golang-vr-opengl-engine,代码行数:33,代码来源:engine.go

示例7: Step

func (d *Director) Step() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	timestamp := glfw.GetTime()
	dt := timestamp - d.timestamp
	d.timestamp = timestamp
	if d.view != nil {
		d.view.Update(timestamp, dt)
	}
}
开发者ID:cherrybob,项目名称:nes,代码行数:9,代码来源:director.go

示例8: drawScene

func drawScene(w *glfw.Window) {
	width, height := w.GetFramebufferSize()
	ratio := float32(width) / float32(height)
	var x1, x2, y1, y2 float32
	if ratio > 1 {
		x1, x2, y1, y2 = -ratio, ratio, -1, 1
	} else {
		x1, x2, y1, y2 = -1, 1, -1/ratio, 1/ratio
	}

	gl.Viewport(0, 0, int32(width), int32(height))
	gl.Clear(gl.COLOR_BUFFER_BIT)

	// Applies subsequent matrix operations to the projection matrix stack
	gl.MatrixMode(gl.PROJECTION)

	gl.LoadIdentity()                                                   // replace the current matrix with the identity matrix
	gl.Ortho(float64(x1), float64(x2), float64(y1), float64(y2), 1, -1) // multiply the current matrix with an orthographic matrix

	// Applies subsequent matrix operations to the modelview matrix stack
	gl.MatrixMode(gl.MODELVIEW)

	gl.LoadIdentity()

	gl.LineWidth(1)
	gl.Begin(gl.LINE)   // delimit the vertices of a primitive or a group of like primitives
	gl.Color3f(0, 0, 0) // set the current color
	gl.Vertex3f(0, y1, 0)
	gl.Vertex3f(0, y2, 0)
	gl.Vertex3f(x1, 0, 0)
	gl.Vertex3f(x2, 0, 0)
	gl.End()

	gl.Rotatef(float32(glfw.GetTime()*50), 0, 0, 1) // multiply the current matrix by a rotation matrix

	s := float32(.95)

	gl.Begin(gl.TRIANGLES)
	gl.Color3f(1, 0, 0)  // set the current color
	gl.Vertex3f(0, s, 0) // specify a vertex
	gl.Color3f(0, 1, 0)
	gl.Vertex3f(s*.866, s*-0.5, 0)
	gl.Color3f(0, 0, 1)
	gl.Vertex3f(s*-.866, s*-0.5, 0)
	gl.End()

	gl.LineWidth(5)
	gl.Begin(gl.LINE_LOOP)
	for i := float64(0); i < 2*math.Pi; i += .05 {
		r, g, b := hsb2rgb(float32(i/(2*math.Pi)), 1, 1)
		gl.Color3f(r, g, b)
		gl.Vertex3f(s*float32(math.Sin(i)), s*float32(math.Cos(i)), 0)
	}
	gl.End()

}
开发者ID:rdterner,项目名称:gl,代码行数:56,代码来源:demo.go

示例9: CreateRenderer

func CreateRenderer(windowWidth, windowHeight int) *Renderer {

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	// defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	if windowWidth == 0 && windowHeight == 0 {
		windowWidth, windowHeight = glfw.GetPrimaryMonitor().GetPhysicalSize()
	}
	fmt.Println("Window Width -", windowWidth, "Window Height -", windowHeight)
	window, err := glfw.CreateWindow(windowWidth, windowHeight, "Karma", glfw.GetPrimaryMonitor(), nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.SetKeyCallback(testCallback)

	// Initialize Glow
	if err := gl.Init(); err != nil {
		panic(err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)

	shaders := Shaders{}

	textureFlatUniforms := []string{"projection", "camera", "modelView", "tex"}
	textureFlatAttributes := []string{"vert", "vertTexCoord"}

	fmt.Println(textureFlatUniforms)
	fmt.Println(textureFlatAttributes)

	shader, err := createProgram("./assets/shaders/texture_flat.vs", "./assets/shaders/texture_flat.fs", textureFlatUniforms, textureFlatAttributes)
	if err != nil {
		panic(err)
	}
	shaders.textureFlat = shader

	meshes := []*Mesh{}

	previousTime := glfw.GetTime()

	return &Renderer{
		PreviousTime: previousTime,
		Window:       window,
		Shaders:      &shaders,
		Meshes:       meshes,
	}
}
开发者ID:wmiller848,项目名称:karma,代码行数:56,代码来源:core.go

示例10: SetView

func (d *Director) SetView(view View) {
	if d.view != nil {
		d.view.Exit()
	}
	d.view = view
	if d.view != nil {
		d.view.Enter()
	}
	d.timestamp = glfw.GetTime()
}
开发者ID:cherrybob,项目名称:nes,代码行数:10,代码来源:director.go

示例11: Render

//Render takes a texture and feed it to the fragment shader as a fullscreen texture. It will call the next post process pass if there is one.
func (ppfb *PostProcessFramebuffer) Render(t gl2.Texture2D) {
	ppfb.Prog.Use()
	ppfb.time.Uniform1f(float32(glfw.GetTime()))

	gl.ActiveTexture(gl2.TEXTURE0)
	t.Bind()
	ppfb.source.Uniform1i(0)
	Fstri()
	if ppfb.next != nil {
		ppfb.next.PreRender()
		ppfb.next.Render(ppfb.Tex)
	}
}
开发者ID:peterudkmaya11,项目名称:lux,代码行数:14,代码来源:postprocess.go

示例12: Render

func (r *Renderer) Render() {
	// defer glfw.Terminate()
	shader := r.Shaders.textureFlat
	program := shader.program
	//
	gl.UseProgram(program)
	//
	gl.BindFragDataLocation(program, 0, gl.Str("outputColor\x00"))
	// // Configure global settings
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LESS)
	gl.ClearColor(1.0, 1.0, 1.0, 1.0)

	//
	// angle += elapsed
	// r.Mesh.modelView = mgl32.HomogRotate3D(float32(angle), mgl32.Vec3{0, 1, 0})

	// Render
	// gl.UniformMatrix4fv(shader.uniforms["modelView"], 1, false, &r.Mesh.modelView[0])

	time := glfw.GetTime()
	_ = time - r.PreviousTime
	r.PreviousTime = time

	// fmt.Println(elapsed * 100)

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UniformMatrix4fv(shader.uniforms["projection"], 1, false, &r.Projection[0])
	gl.UniformMatrix4fv(shader.uniforms["camera"], 1, false, &r.Camera[0])

	// TODO : batch triangles and use multiple textures
	for _, mesh := range r.Meshes {
		gl.UniformMatrix4fv(shader.uniforms["modelView"], 1, false, &mesh.modelView[0])
		gl.Uniform1i(shader.uniforms["tex"], 0)

		gl.BindVertexArray(mesh.vao)

		gl.ActiveTexture(gl.TEXTURE0)
		gl.BindTexture(gl.TEXTURE_2D, mesh.textures[0])

		gl.DrawArrays(gl.TRIANGLES, 0, int32(len(mesh.verticies)/5))
	}

	// Maintenance
	r.Window.SwapBuffers()
	glfw.PollEvents()
	if r.Ready == false {
		r.Ready = true
	}
}
开发者ID:wmiller848,项目名称:karma,代码行数:51,代码来源:core.go

示例13: Run

// Run is runs the main engine loop
func (e *Engine) Run() {
	defer glfw.Terminate()

	previousTime := glfw.GetTime()

	for !e.window.ShouldClose() {
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

		//Update
		time := glfw.GetTime()
		elapsed := time - previousTime
		previousTime = time

		e.currentScene.Update(elapsed)

		// Render
		e.currentScene.Render()

		// Maintenance
		e.window.SwapBuffers()
		glfw.PollEvents()
	}
}
开发者ID:Ariemeth,项目名称:frame-assault-2,代码行数:24,代码来源:engine.go

示例14: onPress

func (view *MenuView) onPress(index int) {
	switch index {
	case nes.ButtonUp:
		view.j--
	case nes.ButtonDown:
		view.j++
	case nes.ButtonLeft:
		view.i--
	case nes.ButtonRight:
		view.i++
	default:
		return
	}
	view.t = glfw.GetTime()
}
开发者ID:sunclx,项目名称:nes,代码行数:15,代码来源:menuview.go

示例15: onChar

func (view *MenuView) onChar(window *glfw.Window, char rune) {
	now := glfw.GetTime()
	if now > view.typeTime {
		view.typeBuffer = ""
	}
	view.typeTime = now + typeDelay
	view.typeBuffer = strings.ToLower(view.typeBuffer + string(char))
	for index, p := range view.paths {
		_, p = path.Split(strings.ToLower(p))
		if p >= view.typeBuffer {
			view.highlight(index)
			return
		}
	}
}
开发者ID:sunclx,项目名称:nes,代码行数:15,代码来源:menuview.go


注:本文中的github.com/go-gl/glfw/v3/1/glfw.GetTime函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。