Пример #1
0
func (f *Font) DrawText2D(x int, y int, color [3]byte, scale float, txt string) (endw int, endh int) {
	gl.LoadIdentity()
	//	gl.Translatef(0.0, 0.0, -2.0);

	glEnable2D()
	gl.Disable(gl.DEPTH_TEST)

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

	locX := gl.GLfloat(x)
	locY := gl.GLfloat(y)
	wi := gl.GLfloat(w) * gl.GLfloat(scale)
	he := gl.GLfloat(h) * gl.GLfloat(scale)

	/* 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.TexCoord2f(0.0, 1.0)
	gl.Vertex2f(locX, locY)
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex2f(locX+wi, locY)
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex2f(locX+wi, locY+he)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex2f(locX, locY+he)
	gl.End()

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

	gl.Enable(gl.DEPTH_TEST)
	glDisable2D()
	return
}
Пример #2
0
func drawQuad(x, y, w, h int, u, v, u2, v2 float32) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(float32(u), float32(v))
	gl.Vertex2i(int(x), int(y))

	gl.TexCoord2f(float32(u2), float32(v))
	gl.Vertex2i(int(x+w), int(y))

	gl.TexCoord2f(float32(u2), float32(v2))
	gl.Vertex2i(int(x+w), int(y+h))

	gl.TexCoord2f(float32(u), float32(v2))
	gl.Vertex2i(int(x), int(y+h))

	gl.End()
}
Пример #3
0
func drawQuad(x, y, w, h int, u, v, u2, v2 float) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(gl.GLfloat(u), gl.GLfloat(v))
	gl.Vertex2i(gl.GLint(x), gl.GLint(y))

	gl.TexCoord2f(gl.GLfloat(u2), gl.GLfloat(v))
	gl.Vertex2i(gl.GLint(x+w), gl.GLint(y))

	gl.TexCoord2f(gl.GLfloat(u2), gl.GLfloat(v2))
	gl.Vertex2i(gl.GLint(x+w), gl.GLint(y+h))

	gl.TexCoord2f(gl.GLfloat(u), gl.GLfloat(v2))
	gl.Vertex2i(gl.GLint(x), gl.GLint(y+h))

	gl.End()
}
Пример #4
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
}
// Here goes our drawing code
func drawGLScene(sector Sector) {
	xtrans := gl.GLfloat(-xpos)
	ztrans := gl.GLfloat(-zpos)
	ytrans := gl.GLfloat(-walkbias - 0.25)
	scenroty := gl.GLfloat(360.0 - yrot)

	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// Rotate up and down to look up and down
	gl.Rotatef(float32(lookupdown), 1.0, 0.0, 0.0)
	// Rotate depending on direction player is facing
	gl.Rotatef(float32(scenroty), 0.0, 1.0, 0.0)
	// translate the scene based on player position
	gl.Translatef(float32(xtrans), float32(ytrans), float32(ztrans))

	gl.BindTexture(gl.TEXTURE_2D, uint(textures[filter]))

	for _, vertices := range sector {
		gl.Begin(gl.TRIANGLES)
		for _, triangle := range *vertices {
			gl.Normal3f(0.0, 0.0, 1.0)
			gl.TexCoord2f(float32(triangle.u), float32(triangle.v))
			gl.Vertex3f(float32(triangle.x), float32(triangle.y), float32(triangle.z))
		}
		gl.End()
	}

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
Пример #6
0
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// Move left 1.5 units and into the screen 6.0 units.
	gl.LoadIdentity()
	gl.Translatef(0.0, 0.0, -7.0)

	gl.Rotatef(float32(xrot), 1.0, 0.0, 0.0) /* Rotate On The X Axis */
	gl.Rotatef(float32(yrot), 0.0, 1.0, 0.0) /* Rotate On The Y Axis */
	gl.Rotatef(float32(zrot), 0.0, 0.0, 1.0) /* Rotate On The Z Axis */

	/* Select Our Texture */
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	gl.Begin(gl.QUADS) // Draw a quad
	/* Front Face */
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom left
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(1.0, -1.0, 1.0) // Bottom right
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(1.0, 1.0, 1.0) // Top right
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, 1.0, 1.0) // Top left

	/* Back Face */
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom right
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-1.0, 1.0, -1.0) // Top right
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(1.0, 1.0, -1.0) // Top left
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(1.0, -1.0, -1.0) // Bottom left

	/* Top Face */
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(-1.0, 1.0, 1.0) // Bottom left
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(1.0, 1.0, 1.0) // Bottom right
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(1.0, 1.0, -1.0) // Top right

	/* Bottom Face */
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Top right
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(1.0, -1.0, -1.0) // Top left
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right

	/* Right face */
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(1.0, -1.0, -1.0) // Bottom right
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(1.0, 1.0, -1.0) // Top right
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(1.0, 1.0, 1.0) // Top left
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(1.0, -1.0, 1.0) // Bottom left

	/* Left Face */
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom left
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom right
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-1.0, 1.0, 1.0) // Top right
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(-1.0, 1.0, -1.0) // Top left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	xrot += 0.3 /* X Axis Rotation */
	yrot += 0.2 /* Y Axis Rotation */
	zrot += 0.4 /* Z Axis Rotation */

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}
Пример #7
0
// Here goes our drawing code
func drawGLScene() {
  // Clear the screen and depth buffer
  gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

  // Move left 1.5 units and into the screen 6.0 units.
  gl.LoadIdentity()
  gl.Translatef(0.0, 0.0, float32(z)) // translate by z

  gl.Rotatef(float32(xrot), 1.0, 0.0, 0.0) /* Rotate On The X Axis */
  gl.Rotatef(float32(yrot), 0.0, 1.0, 0.0) /* Rotate On The Y Axis */

  /* Select Our Texture */
  gl.BindTexture(gl.TEXTURE_2D, uint(textures[filter])) // based on filter

  gl.Begin(gl.QUADS)

  // Front face
  gl.Normal3f(0.0, 0.0, 1.0) // Normal Pointing Towards Viewer
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f(-1.0, -1.0, 1.0) // Bottom left
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f( 1.0, -1.0, 1.0) // Bottom right
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f( 1.0,  1.0, 1.0) // Top right
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f(-1.0,  1.0, 1.0) // Top left

  // Back Face
  gl.Normal3f(0.0, 0.0, -1.0) // Normal Pointing Away From Viewer
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom right
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f(-1.0,  1.0, -1.0) // Top right
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f( 1.0,  1.0, -1.0) // Top left
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f( 1.0, -1.0, -1.0) // Bottom left

  // Top Face
  gl.Normal3f(0.0, 1.0, 0.0) // Normal Pointing Up
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f(-1.0,  1.0, -1.0) // Top left
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f(-1.0,  1.0,  1.0) // Bottom left
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f( 1.0,  1.0,  1.0) // Bottom right
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f( 1.0,  1.0, -1.0) // Top right

  // Bottom Face
  gl.Normal3f(0.0, -1.0, 0.0) // Normal Pointing Down
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f(-1.0, -1.0, -1.0) // Top right
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f( 1.0, -1.0, -1.0) // Top left
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f( 1.0, -1.0,  1.0) // Bottom left
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f(-1.0, -1.0,  1.0) // Bottom right

  // Right face
  gl.Normal3f(1.0, 0.0, 0.0) // Normal Pointing Right
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f(1.0, -1.0, -1.0) // Bottom right
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f(1.0,  1.0, -1.0) // Top right
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f(1.0,  1.0,  1.0) // Top left
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f(1.0, -1.0,  1.0) // Bottom left

  // Left Face
  gl.Normal3f(-1.0, 0.0, 0.0) // Normal Pointing Left
  gl.TexCoord2f(1.0, 0.0); gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom left
  gl.TexCoord2f(0.0, 0.0); gl.Vertex3f(-1.0, -1.0,  1.0) // Bottom right
  gl.TexCoord2f(0.0, 1.0); gl.Vertex3f(-1.0,  1.0,  1.0) // Top right
  gl.TexCoord2f(1.0, 1.0); gl.Vertex3f(-1.0,  1.0, -1.0) // Top left

  gl.End()

  sdl.GL_SwapBuffers()

  xrot += xspeed
  yrot += yspeed

  // Gather our frames per second
  frames++
  t := sdl.GetTicks()
  if t-t0 >= 5000 {
    seconds := (t - t0) / 1000.0
    fps := frames / seconds
    fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
    t0 = t
    frames = 0
  }
}
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	for loop, star := range stars {
		gl.LoadIdentity()
		gl.Translatef(0.0, 0.0, float32(zoom))
		gl.Rotatef(float32(tilt), 1.0, 0.0, 0.0)
		gl.Rotatef(float32(star.angle), 0.0, 1.0, 0.0)
		gl.Translatef(float32(star.dist), 0.0, 0.0)
		gl.Rotatef(float32(-star.angle), 0.0, 1.0, 0.0)
		gl.Rotatef(float32(-tilt), 1.0, 0.0, 0.0)

		if twinkle {
			other := stars[(num-loop)-1]
			gl.Color4ub(uint8(other.r), uint8(other.g), uint8(other.b), 255)
			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 0.0)
			gl.Vertex3f(1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 1.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()
		}

		gl.Rotatef(float32(spin), 0.0, 0.0, 1.0)
		gl.Color4ub(uint8(star.r), uint8(star.g), uint8(star.b), 255)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0.0, 0.0)
		gl.Vertex3f(-1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 0.0)
		gl.Vertex3f(1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 1.0)
		gl.Vertex3f(1.0, 1.0, 0.0)
		gl.TexCoord2f(0.0, 1.0)
		gl.Vertex3f(-1.0, 1.0, 0.0)
		gl.End()

		spin += 0.01
		star.angle += gl.GLfloat(loop) / gl.GLfloat(num)
		star.dist -= 0.01

		if star.dist < 0.0 {
			star.dist += 5.0
			star.r = gl.GLubyte(rand.Float32() * 255)
			star.g = gl.GLubyte(rand.Float32() * 255)
			star.b = gl.GLubyte(rand.Float32() * 255)
		}
	}

	// Draw to the screen
	sdl.GL_SwapBuffers()

	// Gather our frames per second
	frames++
	t := sdl.GetTicks()
	if t-t0 >= 5000 {
		seconds := (t - t0) / 1000.0
		fps := frames / seconds
		fmt.Println(frames, "frames in", seconds, "seconds =", fps, "FPS")
		t0 = t
		frames = 0
	}
}