Beispiel #1
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	bitmap_output(40, 35, "This is written in a GLUT bitmap font.", glut.BITMAP_TIMES_ROMAN_24)
	bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.", glut.BITMAP_9_BY_15)
	bitmap_output(70, 240, "                Helvetica is yet another bitmap font.", glut.BITMAP_HELVETICA_18)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	glu.Perspective(40.0, 1.0, 0.1, 20.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */
		0.0, 0.0, 0.0, /* center is at (0,0,0) */
		0.0, 1.0, 0.0) /* up is in postivie Y direction */
	gl.PushMatrix()
	gl.Translatef(0, 0, -4)
	gl.Rotatef(50, 0, 1, 0)
	stroke_output(-2.5, 1.1, "  This is written in a", glut.STROKE_ROMAN)
	stroke_output(-2.5, 0, " GLUT stroke font.", glut.STROKE_ROMAN)
	stroke_output(-2.5, -1.1, "using 3D perspective.", glut.STROKE_ROMAN)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()
	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
	gl.MatrixMode(gl.MODELVIEW)
	gl.Flush()
}
Beispiel #2
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	positionCamera()

	gl.Begin(gl.QUADS)
	drawTerrain()
	gl.End()

	gl.Flush()
}
Beispiel #3
0
func display() {
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.Begin(gl.TRIANGLES)
	gl.Color3f(0.0, 0.0, 1.0) /* blue */
	gl.Vertex2i(0, 0)
	gl.Color3f(0.0, 1.0, 0.0) /* green */
	gl.Vertex2i(200, 200)
	gl.Color3f(1.0, 0.0, 0.0) /* red */
	gl.Vertex2i(20, 200)
	gl.End()
	gl.Flush() /* Single buffered, so needs a flush. */
}
Beispiel #4
0
func plot_list(list uint) {
	gl.Enable(gl.BLEND)
	gl.Enable(gl.POINT_SMOOTH)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.PointSize(1.0)
	gl.LoadIdentity()
	gl.Rotated(xrot, 1, 0, 0)
	gl.Rotated(yrot, 0, 1, 0)
	gl.Rotated(zrot, 0, 0, 1)
	gl.Scaled(scale, scale, scale)
	gl.Translated(xoff, yoff, zoff)
	gl.CallList(list)
	gl.Flush()
}
Beispiel #5
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()
}
Beispiel #6
0
func Draw(t int64) {
	console.culledVertices = 0
	console.vertices = 0
	gVertexBuffer.Reset()

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

	gl.Color4ub(192, 192, 192, 255)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.COLOR_MATERIAL)
	gl.LoadIdentity()

	center := ThePlayer.Position()

	matrix := ModelMatrix().Float32()
	gl.MultMatrixf(&matrix[0])

	// Sun
	gl.Materialfv(gl.FRONT, gl.AMBIENT, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.DIFFUSE, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.SPECULAR, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.SHININESS, []float32{0.0, 0.0, 0.0, 1})

	daylightIntensity := float32(SUNLIGHT_LEVELS[sunlightLevel])

	gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{daylightIntensity / 2.5, daylightIntensity / 2.5, daylightIntensity / 2.5, 1})

	gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{30 * float32(math.Sin(ThePlayer.Heading()*math.Pi/180)), 60, 30 * float32(math.Cos(ThePlayer.Heading()*math.Pi/180)), 0})
	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity * 2, daylightIntensity * 2, daylightIntensity * 2, 1})
	gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})

	gl.RenderMode(gl.RENDER)

	var selectedBlockFace *BlockFace
	if !pause.visible && !inventory.visible {
		selectedBlockFace = viewport.SelectedBlockFace()
	}
	ThePlayer.Draw(center, selectedBlockFace)
	TheWorld.Draw(center, selectedBlockFace)

	if pause.visible {
		pause.Draw(t)
	} else if inventory.visible {
		inventory.Draw(t)
	} else {
		picker.Draw(t)

	}

	if console.visible {
		console.Draw(t)
	}

	gl.Finish()
	gl.Flush()
	sdl.GL_SwapBuffers()
	console.framesDrawn++
}
Beispiel #7
0
func Draw(t int64) {
	console.culledVertices = 0
	console.vertices = 0

	gVertexBuffer.Reset()

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

	gl.Color4ub(192, 192, 192, 255)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	//gl.Enable(gl.FOG)
	gl.Enable(gl.LIGHTING)
	gl.Enable(gl.LIGHT0)
	gl.Enable(gl.COLOR_MATERIAL)

	if timeOfDay < 5.3 || timeOfDay > 20.7 {
		gl.Enable(gl.LIGHT1)
	} else {
		gl.Disable(gl.LIGHT1)
	}

	// CheckGLError()
	gl.LoadIdentity()

	center := ThePlayer.Position()

	// matrix := *viewport.matrix.Float32()
	matrix := ModelMatrix().Float32()
	gl.MultMatrixf(&matrix[0])
	//gl.Translatef(-float32(center[XAXIS]), -float32(center[YAXIS]), -float32(center[ZAXIS]))

	// Sun
	gl.Materialfv(gl.FRONT, gl.AMBIENT, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.DIFFUSE, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.SPECULAR, []float32{0.1, 0.1, 0.1, 1})
	gl.Materialfv(gl.FRONT, gl.SHININESS, []float32{0.0, 0.0, 0.0, 1})
	var daylightIntensity float32 = 0.45
	var nighttimeIntensity float32 = 0.15
	if timeOfDay < 5 || timeOfDay > 21 {
		gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{0.2, 0.2, 0.2, 1})
		daylightIntensity = 0.01
	} else if timeOfDay < 6 {
		daylightIntensity = nighttimeIntensity + daylightIntensity*(timeOfDay-5)
	} else if timeOfDay > 20 {
		daylightIntensity = nighttimeIntensity + daylightIntensity*(21-timeOfDay)
	}

	gl.LightModelfv(gl.LIGHT_MODEL_AMBIENT, []float32{daylightIntensity / 2.5, daylightIntensity / 2.5, daylightIntensity / 2.5, 1})

	gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{30 * float32(math.Sin(ThePlayer.Heading()*math.Pi/180)), 60, 30 * float32(math.Cos(ThePlayer.Heading()*math.Pi/180)), 0})
	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})
	// gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity, daylightIntensity, daylightIntensity,1})
	// gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity,1})
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{daylightIntensity * 2, daylightIntensity * 2, daylightIntensity * 2, 1})
	gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{daylightIntensity, daylightIntensity, daylightIntensity, 1})

	// Torch
	// ambient := float32(0.6)
	// specular := float32(0.6)
	// diffuse := float32(1)

	// gl.Lightfv(gl.LIGHT1, gl.POSITION, []float32{float32(ThePlayer.position[XAXIS]), float32(ThePlayer.position[YAXIS] + 1), float32(ThePlayer.position[ZAXIS]), 1})
	// gl.Lightfv(gl.LIGHT1, gl.AMBIENT, []float32{ambient, ambient, ambient, 1})
	// gl.Lightfv(gl.LIGHT1, gl.SPECULAR, []float32{specular, specular, specular, 1})
	// gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, []float32{diffuse, diffuse, diffuse, 1})
	// gl.Lightf(gl.LIGHT1, gl.CONSTANT_ATTENUATION, 1.5)
	// gl.Lightf(gl.LIGHT1, gl.LINEAR_ATTENUATION, 0.5)
	// gl.Lightf(gl.LIGHT1, gl.QUADRATIC_ATTENUATION, 0.01)
	// gl.Lightf(gl.LIGHT1, gl.SPOT_CUTOFF, 35)
	// gl.Lightf(gl.LIGHT1, gl.SPOT_EXPONENT, 2.0)
	// gl.Lightfv(gl.LIGHT1, gl.SPOT_DIRECTION, []float32{float32(math.Cos(ThePlayer.Heading() * math.Pi / 180)), float32(-0.7), -float32(math.Sin(ThePlayer.Heading() * math.Pi / 180))})

	gl.RenderMode(gl.RENDER)

	selectedBlockFace := viewport.SelectedBlockFace()
	ThePlayer.Draw(center, selectedBlockFace)
	TheWorld.Draw(center, selectedBlockFace)

	if pause.visible {
		pause.Draw(t)
	} else if inventory.visible {
		inventory.Draw(t)
	} else {
		picker.Draw(t)

	}

	if console.visible {
		console.Draw(t)
	}

	gl.Finish()
	gl.Flush()
	sdl.GL_SwapBuffers()
	// runtime.GC()
}