Пример #1
0
// Shouldn't have tabs nor newlines
func (o *OpenGlStream) PrintSegment(s string) {
	if s == "" {
		return
	}

	if o.BackgroundColor != nil && o.BorderColor == nil {
		gl.PushAttrib(gl.CURRENT_BIT)
		gl.Color3dv((*float64)(&o.BackgroundColor[0]))
		gl.PushMatrix()
		gl.Translated(float64(o.pos[0]), float64(o.pos[1]), 0)
		for range s {
			gl.CallList(oFontBackground)
		}
		gl.PopMatrix()
		gl.PopAttrib()
	}

	gl.TexParameterf(gl.TEXTURE_2D, gl.TEXTURE_LOD_BIAS, float32(lodBias*0.01))

	gl.Enable(gl.BLEND)
	defer gl.Disable(gl.BLEND)
	gl.Enable(gl.TEXTURE_2D)
	defer gl.Disable(gl.TEXTURE_2D)

	gl.PushMatrix()
	gl.Translated(float64(o.pos[0]), float64(o.pos[1]), 0)
	gl.ListBase(oFontBase + uint32(o.FontOptions)*96)
	gl.CallLists(int32(len(s)), gl.UNSIGNED_BYTE, gl.Ptr(&[]byte(s)[0]))
	gl.PopMatrix()

	//CheckGLError()
}
Пример #2
0
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.LoadIdentity()

	//Transform screen to keep player in middle. Added intentation to make obvious the push matrix is like a block
	gl.PushMatrix()
	// gl.Translatef((1280/2)-float32(player.x), 0, 0.0)

	// gl.Begin(gl.LINES)
	// gl.Color3f(.2, .5, .2)
	// for i := range staticLines {
	// 	x := staticLines[i].GetAsSegment().A.X
	// 	y := staticLines[i].GetAsSegment().A.Y
	// 	gl.Vertex3f(float32(x), float32(y), 0)
	// 	x = staticLines[i].GetAsSegment().B.X
	// 	y = staticLines[i].GetAsSegment().B.Y
	// 	gl.Vertex3f(float32(x), float32(y), 0)
	// }
	// gl.End()

	gl.Color4f(player.color_r, player.color_g, player.color_b, player.color_a)

	//Draw Player
	gl.PushMatrix()
	rot := player.rot
	pos_x := player.x
	pos_y := player.y

	gl.Translatef(pos_x, pos_y, 0.0)
	gl.Rotatef(float32(rot), 0, 0, 1)
	drawCircle(float64(BALL_RADIUS), 20)
	gl.PopMatrix()

	//Draw the grapple
	gl.PushMatrix()
	gl.Translatef(player.hook.x_end, player.hook.y_end, 0.0)
	drawCircle(float64(5), 5)
	gl.PopMatrix()

	//Grapple Line
	gl.LineWidth(2.5)
	gl.Color3f(1.0, 0.0, 0.0)
	gl.Begin(gl.LINES)
	gl.Vertex3f(player.x, player.y, 0.0)
	gl.Vertex3f(player.hook.x_end, player.hook.y_end, 0)
	gl.End()

	//Second Pop
	gl.PopMatrix()
}
Пример #3
0
// OpenGL draw function
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.LoadIdentity()

	player := game.Player

	//Transform screen.
	gl.PushMatrix()
	gl.Translatef((1280/2)-float32((player.Body.Position().X)), 0, 0.0)

	gl.Begin(gl.LINES)
	gl.Color3f(.2, .5, .2)
	for _, segment := range game.Level.GetChipmunkSegments() {
		x := segment.GetAsSegment().A.X
		y := segment.GetAsSegment().A.Y
		gl.Vertex3f(float32(x), float32(y), 0)
		x = segment.GetAsSegment().B.X
		y = segment.GetAsSegment().B.Y
		gl.Vertex3f(float32(x), float32(y), 0)
	}
	gl.End()

	gl.Color4f(.9, .1, 1, .9)
	// draw balls
	for _, enemy := range game.Enemies {
		gl.PushMatrix()
		pos := enemy.Body.Position()
		rot := enemy.Body.Angle() * game.DegreeConst
		gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
		gl.Rotatef(float32(rot), 0, 0, 1)
		drawCircle(float64(enemy.Radius), 60)
		gl.PopMatrix()
	}
	gl.Color4f(.3, .3, 1, .8)
	//Draw Player
	gl.PushMatrix()
	pos := player.Body.Position()
	rot := player.Body.Angle() * game.DegreeConst
	gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
	gl.Rotatef(float32(rot), 0, 0, 1)
	drawCircle(float64(player.Radius), 60)
	gl.PopMatrix()

	gl.PopMatrix()
}
Пример #4
0
func (w *MultitouchTestBoxWidget) Render() {
	colors := [...]mgl64.Vec3{
		{0 / 255.0, 140 / 255.0, 0 / 255.0},
		{0 / 255.0, 98 / 255.0, 140 / 255.0},
		{194 / 255.0, 74 / 255.0, 0 / 255.0},
		{89 / 255.0, 0 / 255.0, 140 / 255.0},
		{191 / 255.0, 150 / 255.0, 0 / 255.0},
		{140 / 255.0, 0 / 255.0, 0 / 255.0},
	}

	backgroundColor := colors[w.color]

	//borderColor := backgroundColor

	switch 1 {
	case 0:
		DrawBorderlessBox(w.pos, mgl64.Vec2{200, 200}, backgroundColor)
	case 1:
		gl.PushMatrix()
		gl.Translated(w.pos[0], w.pos[1], 0)
		gl.Color3dv(&backgroundColor[0])

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.BindBuffer(gl.ARRAY_BUFFER, w.buffer)
		gl.VertexPointer(2, gl.FLOAT, 0, nil)

		gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)

		gl.PopMatrix()
	}
}
Пример #5
0
// OpenGL draw function
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.LoadIdentity()

	gl.Begin(gl.LINES)
	gl.Color3f(.2, .2, .2)
	for i := range staticLines {
		x := staticLines[i].GetAsSegment().A.X
		y := staticLines[i].GetAsSegment().A.Y
		gl.Vertex3f(float32(x), float32(y), 0)
		x = staticLines[i].GetAsSegment().B.X
		y = staticLines[i].GetAsSegment().B.Y
		gl.Vertex3f(float32(x), float32(y), 0)
	}
	gl.End()

	gl.Color4f(.3, .3, 1, .8)
	// draw balls
	for _, ball := range balls {
		gl.PushMatrix()
		pos := ball.Body.Position()
		rot := ball.Body.Angle() * chipmunk.DegreeConst
		gl.Translatef(float32(pos.X), float32(pos.Y), 0.0)
		gl.Rotatef(float32(rot), 0, 0, 1)
		drawCircle(float64(ballRadius), 60)
		gl.PopMatrix()
	}
}
Пример #6
0
func (ctx *DrawContext) drawHud(o *orrery.Orrery, frametime time.Duration) {
	txt, size, err := ctx.createHudTexture(o, frametime)
	if err != nil {
		log.Fatalf(`can't create texture from text surface: %s`, err)
	}
	defer gl.DeleteTextures(1, &txt)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(0.0, float64(ctx.width), float64(ctx.height), 0.0, -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Clear(gl.DEPTH_BUFFER_BIT)

	gl.BindTexture(gl.TEXTURE_2D, txt)
	gl.Enable(gl.TEXTURE_2D)
	defer gl.Disable(gl.TEXTURE_2D)

	gl.Color3f(1, 1, 1)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2f(0.0, 0.0)
	gl.TexCoord2f(1, 0)
	gl.Vertex2f(float32(size[0]), 0.0)
	gl.TexCoord2f(1, 1)
	gl.Vertex2f(float32(size[0]), float32(size[1]))
	gl.TexCoord2f(0, 1)
	gl.Vertex2f(0.0, float32(size[1]))
	gl.End()

	gl.PopMatrix()
}
Пример #7
0
func drawSpinner(spinner int) {
	gl.PushMatrix()
	gl.Translated(30.5, 30.5, 0)
	gl.Rotated(float64(spinner), 0, 0, 1)
	gl.Color3d(0, 0, 0)
	gl.Rectd(-0.5, -10.5, 0.5, 10.5)
	gl.PopMatrix()
}
Пример #8
0
// general draw function
func draw() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) // CARGOCULT
	gl.PushMatrix()                                     // CARGOCULT
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)
	gl.Translated(0.0, 0.0, view_z)

	for i := range boxes {
		gl.PushMatrix() // CARGOCULT
		gl.CallList(boxes[i])
		gl.PopMatrix() // CARGOCULT
	}

	gl.PopMatrix() // CARGOCULT

	sdl.GL_SwapBuffers() // CARGOCULT
}
Пример #9
0
func (view *MenuView) Update(t, dt float64) {
	view.checkButtons()
	view.texture.Purge()
	window := view.director.window
	w, h := window.GetFramebufferSize()
	sx := 256 + margin*2
	sy := 240 + margin*2
	nx := (w - border*2) / sx
	ny := (h - border*2) / sy
	ox := (w-nx*sx)/2 + margin
	oy := (h-ny*sy)/2 + margin
	if nx < 1 {
		nx = 1
	}
	if ny < 1 {
		ny = 1
	}
	view.nx = nx
	view.ny = ny
	view.clampSelection()
	gl.PushMatrix()
	gl.Ortho(0, float64(w), float64(h), 0, -1, 1)
	view.texture.Bind()
	for j := 0; j < ny; j++ {
		for i := 0; i < nx; i++ {
			x := float32(ox + i*sx)
			y := float32(oy + j*sy)
			index := nx*(j+view.scroll) + i
			if index >= len(view.paths) {
				continue
			}
			path := view.paths[index]
			tx, ty, tw, th := view.texture.Lookup(path)
			drawThumbnail(x, y, tx, ty, tw, th)
		}
	}
	view.texture.Unbind()
	if int((t-view.t)*4)%2 == 0 {
		x := float32(ox + view.i*sx)
		y := float32(oy + view.j*sy)
		drawSelection(x, y, 8, 4)
	}
	gl.PopMatrix()
}
Пример #10
0
func (this *Pointer) Render() {
	switch {
	case this.VirtualCategory == POINTING && len(this.State.Axes) >= 2:
		// Prevent pointer from being drawn when the OS mouse pointer is visible.
		{
			// HACK
			var windowSize [2]int
			if globalWindow != nil {
				windowSize[0], windowSize[1] = globalWindow.GetSize()
			}

			// HACK: OS X specific.
			const border = 3
			if this.State.Axes[1] < 0 || this.State.Axes[0] < border || this.State.Axes[0] >= float64(windowSize[0])-border || this.State.Axes[1] >= float64(windowSize[1])-border {
				break
			}
		}

		gl.PushMatrix()
		defer gl.PopMatrix()
		gl.Translated(float64(NearInt64(this.State.Axes[0]))+0.5, float64(NearInt64(this.State.Axes[1]))+0.5, 0)

		const size float64 = 12 * 40 / 40
		gl.Color3d(1, 1, 1)
		gl.Begin(gl.TRIANGLE_FAN)
		gl.Vertex2d(0, 0)
		gl.Vertex2d(0, size)
		gl.Vertex2d(size*0.85*math.Sin(math.Pi/8), size*0.85*math.Cos(math.Pi/8))
		gl.Vertex2d(size/math.Sqrt2, size/math.Sqrt2)
		gl.End()

		gl.Begin(gl.LINE_LOOP)
		gl.Color3d(0, 0, 0)
		gl.Vertex2d(0, 0)
		gl.Vertex2d(0, size)
		gl.Color3d(0.75, 0.75, 0.75)
		gl.Vertex2d(size*0.85*math.Sin(math.Pi/8), size*0.85*math.Cos(math.Pi/8))
		gl.Color3d(0, 0, 0)
		gl.Vertex2d(size/math.Sqrt2, size/math.Sqrt2)
		gl.End()
	}
}
Пример #11
0
func Render() {
	gl.ClearColor(0, 0, 0, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.Color4f(1, 1, 1, 1)
	gl.BindTexture(gl.TEXTURE_2D, game.Texture)

	gl.PushMatrix()
	gl.Translatef(20-float32(game.PlayerX), 15-float32(game.PlayerY), 0)
	gl.Begin(gl.TRIANGLES)
	for i := 0; i < game.Width; i++ {
		for j := 0; j < game.Height; j++ {
			renderTile(game.Tiles[(j*game.Width)+i], float32(i), float32(j))
		}
	}
	// Player
	gl.Color4f(1, 0, 0, 1)
	renderTile(4, float32(game.PlayerX), float32(game.PlayerY))
	gl.End()
	gl.PopMatrix()
}
Пример #12
0
func (c *Context) PopMatrix() {
	gl.PopMatrix()
}
// OpenGL draw function
func draw(window *glfw.Window) {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.LoadIdentity()

	gl.PushMatrix()

	gl.Disable(gl.LIGHTING)

	width, height := window.GetSize()
	x := float64(width)
	y := float64(height)
	h := 0

	gl.Color4f(.1, .1, .1, .8)
	gl.LineWidth(1.0)

	// x方向
	var x0, x1, y0, y1 float64
	var deltaX, deltaY float64
	d := width / 2

	x0 = -x
	x1 = -x
	y0 = -y
	y1 = y
	deltaX = ((2 * x) / float64(d))

	for i := 0; i < d; i++ {
		x0 = x0 + deltaX
		gl.Begin(gl.LINES)
		gl.Vertex3f(float32(x0), float32(y0), float32(h))
		gl.Vertex3f(float32(x0), float32(y1), float32(h))
		gl.End()
	}

	// y方向
	x0 = -x
	x1 = x
	deltaY = ((2 * y) / float64(d))

	for i := 0; i < d; i++ {
		y0 = y0 + deltaY
		gl.Begin(gl.LINES)
		gl.Vertex3f(float32(x0), float32(y0), float32(h))
		gl.Vertex3f(float32(x1), float32(y0), float32(h))
		gl.End()
	}

	gl.PopMatrix()

	// draw boxes
	for _, room := range rooms {
		gl.PushMatrix()
		rot := room.Box.Body.Angle() * chipmunk.DegreeConst
		gl.Rotatef(float32(rot), 0, 0, 1.0)
		x := roundm(float64(room.Box.Body.Position().X), 4.0)
		y := roundm(float64(room.Box.Body.Position().Y), 4.0)
		gl.Translated(x, y, 0.0)
		drawRoom(room)
		gl.PopMatrix()
	}
}
Пример #14
0
func (ctx *DrawContext) drawSphere(p vector.V3, r float64, c colorful.Color) {
	/* TODO:
	   - decrease sphere detail if it's further away
	   - only draw spheres that would be visible inside the frustum:
	     - (no small spheres near the far plane)
	*/
	if ctx.cam.SphereInFrustum(p, r) == OUTSIDE {
		return
	}

	gl.Color3f(float32(c.R), float32(c.G), float32(c.B))

	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	defer gl.PopMatrix()

	slices := int(math.Max(10, 5*math.Log(r+1)))

	gl.Translated(p.X, p.Y, p.Z)
	gl.Scaled(r, r, r)

	l, ok := uint32(0), false
	if ctx.wireframe {
		l, ok = ctx.spheresWireframe[slices]
	} else {
		l, ok = ctx.spheresSolid[slices]
	}

	if !ok {
		ctx.listId++ // XXX: atomic?
		l = ctx.listId
		gl.NewList(l, gl.COMPILE)
		for i := 0; i <= slices; i++ {
			lat0 := math.Pi * (-0.5 + float64(i-1)/float64(slices))
			z0 := math.Sin(lat0)
			zr0 := math.Cos(lat0)

			lat1 := math.Pi * (-0.5 + float64(i)/float64(slices))
			z1 := math.Sin(lat1)
			zr1 := math.Cos(lat1)

			if ctx.wireframe {
				gl.Begin(gl.LINES)
			} else {
				gl.Begin(gl.QUAD_STRIP)
			}
			for j := 0; j <= slices; j++ {
				lng := 2 * math.Pi * (float64(j-1) / float64(slices))
				x := math.Cos(lng)
				y := math.Sin(lng)

				gl.Normal3f(float32(x*zr0), float32(y*zr0), float32(z0))
				gl.Vertex3f(float32(x*zr0), float32(y*zr0), float32(z0))
				gl.Normal3f(float32(x*zr1), float32(y*zr1), float32(z1))
				gl.Vertex3f(float32(x*zr1), float32(y*zr1), float32(z1))
			}
			gl.End()
		}
		gl.EndList()
		if ctx.wireframe {
			ctx.spheresWireframe[slices] = l
		} else {
			ctx.spheresSolid[slices] = l
		}
	}

	gl.CallList(l)
}
Пример #15
0
// Printf draws the given string at the specified coordinates.
// It expects the string to be a single line. Line breaks are not
// handled as line breaks and are rendered as glyphs.
//
// In order to render multi-line text, it is up to the caller to split
// the text up into individual lines of adequate length and then call
// this method for each line seperately.
func (f *Font) Printf(x, y float32, fs string, argv ...interface{}) error {
	indices := []rune(fmt.Sprintf(fs, argv...))

	if len(indices) == 0 {
		return nil
	}

	// Runes form display list indices.
	// For this purpose, they need to be offset by -FontConfig.Low
	low := f.config.Low
	for i := range indices {
		indices[i] -= low
	}

	var vp [4]int32
	gl.GetIntegerv(gl.VIEWPORT, &vp[0])

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(float64(vp[0]), float64(vp[2]), float64(vp[1]), float64(vp[3]), 0, 1)
	gl.PopAttrib()

	gl.PushAttrib(gl.LIST_BIT | gl.CURRENT_BIT | gl.ENABLE_BIT | gl.TRANSFORM_BIT)
	{
		gl.MatrixMode(gl.MODELVIEW)
		gl.Disable(gl.LIGHTING)
		gl.Disable(gl.DEPTH_TEST)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.TEXTURE_2D)

		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.TexEnvf(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)
		gl.BindTexture(gl.TEXTURE_2D, f.texture)
		gl.ListBase(f.listbase)

		var mv [16]float32
		gl.GetFloatv(gl.MODELVIEW_MATRIX, &mv[0])

		gl.PushMatrix()
		{
			gl.LoadIdentity()

			mgw := float32(f.maxGlyphWidth)
			mgh := float32(f.maxGlyphHeight)

			switch f.config.Dir {
			case LeftToRight, TopToBottom:
				gl.Translatef(x, float32(vp[3])-y-mgh, 0)
			case RightToLeft:
				gl.Translatef(x-mgw, float32(vp[3])-y-mgh, 0)
			}

			gl.MultMatrixf(&mv[0])
			gl.CallLists(int32(len(indices)), gl.UNSIGNED_INT, unsafe.Pointer(&indices[0]))
		}
		gl.PopMatrix()
		gl.BindTexture(gl.TEXTURE_2D, 0)
	}
	gl.PopAttrib()

	gl.PushAttrib(gl.TRANSFORM_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.PopAttrib()
	return checkGLError()
}