Пример #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 (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()
	}
}
Пример #3
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()
}
Пример #4
0
// list of boxes
// the point of origin
// the translated offset from the origin
// the angles co-ordinate
// the index of the array
// the degree of angular rotation
func wall(b []uint32, o, offset, a_cord cord, i int32, a float64, s size) []uint32 {
	b = append(b, gl.GenLists(1))
	gl.NewList(b[i], gl.COMPILE)
	gl.Translated(o.x+offset.x, o.y+offset.y, o.z+offset.z)
	gl.Rotated(a, a_cord.x, a_cord.y, a_cord.z)
	box(s.x, s.y, s.z)
	gl.EndList()
	return b
}
Пример #5
0
func InitFont() {
	LoadTexture(filepath.FromSlash("/Users/Dmitri/Dropbox/Work/2015/Bitmap Fonts/Helvetica Neue.png"))

	oFontBase = gl.GenLists(32 + 96)
	for i := 0; i < 96; i++ {
		const shiftY = float64(1.0 / 6)

		indexX, indexY := i%16, i/16

		charWidth := shiftXs[indexY][indexX+1] - shiftXs[indexY][indexX]

		gl.NewList(oFontBase+uint32(i+32), gl.COMPILE)
		gl.Begin(gl.QUADS)
		gl.TexCoord2d(shiftXs[indexY][indexX], float64(indexY)*shiftY)
		gl.Vertex2d(0, 0)
		gl.TexCoord2d(shiftXs[indexY][indexX+1], float64(indexY)*shiftY)
		gl.Vertex2d(fontWidth*charWidth/float64(1.0/16), 0)
		gl.TexCoord2d(shiftXs[indexY][indexX+1], float64(indexY+1)*shiftY)
		gl.Vertex2d(fontWidth*charWidth/float64(1.0/16), fontHeight)
		gl.TexCoord2d(shiftXs[indexY][indexX], float64(indexY+1)*shiftY)
		gl.Vertex2d(0, fontHeight)
		gl.End()
		gl.Translated(fontWidth*charWidth/float64(1.0/16), 0.0, 0.0)
		gl.EndList()
	}

	oFontBackground = gl.GenLists(1)
	gl.NewList(oFontBackground, gl.COMPILE)
	gl.Begin(gl.QUADS)
	gl.Vertex2d(0, 0)
	gl.Vertex2d(0, fontHeight)
	gl.Vertex2d(fontWidth, fontHeight)
	gl.Vertex2d(fontWidth, 0)
	gl.End()
	gl.Translated(fontWidth, 0.0, 0.0)
	gl.EndList()

	CheckGLError()
}
Пример #6
0
func (c *Camera) lookAt(at vector.V3) {
	up := vector.V3{0, 0, 1}

	fw := at.Sub(c.Pos).Normalized()
	side := fw.Cross(up).Normalized()
	up = side.Cross(fw).Normalized()

	m := [16]float64{
		side.X, up.X, -fw.X, 0,
		side.Y, up.Y, -fw.Y, 0,
		side.Z, up.Z, -fw.Z, 0,
		0, 0, 0, 1,
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadMatrixd(&m[0])
	gl.Translated(-c.Pos.X, -c.Pos.Y, -c.Pos.Z)

	// Update frustum
	nc := c.Pos.Sub(fw.Scaled(-c.frustum.zNear))
	fc := c.Pos.Sub(fw.Scaled(-c.frustum.zFar))

	planes := []vector.Plane{
		vector.Plane{fw, nc},            // NEARP
		vector.Plane{fw.Scaled(-1), fc}, // FARP
	}

	nh, nw := c.frustum.nearH, c.frustum.nearW

	// TOP
	aux := nc.Add(up.Scaled(nh)).Sub(c.Pos).Normalized()
	normal := aux.Cross(side)
	planes = append(planes, vector.Plane{normal, nc.Add(up.Scaled(nh))})

	// BOTTOM
	aux = nc.Sub(up.Scaled(nh)).Sub(c.Pos).Normalized()
	normal = side.Cross(aux)
	planes = append(planes, vector.Plane{normal, nc.Sub(up.Scaled(nh))})

	// LEFT
	aux = nc.Sub(side.Scaled(nw)).Sub(c.Pos).Normalized()
	normal = aux.Cross(up)
	planes = append(planes, vector.Plane{normal, nc.Sub(side.Scaled(nw))})

	// LEFT
	aux = nc.Add(side.Scaled(nw)).Sub(c.Pos).Normalized()
	normal = up.Cross(aux)
	planes = append(planes, vector.Plane{normal, nc.Add(side.Scaled(nw))})

	c.frustum.planes = planes
}
Пример #7
0
func InitFont() {
	LoadTexture(filepath.Join("data", "Font.png"))

	oFontBase = gl.GenLists(32 + 96*4)
	for i := 0; i < 96*4; i++ {
		const shiftX, shiftY = float64(1.0 / 16), float64(1.0 / 6 / 4)

		indexX, indexY := i%16, i/16

		gl.NewList(oFontBase+uint32(i+32), gl.COMPILE)
		gl.Begin(gl.QUADS)
		gl.TexCoord2d(float64(indexX)*shiftX, float64(indexY)*shiftY)
		gl.Vertex2i(0, 0)
		gl.TexCoord2d(float64(indexX+1)*shiftX, float64(indexY)*shiftY)
		gl.Vertex2i(fontWidth, 0)
		gl.TexCoord2d(float64(indexX+1)*shiftX, float64(indexY+1)*shiftY)
		gl.Vertex2i(fontWidth, fontHeight)
		gl.TexCoord2d(float64(indexX)*shiftX, float64(indexY+1)*shiftY)
		gl.Vertex2i(0, fontHeight)
		gl.End()
		gl.Translated(fontWidth, 0.0, 0.0)
		gl.EndList()
	}

	oFontBackground = gl.GenLists(1)
	gl.NewList(oFontBackground, gl.COMPILE)
	gl.Begin(gl.QUADS)
	gl.Vertex2i(0, 0)
	gl.Vertex2i(0, fontHeight)
	gl.Vertex2i(fontWidth, fontHeight)
	gl.Vertex2i(fontWidth, 0)
	gl.End()
	gl.Translated(fontWidth, 0.0, 0.0)
	gl.EndList()

	CheckGLError()
}
Пример #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 (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()
	}
}
// 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()
	}
}
Пример #11
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)
}