Пример #1
0
func (s *Sprite) Draw(x, y, angle, scale float32, blend bool) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.COLOR_MATERIAL)
	if blend {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
	} else {
		gl.Disable(gl.BLEND)
		gl.BlendFunc(gl.ONE, gl.ZERO)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	gl.Rotatef(angle*360/(2*math.Pi), 0, 0, 1)
	gl.Scalef(scale, scale, 1)
	s.tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.Color3f(1, 1, 1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(-0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(0.5*s.width, 0.5*s.height, 0)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(-0.5*s.width, 0.5*s.height, 0)
	gl.End()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}
Пример #2
0
func (self *Font) Print(str string) {
	for _, ch := range str {
		self.textures[ch].Bind(gl.TEXTURE_2D)
		h := float32(self.height) * PIXEL_SCALE
		w := float32(self.widths[ch]) * PIXEL_SCALE
		gl.Color4ub(255, 255, 255, 255)
		gl.Begin(gl.QUADS)
		gl.TexCoord2d(0, 0)
		gl.Vertex2f(0, 0) // Bottom Left Of The Texture and Quad
		gl.TexCoord2d(1, 0)
		gl.Vertex2f(w, 0) // Bottom Right Of The Texture and Quad
		gl.TexCoord2d(1, 1)
		gl.Vertex2f(w, h) // Top Right Of The Texture and Quad
		gl.TexCoord2d(0, 1)
		gl.Vertex2f(0, h) // Top Left Of The Texture and Quad
		gl.End()
		gl.Translatef(w, 0, 0)
		self.textures[ch].Unbind(gl.TEXTURE_2D)
	}
}
Пример #3
0
func (this *App) Run() {
	fmt.Println("running")

	var done bool
	cam := camera.New()
	cam.Pos = V3(-0, 0, 3)
	cam.Dir = V3(0, -0, -1)

	pos := []float32{5.0, 5.0, 10.0, 0.0}
	gl.Lightfv(gl.LIGHT0, gl.POSITION, pos)
	gl.Enable(gl.LIGHT0)

	elapsed := 0.0
	rotateSpeed := DegToRad(100.0)
	moveSpeed := 3.0
	texture.SetDefaultTexturePaths("res/textures/", ".png")
	texture.Load("ground")
	texture.Load("ground2")
	defer texture.ClearAllData()
	tex1 := texture.Get("ground2")
	//tex2 := texture.Get("ground2")
	model.SetDefaultModelPaths("res/models/", ".obj")
	model.Load("teapot")
	model.Load("cuboid")
	model.Load("sphere")
	model.Load("bunny")
	defer model.ClearAllData()
	mod1 := model.Get("bunny") //*/

	//*
	prog1 := program.New("test", "test")
	defer prog1.Destroy()
	prog := prog1
	println(prog.InfoLog())
	var mView, mProjection, mModel *mat4.Mat4
	mModel = mat4.New() //*/

	done = false
	for !done {
		time1 := time.Now()
		this.win.ClearBuffers()
		this.win.ResetModelViewMatrix()

		//input
		if this.il.KeyDown(glfw.KeyLeft) {
			cam.RotateY(-rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyRight) {
			cam.RotateY(rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyUp) {
			cam.RotateX(-rotateSpeed * elapsed)
		}
		if this.il.KeyDown(glfw.KeyDown) {
			cam.RotateX(rotateSpeed * elapsed)
		}
		if this.il.KeyDown(KeyX) {
			cam.MoveZ(-moveSpeed * elapsed)
		}
		if this.il.KeyDown(KeyC) {
			cam.MoveZ(moveSpeed * elapsed)
		}
		if this.il.KeyPressed(KeyR) {
			prog.Reload()
			println(prog.InfoLog())
		}

		this.win.ApplyCamera(cam)
		//*
		mView = cam.Matrix()
		mProjection = this.win.ProjectionMatrix()
		mModel.SetIdentity()
		prog.SetModelMatrix(mModel)
		prog.SetViewMatrix(mView)
		prog.SetProjectionMatrix(mProjection)
		prog.UniformColor("uColor", Col(1, .1, 0.5, 1))
		prog.UniformMat4("uMat", mModel)
		prog.Use() //*/
		material.White.Use()
		//tex1.Unbind()
		mod1.Render()
		tex1.Bind2(Col(1, 1, 1, 1))
		gl.Begin(gl.TRIANGLES)
		gl.Normal3d(0, 0, 1)
		gl.TexCoord2d(11.0, 10.0)
		gl.Vertex3d(1.0, 0.0, -15.0)
		gl.TexCoord2d(0.5, 11.0)
		gl.Vertex3d(0.0, 1.0, -15.0)
		gl.TexCoord2d(0.0, 0.0)
		gl.Vertex3d(-1.0, 0.0, -15.0)
		gl.TexCoord2d(1.0, 0.0)
		gl.Vertex3d(1.0, 0.0, -5.0)
		gl.TexCoord2d(0.5, 1.0)
		gl.Vertex3d(0.0, 1.0, -5.0)
		gl.TexCoord2d(0.0, 0.0)
		gl.Vertex3d(-1.0, 0.0, -5.0)
		gl.End() //*/
		this.win.Flip()
		done = this.il.MBQuit() || this.il.KeyPressed(glfw.KeyEsc)
		elapsed = time.Since(time1).Seconds()

		printFPS()

	}
}
Пример #4
0
func GlTex2(v *vec2.Vec2)     { gl.TexCoord2d(v.X, v.Y) }