Ejemplo n.º 1
0
func (t *TestSuite) TestRotatedBox() {
	filename := "expected_box_rotated_20.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)
		// Create a 100x100 pixel² box
		box := shapes.NewBox(t.renderState.boxProgram, 100, 100)
		box.AttachToWorld(world)
		// Place the box at the center of the screen
		box.MoveTo(float32(w/2), 0)
		// Rotate the box 20 degrees
		box.Rotate(20.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		box.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 2
0
func newGameState(window mandala.Window) *gameState {
	s := new(gameState)
	s.window = window

	s.window.MakeContextCurrent()

	w, h := window.GetSize()

	s.world = newWorld(w, h)

	// Create the building reading it from a string
	rand.Seed(int64(time.Now().Nanosecond()))

	// Uncomment the following lines to generate the world
	// starting from a string (defined in world.go)

	// s.world.createFromString(pyramid)
	// s.world.setGround(newGround(0, float32(10), float32(w), float32(10)))

	s.world.createFromSvg("raw/world.svg")

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	return s
}
Ejemplo n.º 3
0
func (t *TestSuite) TestScaledBox() {
	filename := "expected_box_scaled.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)
		box := shapes.NewBox(t.renderState.boxProgram, 100, 100)
		// Color is yellow
		box.SetColor(color.RGBA{0, 0, 255, 255})
		box.AttachToWorld(world)
		box.MoveTo(float32(w/2), 0)
		box.Scale(1.5, 1.5)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		box.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 4
0
func draw() {
	// Draw
	gl.ClearColor(0.9, 0.85, 0.46, 0.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	w := g.world
	w.background.Draw()
}
Ejemplo n.º 5
0
// NewGameState creates a new game state. It needs a window onto which
// render the scene.
func NewGameState(window mandala.Window) *GameState {
	s := new(GameState)
	s.window = window

	s.window.MakeContextCurrent()

	w, h := window.GetSize()

	s.World = NewWorld(w, h)

	s.Fps = DefaultFps

	// Uncomment the following lines to generate the world
	// starting from a string (defined in world.go)

	// s.World.CreateFromString(pyramid)
	// s.World.setGround(newGround(s.World, 0, float32(10), float32(w), float32(10)))

	s.World.CreateFromSvg("raw/world.svg")

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	return s
}
Ejemplo n.º 6
0
func (renderState *renderState) draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.VertexAttribPointer(attrPos, 4, gl.FLOAT, false, 6*4, &vertices[0])
	gl.VertexAttribPointer(attrTexIn, 2, gl.FLOAT, false, 6*4, &vertices[4])

	gl.ActiveTexture(gl.TEXTURE0)
	gl.BindTexture(gl.TEXTURE_2D, textureBuffer)
	gl.Uniform1i(int32(unifTexture), 0)

	gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)
	gl.Flush()
	gl.Finish()
}
Ejemplo n.º 7
0
func (s *gameState) draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	s.world.space.Step(vect.Float(1 / float32(FramesPerSecond)))

	for i := 0; i < len(s.world.boxes); i++ {
		box := s.world.boxes[i]
		if box.inViewport() {
			box.draw()
		} else {
			s.world.removeBox(box, i)
			i--
		}
	}

	s.world.ground.draw()
}
Ejemplo n.º 8
0
func (s *GameState) Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)

	s.World.space.Step(vect.Float(1 / float32(s.Fps)))

	for i := 0; i < len(s.World.boxes); i++ {
		box := s.World.boxes[i]
		if box.inViewport() {
			box.draw()
		} else {
			s.World.removeBox(box, i)
			i--
		}
	}

	s.World.ground.draw()

	s.printFPS(float32(s.World.width/2), float32(s.World.height)-25)
}
Ejemplo n.º 9
0
func (t *TestSuite) TestGroup() {
	filename := "expected_group.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)

		// Create first group, 2 small boxes
		group1 := shapes.NewGroup()
		b1 := shapes.NewBox(t.renderState.boxProgram, 20, 20)
		b1.MoveTo(30, 40)
		b2 := shapes.NewBox(t.renderState.boxProgram, 50, 50)
		b2.MoveTo(45, -25)
		b2.Rotate(20.0)
		group1.Append(b1)
		group1.Append(b2)

		// Create the main group
		group := shapes.NewGroup()
		group.Append(group1)
		group.Append(shapes.NewBox(t.renderState.boxProgram, 100, 100))

		// Get the second element of the group
		b3 := group.GetAt(1)
		b3.MoveTo(float32(w/2), 0)

		group.AttachToWorld(world)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		group.Draw()

		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 10
0
func (t *TestSuite) TestPartialTextureRotatedBox() {
	filename := "expected_box_partial_texture_rotated_20.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)

		// Create a box
		box := shapes.NewBox(t.renderState.boxProgram, 100, 100)
		box.AttachToWorld(world)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		box.MoveTo(float32(w/2), 0)

		// Add an image as a texture
		gopherTexture := world.addImageAsTexture(texFilename)

		texCoords := []float32{
			0, 0,
			0.5, 0,
			0, 0.5,
			0.5, 0.5,
		}
		box.SetTexture(gopherTexture, texCoords)

		box.Rotate(20.0)

		box.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < texDistThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 11
0
func (t *TestSuite) TestTranslatedBox() {
	filename := "expected_box_translated_10_10.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)
		// Place a box on the center of the window
		box := shapes.NewBox(t.renderState.boxProgram, 100, 100)
		box.AttachToWorld(world)
		box.MoveTo(111, 0)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		box.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 12
0
func (t *TestSuite) TestRotate() {
	filename := "expected_hello_world_rotated.png"

	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)

		// Render an "Hello World" string
		text, err := world.font.Printf("%s", "Hello World!")
		if err != nil {
			panic(err)
		}

		text.AttachToWorld(world)
		text.MoveTo(float32(world.width/2)+5, -5.0)
		text.Rotate(45)

		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		text.Draw()

		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}

	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}

	t.True(distance < distanceThreshold, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 13
0
func (t *TestSuite) TestSegment() {
	filename := "expected_line.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)
		segment := shapes.NewSegment(t.renderState.segmentProgram, 81.5, -40, 238.5, 44)

		// Color is yellow
		segment.SetColor(color.RGBA{255, 0, 0, 255})
		segment.AttachToWorld(world)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		segment.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < 0.0009, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}
Ejemplo n.º 14
0
func draw() {
	gl.ClearColor(1.0, 0.0, 0.0, 1.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
}
Ejemplo n.º 15
0
func (w *World) Draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	for _, obj := range w.objects {
		obj.Draw()
	}
}
Ejemplo n.º 16
0
func (renderState *renderState) draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
}