示例#1
0
文件: Scene.go 项目: Triangle345/GT
// Draw : wrap the openGl draw method and report fps info
func (s *BaseScene) Draw() {

	if s.update {
		// TODO: remove hard coded resolution
		// gl.BindTexture(gl.TEXTURE_2D, s.spriteSheet.textureId)
		Opengl.BindBuffers()
		s.update = false
	}

	Opengl.Draw()

	// calc fps
	if (int32(time.Now().Unix()) - s.timestart) >= 1 {
		fmt.Printf("FPS: %d \n", s.fps)
		s.fps = 0
		s.timestart = int32(time.Now().Unix())
	}

	s.fps = s.fps + 1
}
示例#2
0
文件: Scene.go 项目: xladykiller/GT
func (s *BaseScene) Draw() {

	if len(s.entities) == 0 {
		fmt.Println("No Sprites to draw.")
		return
	}

	idx := uint32(0)

	vertexInfo := &Opengl.OpenGLVertexInfo{}

	// clone := &Opengl.OpenGLVertexInfo{}
	for _, v := range s.spriteDraw {

		//TODO: move this to sprite class and use interface instead.. what if i have "shape"
		// fmt.Printf("Img name: %s\n", k)
		// glInfo := v.getGLVertexInfo()
		w, h := v.GetImageSection().GetDimensions()

		for i := 0; i < 4; i++ {
			vertexInfo.Translations = append(vertexInfo.Translations, float32(v.x), float32(v.y), 0)
			vertexInfo.Rotations = append(vertexInfo.Rotations, 0, 0, 1, v.rot)
			vertexInfo.Scales = append(vertexInfo.Scales, v.xS, v.yS, 0)
			vertexInfo.Colors = append(vertexInfo.Colors, v.r, v.g, v.b, v.a)

		}

		vertexInfo.Vertices = append(vertexInfo.Vertices, -0.5*w, 0.5*h, 1.0, 0.5*w, 0.5*h, 1.0, 0.5*w, -0.5*h, 1.0, -0.5*w, -0.5*h, 1.0)

		// TODO: maybe put this inside struct to store since this will really never change
		x, y := s.spriteSheet.GetUVFromPosition(v.GetImageSection().BottomLeft())
		vertexInfo.Uvs = append(vertexInfo.Uvs, x, y)
		x, y = s.spriteSheet.GetUVFromPosition(v.GetImageSection().BottomRight())
		vertexInfo.Uvs = append(vertexInfo.Uvs, x, y)
		x, y = s.spriteSheet.GetUVFromPosition(v.GetImageSection().TopRight())
		vertexInfo.Uvs = append(vertexInfo.Uvs, x, y)
		x, y = s.spriteSheet.GetUVFromPosition(v.GetImageSection().TopLeft())
		vertexInfo.Uvs = append(vertexInfo.Uvs, x, y)

		vertexInfo.Elements = append(vertexInfo.Elements, uint32(idx*4), uint32(idx*4+1), uint32(idx*4+2), uint32(idx*4), uint32(idx*4+2), uint32(idx*4+3))

		// glInfo.AdjustElements(idx)

		// idx += 4
		// clone.Append(glInfo)
		idx = idx + 1
	}

	// vertexInfo.Print()
	Opengl.BindBuffers(vertexInfo)

	gl.BindTexture(gl.TEXTURE_2D, s.spriteSheet.textureId)

	Opengl.Draw(vertexInfo)

	Opengl.Cleanup()

	// calc fps
	if (int32(time.Now().Unix()) - s.timestart) >= 1 {
		fmt.Printf("FPS: %d \n", s.fps)
		s.fps = 0
		s.timestart = int32(time.Now().Unix())

	}

	s.fps = s.fps + 1

}