Beispiel #1
0
func (pen *Pen) lineTo(p Point) {

	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.Color4f(0.0, 0.0, 0.0, 0.1)

	gl.Begin(gl.LINES)

	for _, s := range pen.points {

		if s.x == 0 && s.y == 0 {
			continue
		}

		if p.distanceTo(s) < 20.0 {

			gl.Vertex2i(int(p.x), int(p.y))
			gl.Vertex2i(int(s.x), int(s.y))

		}

	}

	gl.End()

	pen.n = (pen.n + 1) % len(pen.points)
	pen.points[pen.n] = p

	pen.moveTo(p)

}
Beispiel #2
0
func drawFrame() {

	gl.LoadIdentity()
	gl.LineWidth(5.0)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Enable(gl.LINE_SMOOTH)

	gl.Color4f(gl.GLfloat(FrameColor[0]), gl.GLfloat(FrameColor[1]), gl.GLfloat(FrameColor[2]), 0.1)

	m := PlayArea

	t := 1.0 * m
	b := -1.0 * m
	r := 1.0 * m
	l := -1.0 * m

	gl.Begin(gl.LINE_STRIP)

	zo := -5.0

	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(t), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(r), gl.GLfloat(t), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(r), gl.GLfloat(b), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(b), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(t), gl.GLfloat(zo))

	gl.End()

}
Beispiel #3
0
func (f *Font) setupTextRendering(color [3]byte, txt string) (gl.GLuint, *sdl.Surface, *sdl.Surface, *sdl.Surface, int, int) {

	//
	var texture gl.GLuint

	/* Use SDL_TTF to render our text */
	var col sdl.Color
	col.R = color[0]
	col.G = color[1]
	col.B = color[2]

	// get surface with text
	initial := ttf.RenderText_Blended(f.font, txt, col)

	/* Convert the rendered text to a known format */
	w := next_p2(int(initial.W))
	h := next_p2(int(initial.H))

	intermediarya := sdl.CreateRGBSurface(0, w, h, 32,
		0x00ff0000, 0x0000ff00, 0x000000ff, 0xff000000)

	var rr *sdl.Rect = nil
	intermediarya.Blit(rr, initial, rr)

	intermediary := intermediarya.DisplayFormatAlpha()

	/* Tell GL about our new texture */
	gl.GenTextures(1, &texture)
	gl.BindTexture(gl.TEXTURE_2D, texture)
	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, gl.GLsizei(w), gl.GLsizei(h), 0, gl.BGRA,
		gl.UNSIGNED_BYTE, unsafe.Pointer(intermediary.Pixels))

	gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)

	/* GL_NEAREST looks horrible, if scaled... */
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)

	/* prepare to render our texture */
	gl.Enable(gl.TEXTURE_2D)

	gl.BindTexture(gl.TEXTURE_2D, texture)
	gl.Color4f(1.0, 1.0, 1.0, 1.0)

	gl.Enable(gl.BLEND)
	//	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_COLOR) // TODO : MAke real alpha work!

	return texture, initial, intermediarya, intermediary, w, h
}
Beispiel #4
0
// general OpenGL initialization
func initGL() {
  gl.Enable(gl.TEXTURE_2D)
  gl.ShadeModel(gl.SMOOTH)
  gl.ClearColor(0.0, 0.0, 0.0, 0.5)
  gl.ClearDepth(1.0)
  gl.Enable(gl.DEPTH_TEST)
  gl.DepthFunc(gl.LEQUAL)
  gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

  // Setup the light
  gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:]) // ambient lighting
  gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:]) // make it diffuse
  gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:]) // and place it
  gl.Enable(gl.LIGHT1) // and finally turn it on.

  gl.Color4f(1.0, 1.0, 1.0, 0.5) // Full Brightness, 50% Alpha ( NEW )
  gl.BlendFunc(gl.SRC_ALPHA, gl.ONE) // Blending Function For Translucency Based On Source Alpha Value ( NEW )
}
// general OpenGL initialization
func initGL() {
	LoadGLTextures("data/mud.bmp")

	gl.Enable(gl.TEXTURE_2D)
	gl.ShadeModel(gl.SMOOTH)
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.ClearDepth(1.0)
	gl.Enable(gl.DEPTH_TEST)
	gl.DepthFunc(gl.LEQUAL)
	gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST)

	gl.Lightfv(gl.LIGHT1, gl.AMBIENT, lightAmbient[:])
	gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, lightDiffuse[:])
	gl.Lightfv(gl.LIGHT1, gl.POSITION, lightPosition[:])
	gl.Enable(gl.LIGHT1)

	gl.Color4f(1.0, 1.0, 1.0, 0.5)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE)
}
Beispiel #6
0
func drawWin(d float) {

	gl.LoadIdentity()
	//	gl.LineWidth(5.0)
	//	gl.Enable(gl.POINT_SMOOTH)
	//	gl.Enable(gl.LINE_SMOOTH)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	if d > 1.0 {
		d = 1.0
	}

	c := WinColor

	gl.Color4f(gl.GLfloat(c[0]), gl.GLfloat(c[1]), gl.GLfloat(c[2]), gl.GLfloat(d))

	m := PlayArea * 4

	t := 1.0 * m
	b := -1.0 * m
	r := 1.0 * m
	l := -1.0 * m

	gl.Begin(gl.POLYGON)

	zo := -10.0

	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(t), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(r), gl.GLfloat(t), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(r), gl.GLfloat(b), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(b), gl.GLfloat(zo))
	gl.Vertex3f(gl.GLfloat(l), gl.GLfloat(t), gl.GLfloat(zo))

	gl.End()
	gl.Disable(gl.BLEND)

}
Beispiel #7
0
func (f *Font) DrawText3D(pos Vector3, color [3]byte, scale float, txt string) (endw int, endh int) {

	gl.LoadIdentity()
	// 	gl.Translatef(gl.GLfloat(pos.X), gl.GLfloat(pos.Y), gl.GLfloat(-4.99));
	gl.Translatef(gl.GLfloat(pos.X), gl.GLfloat(pos.Y), gl.GLfloat(-4.99))
	gl.Scalef(gl.GLfloat(1.0/64.0*scale), gl.GLfloat(1.0/64.0*scale), gl.GLfloat(1.0))
	gl.Disable(gl.DEPTH_TEST)

	texture, initial, intermediarya, intermediary, w, h := f.setupTextRendering(color, txt)

	wi := gl.GLfloat(w)
	he := gl.GLfloat(h)
	locX := gl.GLfloat(0) - wi*0.5
	locY := gl.GLfloat(0) - he*0.5

	/* Draw a quad at location */
	gl.Begin(gl.QUADS)
	/* Recall that the origin is in the lower-left corner
	   That is why the TexCoords specify different corners
	   than the Vertex coors seem to. */

	gl.Color4f(1.0, 1.0, 0.0, 1.0)

	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(locX, locY, 0.0)
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(locX+wi, locY, 0.0)
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(locX+wi, locY+he, 0.0)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(locX, locY+he, 0.0)
	gl.End()

	endw, endh = f.teardownTextRendering(texture, initial, intermediarya, intermediary)

	gl.Enable(gl.DEPTH_TEST)
	return
}
Beispiel #8
0
func drawCircle(t *trigger) {

	radius := float64(t.Size)
	pos := t.Pos

	gl.LoadIdentity()
	gl.Color4f(gl.GLfloat(t.Col[0]), gl.GLfloat(t.Col[1]), gl.GLfloat(t.Col[2]), gl.GLfloat(t.Col[3]))

	gl.LineWidth(2.0)
	gl.Translatef(gl.GLfloat(pos.X), gl.GLfloat(pos.Y), gl.GLfloat(pos.Z))

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

	gl.Begin(gl.POLYGON)

	for i := 0; i < 360; i++ {
		var degInRad float64 = float64(i) * DEG2RAD
		gl.Vertex3f(gl.GLfloat(math.Cos(degInRad)*radius), gl.GLfloat(math.Sin(degInRad)*radius), gl.GLfloat(0.0))
	}

	gl.End()
	gl.Disable(gl.BLEND)
}
Beispiel #9
0
func cube(color []float32) {
	gl.Materialfv(gl.FRONT, gl.AMBIENT_AND_DIFFUSE, whiteColor)
	gl.Color4f(color[0], color[1], color[2], color[3])
	// TOP
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth)
	gl.End()
	// Bottom
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth)
	gl.End()
	// Front
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth)
	gl.End()
	// Back
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth)
	gl.End()
	// Left
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.End()
	// Right
	gl.Begin(gl.TRIANGLE_FAN)
	gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth)
	gl.End()

	//*
	gl.Color4f(color[0]/1.2, color[1]/1.2, color[2]/1.2, 1.0)
	gl.Begin(gl.LINE_STRIP) // Start Drawing Our Player Using Lines
	// TOP
	gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth)
	// Front
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth)
	// Bottom
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth)
	// Back
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(cubeWidth, cubeWidth, -cubeWidth)
	// Right
	gl.Vertex3f(cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, cubeWidth)
	gl.Vertex3f(cubeWidth, -cubeWidth, -cubeWidth)
	// Left
	gl.Vertex3f(-cubeWidth, cubeWidth, cubeWidth)
	gl.Vertex3f(-cubeWidth, cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, -cubeWidth)
	gl.Vertex3f(-cubeWidth, -cubeWidth, cubeWidth)
	gl.End()
	//*/
}