예제 #1
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()

}
예제 #2
0
func main() {

	ret := glfw.Init()

	print(ret)

	ret = glfw.OpenWindow(300, 300, 0, 0, 0, 0, 0, 0, glfw.WINDOW)

	print(ret)

	if gl.Init() != 0 {
		panic("glew error")
	}

	running := true

	for running {

		gl.Begin(gl.TRIANGLES)
		gl.Vertex3f(0, 0, 0)
		gl.Vertex3f(0, 1, 0)
		gl.Vertex3f(1, 1, 0)
		gl.End()

		glfw.SwapBuffers()

		running = glfw.GetKey(glfw.KEY_ESC) == 0 && glfw.GetWindowParam(glfw.OPENED) != 0

	}

}
예제 #3
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)

}
예제 #4
0
파일: draw_font.go 프로젝트: jcd/go-gamelib
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() {
	// 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(-1.5, 0.0, -6.0)
	gl.Rotatef(float32(rtri), 0.0, 1.0, 0.0) // Rotate the triangle on the Y axis

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Color3f(1.0, 0.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Color3f(0.0, 1.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Color3f(0.0, 0.0, 1.0)    // Set The Color To Red
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -6.0)
	gl.Color3f(0.5, 0.5, 1.0)                 // Set The Color To Blue One Time Only
	gl.Rotatef(float32(rquad), 1.0, 0.0, 0.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	rtri += 0.2   // Increase The Rotation Variable For The Triangle
	rquad -= 0.15 // Decrease The Rotation Variable For The Quad

	// 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(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
	}
}
예제 #7
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)
}
예제 #8
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(-1.5, 0.0, -6.0)

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.Translatef(3.0, 0.0, 0.0)

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// 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
	}
}
예제 #9
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
	}
}
예제 #10
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
  }
}
예제 #11
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(-1.5, 0.0, -6.0)
	gl.Rotatef(float32(rtri), 0.0, 1.0, 0.0) // Rotate the triangle on the Y axis

	gl.Begin(gl.TRIANGLES) // Draw triangles

	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Front)       */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0) /* Left Of Triangle (Front)      */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Right Of Triangle (Front)     */

	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Right)       */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Left Of Triangle (Right)      */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0) /* Right Of Triangle (Right)     */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Back)        */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Left Of Triangle (Back)       */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Right Of Triangle (Back)      */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Left)        */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Left Of Triangle (Left)       */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Right Of Triangle (Left)      */

	gl.End() // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -7.0)
	gl.Rotatef(float32(rquad), 1.0, 1.0, 1.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)            // draw quads
	gl.Color3f(0.0, 1.0, 0.0)     // Set The Color To Green
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Right Of The Quad (Top)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Left Of The Quad (Top)
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Bottom Left Of The Quad (Top)
	gl.Vertex3f(1.0, 1.0, 1.0)    // Bottom Right Of The Quad (Top)
	gl.Color3f(1.0, 0.5, 0.0)     // Set The Color To Orange
	gl.Vertex3f(1.0, -1.0, 1.0)   // Top Right Of The Quad (Bottom)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Top Left Of The Quad (Bottom)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Bottom)
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Right Of The Quad (Bottom)
	gl.Color3f(1.0, 0.0, 0.0)     // Set The Color To Red
	gl.Vertex3f(1.0, 1.0, 1.0)    // Top Right Of The Quad (Front)
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Top Left Of The Quad (Front)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Bottom Left Of The Quad (Front)
	gl.Vertex3f(1.0, -1.0, 1.0)   // Bottom Right Of The Quad (Front)
	gl.Color3f(1.0, 1.0, 0.0)     // Set The Color To Yellow
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Left Of The Quad (Back)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Right Of The Quad (Back)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Right Of The Quad (Back)
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Left Of The Quad (Back)
	gl.Color3f(0.0, 0.0, 1.0)     // Set The Color To Blue
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Top Right Of The Quad (Left)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Left Of The Quad (Left)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Left)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Bottom Right Of The Quad (Left)
	gl.Color3f(1.0, 0.0, 1.0)     // Set The Color To Violet
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Right Of The Quad (Right)
	gl.Vertex3f(1.0, 1.0, 1.0)    // Top Left Of The Quad (Right)
	gl.Vertex3f(1.0, -1.0, 1.0)   // Bottom Left Of The Quad (Right)
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Right Of The Quad (Right)
	gl.End()                      // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	rtri += 0.2   // Increase The Rotation Variable For The Triangle
	rquad -= 0.15 // Decrease The Rotation Variable For The Quad

	// 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
	}
}
예제 #12
0
파일: draw.go 프로젝트: jcd/go-gamelib
func drawCubes(v *Vector3) {

	gl.LoadIdentity()
	//	gl.Translatef( -1.5, 0.0, -6.0 )
	gl.Translatef(gl.GLfloat(v.X), gl.GLfloat(v.Y), gl.GLfloat(v.Z))

	/* Rotate The Triangle On The Y axis ( NEW ) */
	gl.Rotatef(rtri, 0.0, 1.0, 0.0)

	gl.Begin(gl.TRIANGLES)       /* Drawing Using Triangles       */
	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Front)       */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0) /* Left Of Triangle (Front)      */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Right Of Triangle (Front)     */

	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Right)       */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Left Of Triangle (Right)      */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0) /* Right Of Triangle (Right)     */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Back)        */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Left Of Triangle (Back)       */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Right Of Triangle (Back)      */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Left)        */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Left Of Triangle (Left)       */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Right Of Triangle (Left)      */
	gl.End()                      /* Finished Drawing The Triangle */

	rtri = rtri + 0.2

	return

	/* Move Right 3 Units */
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -6.0)

	/* Rotate The Quad On The X axis ( NEW ) */
	gl.Rotatef(rquad, 1.0, 0.0, 0.0)

	/* Set The Color To Blue One Time Only */
	gl.Color3f(0.5, 0.5, 1.0)

	gl.Begin(gl.QUADS)           /* Draw A Quad                      */
	gl.Color3f(0.0, 1.0, 0.0)    /* Set The Color To Green           */
	gl.Vertex3f(1.0, 1.0, -1.0)  /* Top Right Of The Quad (Top)      */
	gl.Vertex3f(-1.0, 1.0, -1.0) /* Top Left Of The Quad (Top)       */
	gl.Vertex3f(-1.0, 1.0, 1.0)  /* Bottom Left Of The Quad (Top)    */
	gl.Vertex3f(1.0, 1.0, 1.0)   /* Bottom Right Of The Quad (Top)   */

	gl.Color3f(1.0, 0.5, 0.0)     /* Set The Color To Orange          */
	gl.Vertex3f(1.0, -1.0, 1.0)   /* Top Right Of The Quad (Botm)     */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Top Left Of The Quad (Botm)      */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Bottom Left Of The Quad (Botm)   */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Bottom Right Of The Quad (Botm)  */

	gl.Color3f(1.0, 0.0, 0.0)    /* Set The Color To Red             */
	gl.Vertex3f(1.0, 1.0, 1.0)   /* Top Right Of The Quad (Front)    */
	gl.Vertex3f(-1.0, 1.0, 1.0)  /* Top Left Of The Quad (Front)     */
	gl.Vertex3f(-1.0, -1.0, 1.0) /* Bottom Left Of The Quad (Front)  */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Bottom Right Of The Quad (Front) */

	gl.Color3f(1.0, 1.0, 0.0)     /* Set The Color To Yellow          */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Bottom Left Of The Quad (Back)   */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Bottom Right Of The Quad (Back)  */
	gl.Vertex3f(-1.0, 1.0, -1.0)  /* Top Right Of The Quad (Back)     */
	gl.Vertex3f(1.0, 1.0, -1.0)   /* Top Left Of The Quad (Back)      */

	gl.Color3f(0.0, 0.0, 1.0)     /* Set The Color To Blue            */
	gl.Vertex3f(-1.0, 1.0, 1.0)   /* Top Right Of The Quad (Left)     */
	gl.Vertex3f(-1.0, 1.0, -1.0)  /* Top Left Of The Quad (Left)      */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Bottom Left Of The Quad (Left)   */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Bottom Right Of The Quad (Left)  */

	gl.Color3f(1.0, 0.0, 1.0)    /* Set The Color To Violet          */
	gl.Vertex3f(1.0, 1.0, -1.0)  /* Top Right Of The Quad (Right)    */
	gl.Vertex3f(1.0, 1.0, 1.0)   /* Top Left Of The Quad (Right)     */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Bottom Left Of The Quad (Right)  */
	gl.Vertex3f(1.0, -1.0, -1.0) /* Bottom Right Of The Quad (Right) */
	gl.End()                     /* Done Drawing The Quad            */

	rquad -= 0.15
}
예제 #13
0
파일: draw.go 프로젝트: jcd/go-gamelib
func drawCube(v *Vector3) {

	gl.LoadIdentity()
	//	gl.Translatef( -1.5, 0.0, -6.0 )
	gl.Translatef(gl.GLfloat(v.X), gl.GLfloat(v.Y), gl.GLfloat(v.Z))

	/* Rotate The Triangle On The Y axis ( NEW ) */
	// gl.Rotatef( rtri, 0.0, 1.0, 0.0 );

	gl.Begin(gl.TRIANGLES)       /* Drawing Using Triangles       */
	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Front)       */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0) /* Left Of Triangle (Front)      */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Right Of Triangle (Front)     */

	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Right)       */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Left Of Triangle (Right)      */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0) /* Right Of Triangle (Right)     */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Back)        */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Left Of Triangle (Back)       */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Right Of Triangle (Back)      */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Left)        */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Left Of Triangle (Left)       */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Right Of Triangle (Left)      */
	gl.End()                      /* Finished Drawing The Triangle */

	rtri = rtri + 0.2

}
예제 #14
0
파일: draw.go 프로젝트: jcd/go-gamelib
func drawMass(m *phys.Mass, dsz gl.GLfloat) {

	gl.LoadIdentity()
	//	gl.Translatef( -1.5, 0.0, -6.0 )

	v := m.Pos
	gl.Translatef(gl.GLfloat(v.X), gl.GLfloat(v.Y), gl.GLfloat(v.Z))

	/* Rotate The Triangle On The Y axis ( NEW ) */
	// gl.Rotatef( rtri, 0.0, 1.0, 0.0 );

	gl.Begin(gl.TRIANGLES)       /* Drawing Using Triangles       */
	gl.Color3f(dsz, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, dsz, 0.0)   /* Top Of Triangle (Front)       */
	gl.Color3f(0.0, dsz, 0.0)    /* Green                         */
	gl.Vertex3f(-dsz, -dsz, dsz) /* Left Of Triangle (Front)      */
	gl.Color3f(0.0, 0.0, dsz)    /* Blue                          */
	gl.Vertex3f(dsz, -dsz, dsz)  /* Right Of Triangle (Front)     */

	gl.Color3f(dsz, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, dsz, 0.0)   /* Top Of Triangle (Right)       */
	gl.Color3f(0.0, 0.0, dsz)    /* Blue                          */
	gl.Vertex3f(dsz, -dsz, dsz)  /* Left Of Triangle (Right)      */
	gl.Color3f(0.0, dsz, 0.0)    /* Green                         */
	gl.Vertex3f(dsz, -dsz, -dsz) /* Right Of Triangle (Right)     */

	gl.Color3f(dsz, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, dsz, 0.0)    /* Top Of Triangle (Back)        */
	gl.Color3f(0.0, dsz, 0.0)     /* Green                         */
	gl.Vertex3f(dsz, -dsz, -dsz)  /* Left Of Triangle (Back)       */
	gl.Color3f(0.0, 0.0, dsz)     /* Blue                          */
	gl.Vertex3f(-dsz, -dsz, -dsz) /* Right Of Triangle (Back)      */

	gl.Color3f(dsz, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, dsz, 0.0)    /* Top Of Triangle (Left)        */
	gl.Color3f(0.0, 0.0, dsz)     /* Blue                          */
	gl.Vertex3f(-dsz, -dsz, -dsz) /* Left Of Triangle (Left)       */
	gl.Color3f(0.0, dsz, 0.0)     /* Green                         */
	gl.Vertex3f(-dsz, -dsz, dsz)  /* Right Of Triangle (Left)      */
	gl.End()                      /* Finished Drawing The Triangle */

}
// 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
	}
}
예제 #16
0
파일: main.go 프로젝트: yohcop/cubopolis.go
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()
	//*/
}