Exemplo n.º 1
0
func InitViewport() {
	gl.Viewport(0, 0, gl.Sizei(Width), gl.Sizei(Height))
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	x := gl.Double(float64(Height) / float64(Width))
	gl.Frustum(-1./2., 1./2., -x/2, x/2, 10, 100)
}
Exemplo n.º 2
0
func perspective(fov, aspect, zNear, zFar gl.Double) {
	var xmin, xmax, ymin, ymax gl.Double

	ymax = zNear * gl.Double(math.Tan(float64(fov*math.Pi/360.0)))
	ymin = -ymax

	xmin = ymin * aspect
	xmax = ymax * aspect

	xmin += -1.0 / zNear
	xmax += -1.0 / zNear

	gl.Frustum(xmin, xmax, ymin, ymax, zNear, zFar)
}
Exemplo n.º 3
0
func SetUpCamera(
	screenWidth int32,
	screenHeight int32,
	lb *LevelBlueprint,
	playerIndex int32) {
	pb := &lb.Players[playerIndex]

	// Calculate the distance between the near plane and the camera. We want
	// (PaddleAreaWidth / 2) / cameraDist = tan(CameraHorzFovDegrees / 2)
	t := math.Tan(math.Pi * Config.CameraHorzFovDegrees / 360)
	cameraDist := pb.PaddleAreaWidth / (2 * t)
	cameraPos := pb.PaddleAreaCenter.Minus(
		pb.Orientation.Forward.Times(cameraDist))

	// Set up the projection matrix.
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, gl.Sizei(screenWidth), gl.Sizei(screenHeight))
	gl.Frustum(
		gl.Double(-pb.PaddleAreaWidth/2), gl.Double(pb.PaddleAreaWidth/2),
		gl.Double(-pb.PaddleAreaHeight/2), gl.Double(pb.PaddleAreaHeight/2),
		gl.Double(cameraDist), gl.Double(cameraDist+Config.ViewDepth))

	// Set up the modelview matrix.
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	transformation := [16]gl.Double{
		gl.Double(pb.Orientation.Right.X),
		gl.Double(pb.Orientation.Up.X),
		gl.Double(-pb.Orientation.Forward.X),
		gl.Double(0.0),
		gl.Double(pb.Orientation.Right.Y),
		gl.Double(pb.Orientation.Up.Y),
		gl.Double(-pb.Orientation.Forward.Y),
		gl.Double(0.0),
		gl.Double(pb.Orientation.Right.Z),
		gl.Double(pb.Orientation.Up.Z),
		gl.Double(-pb.Orientation.Forward.Z),
		gl.Double(0.0),
		gl.Double(0.0), gl.Double(0.0), gl.Double(0.0), gl.Double(1.0)}
	gl.MultMatrixd(&transformation[0])
	gl.Translated(
		gl.Double(-cameraPos.X),
		gl.Double(-cameraPos.Y),
		gl.Double(-cameraPos.Z))
}
Exemplo n.º 4
0
func (o *OpenGl) initScene() (err error) {
	gl.ClearColor(0.0, 0.0, 0.0, 0.0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)

	ambient := []gl.Float{0.5, 0.5, 0.5, 1}
	diffuse := []gl.Float{1, 1, 1, 1}
	position := []gl.Float{-5, 5, 10, 0}
	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0])
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0])
	gl.Lightfv(gl.LIGHT0, gl.POSITION, &position[0])

	gl.Viewport(0, 0, gl.Sizei(o.width), gl.Sizei(o.height))
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.0, 10.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	return nil
}
Exemplo n.º 5
0
func initScene() (err error) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)

	gl.ClearColor(0.5, 0.5, 0.5, 0.0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)

	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0])
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0])
	gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightpos[0])
	gl.Enable(gl.LIGHT0)

	gl.Viewport(0, 0, Width, Height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.0, 10.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	texture, err = createTextureFromBytes(gopher_png[:])
	return
}
Exemplo n.º 6
0
func initScene() {
	gl.Enable(gl.DEPTH_TEST)
	gl.Enable(gl.LIGHTING)

	gl.ClearColor(0.1, 0.1, 0.6, 1.0)
	gl.ClearDepth(1)
	gl.DepthFunc(gl.LEQUAL)

	gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0])
	gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0])
	gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightPos[0])
	gl.Enable(gl.LIGHT0)

	gl.Viewport(0, 0, Width, Height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1, 1, -1, 1, 1.0, 1000.0)
	gl.Rotatef(20, 1, 0, 0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.PushMatrix()

	return
}