Example #1
0
func renderTile(x, y float32, tex *gl.Texture) {
	tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0, 0)
	gl.Vertex2f(x, y)
	gl.TexCoord2f(1, 0)
	gl.Vertex2f(x+1, y)
	gl.TexCoord2f(1, 1)
	gl.Vertex2f(x+1, y+1)
	gl.TexCoord2f(0, 1)
	gl.Vertex2f(x, y+1)
	gl.End()
}
Example #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()
}
Example #3
0
func (s sprite) render() {
	gl.Translatef(float32(s.X), float32(s.Y), float32(s.Z))
	gl.Rotatef(90.0, 1.0, 0.0, 0.0)

	s.tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0.0, 1.0)
	gl.Vertex3f(-s.width/2.0, -s.height/2.0, 0.0)
	gl.TexCoord2f(1.0, 1.0)
	gl.Vertex3f(s.width/2.0, -s.height/2.0, 0.0)
	gl.TexCoord2f(1.0, 0.0)
	gl.Vertex3f(s.width/2.0, s.height/2.0, 0.0)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-s.width/2.0, s.height/2.0, 0.0)
	gl.End()
	s.tex.Unbind(gl.TEXTURE_2D)
}
Example #4
0
func (v *Video) Render() {
	for running {
		select {
		case dimensions := <-v.resize:
			v.ResizeEvent(dimensions[0], dimensions[1])
		case val := <-v.tick:
			slice := make([]uint8, len(val)*3)
			for i := 0; i < len(val); i = i + 1 {
				slice[i*3+0] = (uint8)((val[i] >> 16) & 0xff)
				slice[i*3+1] = (uint8)((val[i] >> 8) & 0xff)
				slice[i*3+2] = (uint8)((val[i]) & 0xff)
			}

			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

			v.tex.Bind(gl.TEXTURE_2D)

			if ppu.OverscanEnabled {
				gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 240, 224, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			} else {
				gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 256, 240, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			}

			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()

			if v.screen != nil {
				sdl.GL_SwapBuffers()
				v.fpsmanager.FramerateDelay()
			}
		}
	}
}
Example #5
0
File: ca.go Project: samnardoni/ca
func draw() {
	for y := 0; y < Size; y++ {
		for x := 0; x < Size; x++ {

			var color uint8
			if grid.Front()[y][x] {
				color = 0x00
			} else {
				color = 0xFF
			}

			pixels[(y*Size+x)*3+0] = color
			pixels[(y*Size+x)*3+1] = color
			pixels[(y*Size+x)*3+2] = color

		}
	}

	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.TexImage2D(gl.TEXTURE_2D, 0, 3, Size, Size, 0, gl.RGB, gl.UNSIGNED_BYTE, pixels)

	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

	gl.Begin(gl.QUADS)
	gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
	gl.Vertex3f(1.0, 1.0, 0.0)
	gl.TexCoord2f(0.0, 0.0)
	gl.Vertex3f(-1.0, 1.0, 0.0)
	gl.End()

	glfw.SwapBuffers()
}
Example #6
0
File: model.go Project: iand/go
// Function GLDraw draws the model into the current GL scene. It assumes that the context is already
// set up, including any translation and rotation.
func (model *Model) GLDraw() {
	var a, b, c float32
	var v *Vertex

	// Start drawing triangles
	gl.Begin(gl.TRIANGLES)

	for _, triangle := range model.triangles {
		triangleNormals := triangle.TriangleNormals()
		textureCoordinates := triangle.TextureCoordinates()

		// Set the normal. Assume it's a flat triangle (the normals at all 3 vertices are equal)
		a, b, c = triangleNormals.Vertex1Normal()
		gl.Normal3f(a, b, c)

		// Vertex 1
		a, b = textureCoordinates.Vertex1Coord()
		gl.TexCoord2f(a, b)
		v = triangle.Vertex1()
		gl.Vertex3f(v.X(), v.Y(), v.Z())

		// Vertex 2
		a, b = textureCoordinates.Vertex2Coord()
		gl.TexCoord2f(a, b)
		v = triangle.Vertex2()
		gl.Vertex3f(v.X(), v.Y(), v.Z())

		// Vertex 3
		a, b = textureCoordinates.Vertex3Coord()
		gl.TexCoord2f(a, b)
		v = triangle.Vertex3()
		gl.Vertex3f(v.X(), v.Y(), v.Z())
	}

	// Finish
	gl.End()
}
Example #7
0
func (v *Video) Render() {
	runtime.LockOSThread()

	for running {
		select {
		case val := <-v.tick:
			slice := make([]uint8, len(val)*3)
			for i := 0; i < len(val); i = i + 1 {
				slice[i*3+0] = (uint8)((val[i] >> 16) & 0xff)
				slice[i*3+1] = (uint8)((val[i] >> 8) & 0xff)
				slice[i*3+2] = (uint8)((val[i]) & 0xff)
			}

			gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

			v.tex.Bind(gl.TEXTURE_2D)
			gl.TexImage2D(gl.TEXTURE_2D, 0, 3, 256, 240, 0, gl.RGB, gl.UNSIGNED_BYTE, slice)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
			gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)

			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 1.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(1.0, 0.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()

			glfw.SwapBuffers()
			v.fpsmanager.FramerateDelay()
		}
	}
}
// 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
	}
}
// 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
	}
}
Example #10
0
File: main.go Project: sycoso/glfw
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(0, 0, z)

	gl.Rotatef(rotation[0], 1, 0, 0)
	gl.Rotatef(rotation[1], 0, 1, 0)

	rotation[0] += speed[0]
	rotation[1] += speed[1]

	textures[filter].Bind(gl.TEXTURE_2D)

	gl.Begin(gl.QUADS)
	// Front Face
	gl.Normal3f(0, 0, 1) // Normal Pointing Towards Viewer
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1) // Point 1 (Front)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) // Point 2 (Front)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Front)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) // Point 4 (Front)
	// Back Face
	gl.Normal3f(0, 0, -1) // Normal Pointing Away From Viewer
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Back)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1) // Point 2 (Back)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1) // Point 3 (Back)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1) // Point 4 (Back)
	// Top Face
	gl.Normal3f(0, 1, 0) // Normal Pointing Up
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Point 1 (Top)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1) // Point 2 (Top)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1) // Point 3 (Top)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 4 (Top)
	// Bottom Face
	gl.Normal3f(0, -1, 0) // Normal Pointing Down
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Bottom)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1) // Point 2 (Bottom)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 3 (Bottom)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 4 (Bottom)
	// Right face
	gl.Normal3f(1, 0, 0) // Normal Pointing Right
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1) // Point 1 (Right)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Point 2 (Right)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1) // Point 3 (Right)
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Point 4 (Right)
	// Left Face
	gl.Normal3f(-1, 0, 0) // Normal Pointing Left
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1) // Point 1 (Left)
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Point 2 (Left)
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1) // Point 3 (Left)
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1)
	gl.End()

	glfw.SwapBuffers()
}
Example #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)
	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
	}
}
Example #12
0
File: main.go Project: andrebq/glfw
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.LoadIdentity()

	gl.Translatef(0, 0, -5)

	gl.Rotatef(rotation[0], 1, 0, 0)
	gl.Rotatef(rotation[1], 0, 1, 0)
	gl.Rotatef(rotation[2], 0, 0, 1)

	rotation[0] += 0.3
	rotation[1] += 0.2
	rotation[2] += 0.4

	textures[0].Bind(gl.TEXTURE_2D)

	gl.Begin(gl.QUADS)
	// Front Face
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, 1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, 1) // Top Left Of The Texture and Quad
	// Back Face
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, -1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, -1) // Bottom Left Of The Texture and Quad
	// Top Face
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, 1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, 1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Top Right Of The Texture and Quad
	// Bottom Face
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, -1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, -1, -1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Right Of The Texture and Quad
	// Right face
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(1, -1, -1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(1, 1, -1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(1, 1, 1) // Top Left Of The Texture and Quad
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(1, -1, 1) // Bottom Left Of The Texture and Quad
	// Left Face
	gl.TexCoord2f(0, 0)
	gl.Vertex3f(-1, -1, -1) // Bottom Left Of The Texture and Quad
	gl.TexCoord2f(1, 0)
	gl.Vertex3f(-1, -1, 1) // Bottom Right Of The Texture and Quad
	gl.TexCoord2f(1, 1)
	gl.Vertex3f(-1, 1, 1) // Top Right Of The Texture and Quad
	gl.TexCoord2f(0, 1)
	gl.Vertex3f(-1, 1, -1) // Top Left Of The Texture and Quad
	gl.End()

	glfw.SwapBuffers()
}
Example #13
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
	}
}