Exemple #1
0
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()

	gl.Translatef(0, 0, -20+globalState.MousePos.Z*globalState.speed)

	gl.Rotatef(globalState.Rot.X, 1, 0, 0)
	gl.Rotatef(globalState.Rot.Y, 0, 1, 0)
	gl.Rotatef(globalState.Rot.Z, 0, 0, 1)

	if globalState.speed != 1 {
		gl.Scalef(globalState.speed, globalState.speed, globalState.speed)
	}

	gl.RenderMode(gl.RENDER)

	gl.Begin(gl.QUADS)
	for i, _ := range mesh.Faces {
		if colors, ok := faceColor[i]; ok {
			gl.Color3f(colors[0], colors[1], colors[2])
		} else {
			faceColor[i] = make([]float32, 3)
			faceColor[i][0] = rand.Float32()
			faceColor[i][1] = rand.Float32()
			faceColor[i][2] = rand.Float32()
			gl.Color3f(faceColor[i][0], faceColor[i][1], faceColor[i][2])
		}

		face := &mesh.Faces[i]
		for j, _ := range face.Vertices {
			var v *wfobj.Vertex
			if len(face.Normals) > 0 {
				v = &face.Normals[j]
				gl.Normal3f(v.X, v.Y, v.Z)
			}
			v = &face.Vertices[j]
			gl.Vertex3f(v.X, v.Y, v.Z)
		}
	}
	gl.End()
	gl.Finish()
	gl.Flush()

	sdl.GL_SwapBuffers()
}
// 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
	}
}
Exemple #3
0
Fichier : model.go Projet : 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()
}
// 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
	}
}
Exemple #5
0
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()
}