예제 #1
0
func (s *Sprite) Draw(x, y, angle, scale float32, blend bool) {
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.COLOR_MATERIAL)
	if blend {
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
	} else {
		gl.Disable(gl.BLEND)
		gl.BlendFunc(gl.ONE, gl.ZERO)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(x, y, 0)
	gl.Rotatef(angle*360/(2*math.Pi), 0, 0, 1)
	gl.Scalef(scale, scale, 1)
	s.tex.Bind(gl.TEXTURE_2D)
	gl.Begin(gl.QUADS)
	gl.Color3f(1, 1, 1)
	gl.TexCoord2d(0, 0)
	gl.Vertex3f(-0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 0)
	gl.Vertex3f(0.5*s.width, -0.5*s.height, 0)
	gl.TexCoord2d(1, 1)
	gl.Vertex3f(0.5*s.width, 0.5*s.height, 0)
	gl.TexCoord2d(0, 1)
	gl.Vertex3f(-0.5*s.width, 0.5*s.height, 0)
	gl.End()
	gl.Disable(gl.TEXTURE_2D)
	gl.Disable(gl.BLEND)
}
예제 #2
0
func (self *Picker) Draw(t int64) {

	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()

	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Begin(gl.TRIANGLE_FAN)
	gl.Color4ub(0, 0, 0, 128)
	gl.Vertex2f(self.x, self.y)
	for angle := float64(0); angle <= 2*math.Pi; angle += math.Pi / 2 / 10 {
		gl.Vertex2f(self.x-float32(math.Sin(angle))*self.radius, self.y+float32(math.Cos(angle))*self.radius)
	}
	gl.End()

	self.DrawItemHighlight(t, ThePlayer.currentAction)
	self.DrawPlayerItems(t, true)

	gl.PopMatrix()

}
예제 #3
0
파일: pause.go 프로젝트: codygman/amberfell
func (self *Pause) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 240)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	str := "paused"
	h, w := pauseFont.Measure(str)

	// x := (viewport.rplane - viewport.lplane - w) / 2
	// y := (viewport.tplane - viewport.bplane - h) / 2
	gl.Translated(-w/2, -h/2, 0)
	pauseFont.Print(str)

	gl.PopMatrix()

}
예제 #4
0
func (self *Console) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	h := float32(consoleFont.height) * PIXEL_SCALE
	margin := float32(3.0) * PIXEL_SCALE
	consoleHeight := 3 * h

	gl.MatrixMode(gl.MODELVIEW)

	gl.LoadIdentity()
	gl.Color4ub(0, 0, 0, 208)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane)+consoleHeight+margin*2) // Bottom Left Of The Texture and Quad
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane)+consoleHeight+margin*2) // Bottom Right Of The Texture and Quad
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))                        // Top Right Of The Texture and Quad
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))                        // Top Left Of The Texture and Quad
	gl.End()

	gl.Translatef(float32(viewport.lplane)+margin, float32(viewport.bplane)+consoleHeight+margin-h, 0)
	consoleFont.Print(fmt.Sprintf("FPS: %5.2f V: %d (%d) CH: %d M: %d", self.fps, self.vertices, self.culledVertices, len(TheWorld.chunks), len(TheWorld.mobs)))
	gl.LoadIdentity()
	gl.Translatef(float32(viewport.lplane)+margin, float32(viewport.bplane)+consoleHeight+margin-2*h, 0)

	consoleFont.Print(fmt.Sprintf("X: %5.2f Y: %4.2f Z: %5.2f H: %5.2f (%s) D: %0.1f (%d)", ThePlayer.position[XAXIS], ThePlayer.position[YAXIS], ThePlayer.position[ZAXIS], ThePlayer.heading, HeadingToCompass(ThePlayer.heading), ThePlayer.distanceTravelled, ThePlayer.distanceFromStart))

	gl.LoadIdentity()
	gl.Translatef(float32(viewport.lplane)+margin, float32(viewport.bplane)+consoleHeight+margin-3*h, 0)

	numgc := uint32(0)
	avggc := float64(0)
	var last3 [3]float64
	if self.mem.NumGC > 3 {
		numgc = self.mem.NumGC
		avggc = float64(self.mem.PauseTotalNs) / float64(self.mem.NumGC) / 1e6
		index := int(numgc) - 1
		if index > 255 {
			index = 255
		}

		last3[0] = float64(self.mem.PauseNs[index]) / 1e6
		last3[1] = float64(self.mem.PauseNs[index-1]) / 1e6
		last3[2] = float64(self.mem.PauseNs[index-2]) / 1e6
	}

	consoleFont.Print(fmt.Sprintf("Mem: %.1f/%.1f   GC: %.1fms [%d: %.1f, %.1f, %.1f] ChGen: %.1fms | Sc: %.1f TOD: %.1f", float64(self.mem.Alloc)/(1024*1024), float64(self.mem.Sys)/(1024*1024), avggc, numgc, last3[0], last3[1], last3[2], float64(self.chunkGenerationTime)/1e6, viewport.scale, timeOfDay))

	gl.PopMatrix()
}
예제 #5
0
func (t *Skybox) RenderScaled(center, scale *Vec3) {
	v := []*Vec3{
		V3(-1, -1, 1),
		V3(1, -1, 1),
		V3(1, 1, 1),
		V3(-1, 1, 1),
		V3(-1, -1, -1),
		V3(1, -1, -1),
		V3(1, 1, -1),
		V3(-1, 1, -1)}
	for i := 0; i < 8; i++ {
		v[i].Muli(scale).Addi(center)
	}

	if globals.UseShader {
		program.Unuse()
	}

	//*//save attributes and change them
	gl.PushAttrib(gl.ENABLE_BIT | gl.TEXTURE_BIT)
	defer gl.PopAttrib() //reset to old attributes
	gl.Enable(gl.TEXTURE_2D)
	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.BLEND) //*/
	oneSide := func(tex *texture.Texture, a, b, c, d int, n *Vec3) {
		tex.BindForSkybox(color.White)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
		gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
		gl.Begin(gl.TRIANGLES)
		gl.Normal3dv(n.Slc())
		gl.TexCoord2i(0, 0)
		gl.Vertex3dv(v[a].Slc())
		gl.TexCoord2i(1, 0)
		gl.Vertex3dv(v[b].Slc())
		gl.TexCoord2i(1, 1)
		gl.Vertex3dv(v[c].Slc())
		gl.TexCoord2i(0, 0)
		gl.Vertex3dv(v[a].Slc())
		gl.TexCoord2i(1, 1)
		gl.Vertex3dv(v[c].Slc())
		gl.TexCoord2i(0, 1)
		gl.Vertex3dv(v[d].Slc())
		gl.End()
	}
	oneSide(t.up, 2, 3, 7, 6, V3(0, -1, 0))
	oneSide(t.dn, 5, 4, 0, 1, V3(0, 1, 0))
	oneSide(t.lt, 5, 1, 2, 6, V3(1, 0, 0))
	oneSide(t.rt, 0, 4, 7, 3, V3(-1, 0, 0))
	oneSide(t.ft, 1, 0, 3, 2, V3(0, 0, -1))
	oneSide(t.bk, 4, 5, 6, 7, V3(0, 0, 1))
}
예제 #6
0
파일: app.go 프로젝트: swantescholz/coding
func (this *App) draw() {
	gl.Disable(gl.CULL_FACE)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.DEPTH_TEST)

	White.Gl()
	var w, h = Double(this.win.Width()), Double(this.win.Height())
	drawTexRect(this.texmandel, V2(0, 0), V2(w, h))
	var col = color24.NewColor24(0, 0, 0)
	this.frac.Gradient().Interpolate(col, this.cursor.Pos.X)
	this.cursor.Draw(w, h, col)

	this.win.FinishFrame()
}
예제 #7
0
func main() {
	glfw.Init()
	defer glfw.Terminate()

	glfw.OpenWindow(640, 480, 8, 8, 8, 8, 0, 0, glfw.Windowed)
	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Tile test")
	glfw.Enable(glfw.StickyKeys)
	glfw.SetSwapInterval(1)
	glfw.SetKeyCallback(inputCallback)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, GridWidth, GridHeight, 0, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.Disable(gl.DEPTH_TEST)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	initResources()
	initWorld()

	for Running {
		if (time.Since(DT).Nanoseconds() / 1000000) > 15 { //don't loop faster than every 15ms
			DT = time.Now()
			gl.Clear(gl.COLOR_BUFFER_BIT)
			player.update()
			renderScene()
			glfw.SwapBuffers()
		}
	}
}
예제 #8
0
// handle key press events
func handleKeyPress(keysym sdl.Keysym) {
	switch keysym.Sym {
	case sdl.K_f: // f key pages through filters
		filter = (filter + 1) % 3
		p("new filter:", filter)
	case sdl.K_l: // l key toggles light
		light = !light
		if light {
			p("light on")
			gl.Enable(gl.LIGHTING)
		} else {
			p("light off")
			gl.Disable(gl.LIGHTING)
		}
	case sdl.K_PAGEUP: // page up zooms into the scene
		z -= 0.02
	case sdl.K_PAGEDOWN: // zoom out of the scene
		z += 0.02
	case sdl.K_UP: // up arrow affects x rotation
		xspeed -= 0.01
	case sdl.K_DOWN: // down arrow affects x rotation
		xspeed += 0.01
	case sdl.K_RIGHT: // affect y rotation
		yspeed += 0.01
	case sdl.K_LEFT: // affect y rotation
		yspeed -= 0.01
	case sdl.K_ESCAPE:
		Quit(0)
	case sdl.K_F1:
		sdl.WM_ToggleFullScreen(surface)
	}
}
예제 #9
0
func (v *Video) Reshape(width int, height int) {
	x_offset := 0
	y_offset := 0

	r := ((float64)(height)) / ((float64)(width))

	if r > 0.9375 { // Height taller than ratio
		h := (int)(math.Floor((float64)(0.9375 * (float64)(width))))
		y_offset = (height - h) / 2
		height = h
	} else if r < 0.9375 { // Width wider
		var scrW, scrH float64
		if ppu.OverscanEnabled {
			scrW = 240.0
			scrH = 224.0
		} else {
			scrW = 256.0
			scrH = 240.0
		}

		w := (int)(math.Floor((float64)((scrH / scrW) * (float64)(height))))
		x_offset = (width - w) / 2
		width = w
	}

	gl.Viewport(x_offset, y_offset, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
예제 #10
0
파일: main.go 프로젝트: andrebq/glfw
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = false
	case 76: // L
		if state == 1 {
			if light = !light; !light {
				gl.Disable(gl.LIGHTING)
			} else {
				gl.Enable(gl.LIGHTING)
			}
		}
	case 70: // F
		if state == 1 {
			if filter++; filter >= len(textures) {
				filter = 0
			}
		}
	case glfw.KeyPageup:
		z -= 0.2
	case glfw.KeyPagedown:
		z += 0.2
	case glfw.KeyUp:
		speed[0] -= 0.1
	case glfw.KeyDown:
		speed[0] += 0.1
	case glfw.KeyLeft:
		speed[1] -= 0.1
	case glfw.KeyRight:
		speed[1] += 0.1
	}
}
예제 #11
0
파일: main.go 프로젝트: sycoso/glfw
func onKey(key, state int) {
	switch key {
	case glfw.KeyEsc:
		running = false
	case 'L':
		if state == 1 {
			if light = !light; !light {
				gl.Disable(gl.LIGHTING)
			} else {
				gl.Enable(gl.LIGHTING)
			}
		}
	case 'F':
		if state == 1 {
			if filter++; filter >= len(textures) {
				filter = 0
			}
		}
	case 'B': // B
		if state == 1 {
			if blend = !blend; blend {
				gl.Enable(gl.BLEND)
				gl.Disable(gl.DEPTH_TEST)
			} else {
				gl.Disable(gl.BLEND)
				gl.Enable(gl.DEPTH_TEST)
			}
		}
	case glfw.KeyPageup:
		z -= 0.2
	case glfw.KeyPagedown:
		z += 0.2
	case glfw.KeyUp:
		speed[0] -= 0.1
	case glfw.KeyDown:
		speed[0] += 0.1
	case glfw.KeyLeft:
		speed[1] -= 0.1
	case glfw.KeyRight:
		speed[1] += 0.1
	}
}
예제 #12
0
func uploadTexture(img *image.RGBA) gl.Texture {
	gl.Enable(gl.TEXTURE_2D)
	tex := gl.GenTexture()
	tex.Bind(gl.TEXTURE_2D)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST)
	gl.TexImage2D(gl.TEXTURE_2D, 0, 4, img.Bounds().Max.X, img.Bounds().Max.Y,
		0, gl.RGBA, gl.UNSIGNED_BYTE, img.Pix)
	gl.Disable(gl.TEXTURE_2D)
	return tex
}
예제 #13
0
파일: main.go 프로젝트: sycoso/glfw
func main() {
	var err error
	if err = glfw.Init(); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.Terminate()

	// Open window with FSAA samples (if possible).
	glfw.OpenWindowHint(glfw.FsaaSamples, 4)

	if err = glfw.OpenWindow(400, 400, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil {
		fmt.Fprintf(os.Stderr, "[e] %v\n", err)
		return
	}

	defer glfw.CloseWindow()

	glfw.SetWindowTitle("Aliasing Detector")
	glfw.SetSwapInterval(1)

	if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 {
		fmt.Fprintf(os.Stdout, "Context reports FSAA is supported with %d samples\n", samples)
	} else {
		fmt.Fprintf(os.Stdout, "Context reports FSAA is unsupported\n")
	}

	gl.MatrixMode(gl.PROJECTION)
	glu.Perspective(0, 1, 0, 1)

	for glfw.WindowParam(glfw.Opened) == 1 {
		time := float32(glfw.Time())

		gl.Clear(gl.COLOR_BUFFER_BIT)

		gl.LoadIdentity()
		gl.Translatef(0.5, 0, 0)
		gl.Rotatef(time, 0, 0, 1)

		gl.Enable(GL_MULTISAMPLE_ARB)
		gl.Color3f(1, 1, 1)
		gl.Rectf(-0.25, -0.25, 0.25, 0.25)

		gl.LoadIdentity()
		gl.Translatef(-0.5, 0, 0)
		gl.Rotatef(time, 0, 0, 1)

		gl.Disable(GL_MULTISAMPLE_ARB)
		gl.Color3f(1, 1, 1)
		gl.Rectf(-0.25, -0.25, 0.25, 0.25)
		glfw.SwapBuffers()
	}
}
예제 #14
0
파일: main.go 프로젝트: reiver/lifepack
func initialize(WIDTH, HEIGHT int) {

	gl.MatrixMode(gl.PROJECTION)

	gl.LoadIdentity()

	gl.Ortho(0, float64(WIDTH), float64(HEIGHT), 0, 0, 1)

	gl.MatrixMode(gl.MODELVIEW)

	gl.Disable(gl.DEPTH_TEST)
}
예제 #15
0
파일: app.go 프로젝트: swantescholz/coding
func (this *Cursor) Draw(w, h Double, col *color24.Color24) {
	var p = this.Pos.Mul(V2(w, h))
	var a = p.Add(V2(-10, -10))
	var b = p.Add(V2(10, -10))
	gl.Disable(gl.TEXTURE_2D)
	col.Gl()
	gl.Begin(gl.TRIANGLES)
	p.Gl()
	a.Gl()
	b.Gl()
	gl.End()
	gl.Enable(gl.TEXTURE_2D)
}
예제 #16
0
파일: asteroids.go 프로젝트: tmc/glut
func special(key, x, y int) {
	switch key {
	case glut.KEY_F1:
		gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
		gl.Enable(gl.BLEND)
		gl.Enable(gl.LINE_SMOOTH)
		gl.Enable(gl.POINT_SMOOTH)
	case glut.KEY_F2:
		gl.Disable(gl.BLEND)
		gl.Disable(gl.LINE_SMOOTH)
		gl.Disable(gl.POINT_SMOOTH)
	case glut.KEY_UP:
		thrust = true
		thrustTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_LEFT:
		left = true
		leftTime = glut.Get(glut.ELAPSED_TIME)
	case glut.KEY_RIGHT:
		right = true
		rightTime = glut.Get(glut.ELAPSED_TIME)
	}
}
예제 #17
0
파일: ca.go 프로젝트: samnardoni/ca
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
예제 #18
0
파일: video.go 프로젝트: wmbest2/Fergulator
func reshape(width int, height int) {
	x_offset := 0
	y_offset := 0

	r := ((float64)(height)) / ((float64)(width))

	if r > 0.9375 { // Height taller than ratio
		h := (int)(math.Floor((float64)(0.9375 * (float64)(width))))
		y_offset = (height - h) / 2
		height = h
	} else if r < 0.9375 { // Width wider
		w := (int)(math.Floor((float64)((256.0 / 240.0) * (float64)(height))))
		x_offset = (width - w) / 2
		width = w
	}

	gl.Viewport(x_offset, y_offset, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(-1, 1, -1, 1, -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Disable(gl.DEPTH_TEST)
}
예제 #19
0
func (self *Inventory) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 240)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	picker.DrawItemHighlight(t, 3)
	picker.DrawItemHighlight(t, 4)
	picker.DrawItemHighlight(t, 5)
	picker.DrawItemHighlight(t, 6)
	picker.DrawItemHighlight(t, 7)
	picker.DrawPlayerItems(t)

	const blocksize = float64(0.3)
	const COLSIZE = 12

	diam := blocksize * 2.4

	offset := diam + float64(4)*PIXEL_SCALE

	for i := 0; i < len(self.inventoryRects); i++ {
		x := float64(viewport.lplane) + float64(10)*PIXEL_SCALE + float64(i/COLSIZE)*offset
		y := float64(viewport.tplane) - float64(10)*PIXEL_SCALE - float64(i%COLSIZE)*offset
		self.inventoryRects[i] = Rect{x, y - diam, diam, diam}
		self.DrawItemSlot(t, self.inventoryRects[i])
	}

	slot := 0
	for i := 1; i < len(ThePlayer.inventory); i++ {
		if ThePlayer.inventory[i] > 0 {
			self.inventorySlots[slot] = uint16(i)
			self.DrawItem(t, ThePlayer.inventory[i], uint16(i), self.inventoryRects[slot])
			slot++
		}
	}

	for i := 0; i < len(self.componentSlots); i++ {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + float64(i)*offset
		y := float64(viewport.tplane) - (float64(10) * PIXEL_SCALE)
		self.componentRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.componentRects[i])
	}

	for i := 0; i < len(self.componentSlots); i++ {
		if self.componentSlots[i] != 0 {
			self.DrawItem(t, ThePlayer.inventory[self.componentSlots[i]], self.componentSlots[i], self.componentRects[i])
		}
	}

	for i := 0; i < len(self.productSlots); i++ {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + offset*float64(i%len(self.componentRects))
		y := float64(viewport.tplane) - (float64(10) * PIXEL_SCALE) - offset*float64(2+float64(i/len(self.componentRects)))
		self.productRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.productRects[i])
	}

	for i := 0; i < len(self.productSlots); i++ {
		if self.productSlots[i] != nil {
			self.DrawItem(t, self.productSlots[i].product.quantity, self.productSlots[i].product.item, self.productRects[i])
		}
	}

	var mousex, mousey int
	mousestate := sdl.GetMouseState(&mousex, &mousey)
	self.HandleMouse(mousex, mousey, mousestate)

	gl.PopMatrix()
}
예제 #20
0
func main() {
	runtime.LockOSThread()

	if sdl.Init(sdl.INIT_EVERYTHING) != 0 {
		log.Fatal(sdl.GetError())
	}
	var screen = sdl.SetVideoMode(screenWidth, screenHeight, 32, sdl.OPENGL|sdl.HWSURFACE|sdl.GL_DOUBLEBUFFER|sdl.FULLSCREEN)
	if screen == nil {
		log.Fatal(sdl.GetError())
	}
	sdl.WM_SetCaption("Lecture Hall Games", "")
	sdl.EnableUNICODE(1)
	if gl.Init() != 0 {
		log.Fatal("could not initialize OpenGL")
	}
	gl.Viewport(0, 0, int(screen.W), int(screen.H))
	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.DEPTH_TEST)
	gl.TexEnvi(gl.TEXTURE_ENV, gl.TEXTURE_ENV_MODE, gl.MODULATE)

	if mixer.OpenAudio(mixer.DEFAULT_FREQUENCY, mixer.DEFAULT_FORMAT,
		mixer.DEFAULT_CHANNELS, 4096) != 0 {
		log.Fatal(sdl.GetError())
	}

	if ttf.Init() != 0 {
		log.Fatal(sdl.GetError())
	}

	if p, err := build.Default.Import(basePkg, "", build.FindOnly); err == nil {
		os.Chdir(p.Dir)
	}

	var err error

	rand.Seed(time.Now().UnixNano())
	levelDir := fmt.Sprintf("data/levels/demolevel%d", 3+rand.Intn(numberLevels))
	//carsDir := fmt.Sprintf(" data/cars/car%d/", 1+rand.Intn(numberCars))
	if game, err = NewRacer(levelDir); err != nil {
		log.Fatal(err)
	}

	go func() {
		listen, err := net.Listen("tcp", ":8001")
		if err != nil {
			log.Fatal(err)
		}
		for {
			conn, err := listen.Accept()
			if err != nil {
				log.Println(err)
				continue
			}
			go handleConnection(conn)
		}
	}()

	running := true
	last := time.Now()
	for running {
		select {
		case event := <-sdl.Events:
			switch e := event.(type) {
			case sdl.QuitEvent:
				running = false
			case sdl.ResizeEvent:
				screen = sdl.SetVideoMode(int(e.W), int(e.H), 32, sdl.RESIZABLE)
			case sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					if e.Keysym.Sym == sdl.K_ESCAPE {
						running = false
					} else {
						game.KeyPressed(e.Keysym)
					}
				}
			}
		default:
		}

		current := time.Now()
		t := current.Sub(last)
		last = current

		mu.Lock()
		game.Update(t)
		game.Render(screen)
		mu.Unlock()

		sdl.GL_SwapBuffers()
	}

	sdl.Quit()
}
예제 #21
0
func (self *Inventory) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 208)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	picker.DrawItemHighlight(t, 3)
	picker.DrawItemHighlight(t, 4)
	picker.DrawItemHighlight(t, 5)
	picker.DrawItemHighlight(t, 6)
	picker.DrawItemHighlight(t, 7)
	picker.DrawPlayerItems(t, false)

	const blocksize = float64(0.3)
	const COLSIZE = 12

	slotsize := blocksize * 2.4
	slotstep := slotsize + float64(4)*PIXEL_SCALE
	slotsInRow := len(self.componentRects)

	xtools := float64(viewport.lplane) + 10.0*PIXEL_SCALE
	ytools := float64(viewport.tplane) - 10.0*PIXEL_SCALE - slotstep

	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)
	inventoryItemFont.Print("Inventory")
	gl.PopMatrix()
	for i := range self.inventoryRects {
		x := xtools + float64(i%slotsInRow)*slotstep
		y := ytools - float64(i/slotsInRow)*slotstep
		self.inventoryRects[i] = Rect{x, y - slotsize, slotsize, slotsize}
		self.DrawItemSlot(t, self.inventoryRects[i])
	}

	for i := range self.inventorySlots {
		if self.inventorySlots[i].item != 0 && self.inventorySlots[i].quantity > 0 {
			self.DrawItemInSlot(t, self.inventorySlots[i].quantity, self.inventorySlots[i].item, self.inventoryRects[i])
		}
	}

	xtools += slotstep * (1.0 + float64(slotsInRow))

	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)

	if self.currentCrafting == nil {
		inventoryItemFont.Print("Handcrafting")
	} else {
		inventoryItemFont.Print(self.currentCrafting.Label())
	}
	gl.PopMatrix()

	for i := range self.componentSlots {
		x := xtools + float64(i)*slotstep
		y := ytools
		self.componentRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

		self.DrawItemSlot(t, self.componentRects[i])
	}

	for i, cs := range self.componentSlots {
		if cs.item != 0 {
			self.DrawItemInSlot(t, cs.quantity, cs.item, self.componentRects[i])
		}
	}

	ytools -= slotstep * 2
	for i := range self.productSlots {
		x := xtools + slotstep*float64(i%slotsInRow)
		y := ytools - slotstep*float64(i/slotsInRow)
		self.productRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

		self.DrawItemSlot(t, self.productRects[i])
	}

	for i, ps := range self.productSlots {
		if ps != nil {
			self.DrawItemInSlot(t, ps.product.quantity, ps.product.item, self.productRects[i])
		}
	}

	ytools -= slotstep * float64(1+len(self.productRects)/slotsInRow)
	if self.currentContainer != nil {

		gl.PushMatrix()
		gl.LoadIdentity()
		gl.Translated(xtools, ytools+4*PIXEL_SCALE, 0)
		inventoryItemFont.Print(self.currentContainer.Label())
		gl.PopMatrix()

		for i := range self.containerRects {
			x := xtools + slotstep*float64(i%slotsInRow)
			y := ytools - slotstep*float64(i/slotsInRow)
			self.containerRects[i] = Rect{x, y - slotsize, slotsize, slotsize}

			self.DrawItemSlot(t, self.containerRects[i])
		}

		for i := 0; i < self.currentContainer.Slots(); i++ {
			if self.currentContainer.Item(i).item != 0 {
				self.DrawItemInSlot(t, self.currentContainer.Item(i).quantity, self.currentContainer.Item(i).item, self.containerRects[i])
			}
		}

	}

	var mousex, mousey int
	mousestate := sdl.GetMouseState(&mousex, &mousey)

	if self.selectedItem != nil {
		x, y := viewport.ScreenCoordsToWorld2D(uint16(mousex), uint16(mousey))
		self.DrawItem(t, self.selectedItem.quantity, self.selectedItem.item, x, y)
	}

	self.HandleMouse(mousex, mousey, mousestate)

	gl.PopMatrix()
}
예제 #22
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()
}
예제 #23
0
func (self *Inventory) Draw(t int64) {
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Disable(gl.DEPTH_TEST)
	gl.Disable(gl.LIGHTING)
	gl.Disable(gl.LIGHT0)
	gl.Disable(gl.LIGHT1)

	gl.Color4ub(0, 0, 0, 208)

	gl.Begin(gl.QUADS)
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.bplane))
	gl.Vertex2f(float32(viewport.rplane), float32(viewport.tplane))
	gl.Vertex2f(float32(viewport.lplane), float32(viewport.tplane))
	gl.End()

	picker.DrawItemHighlight(t, 3)
	picker.DrawItemHighlight(t, 4)
	picker.DrawItemHighlight(t, 5)
	picker.DrawItemHighlight(t, 6)
	picker.DrawItemHighlight(t, 7)
	picker.DrawPlayerItems(t)

	const blocksize = float64(0.3)
	const COLSIZE = 12

	diam := blocksize * 2.4

	offset := diam + float64(4)*PIXEL_SCALE

	for i := range self.inventoryRects {
		x := float64(viewport.lplane) + float64(10)*PIXEL_SCALE + float64(i/COLSIZE)*offset
		y := float64(viewport.tplane) - float64(10)*PIXEL_SCALE - float64(i%COLSIZE)*offset
		self.inventoryRects[i] = Rect{x, y - diam, diam, diam}
		self.DrawItemSlot(t, self.inventoryRects[i])
	}

	slot := 0
	for i := 1; i < len(ThePlayer.inventory); i++ {
		if ThePlayer.inventory[i] > 0 {
			self.inventorySlots[slot] = uint16(i)
			self.DrawItem(t, ThePlayer.inventory[i], uint16(i), self.inventoryRects[slot])
			slot++
		}
	}

	for i := range self.componentSlots {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + float64(i)*offset
		y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE)
		self.componentRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.componentRects[i])
	}

	for i, cs := range self.componentSlots {
		if cs != 0 {
			self.DrawItem(t, ThePlayer.inventory[cs], cs, self.componentRects[i])
		}
	}

	for i := range self.productSlots {
		x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + offset*float64(i%len(self.componentRects))
		y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE) - offset*float64(2+float64(i/len(self.componentRects)))
		self.productRects[i] = Rect{x, y - diam, diam, diam}

		self.DrawItemSlot(t, self.productRects[i])
	}

	for i, ps := range self.productSlots {
		if ps != nil {
			self.DrawItem(t, ps.product.quantity, ps.product.item, self.productRects[i])
		}
	}

	if self.currentContainer != nil {

		for i := range self.containerRects {
			x := float64(viewport.lplane) + offset*float64(2+len(self.inventoryRects)/COLSIZE) + float64(i)*offset
			y := float64(viewport.tplane) - (10.0 * PIXEL_SCALE) - offset*float64(2+float64(len(self.productRects)/len(self.componentRects))) - offset*float64(2+float64(i/len(self.componentRects)))
			self.containerRects[i] = Rect{x, y - diam, diam, diam}

			self.DrawItemSlot(t, self.containerRects[i])
		}

		for i := uint16(0); i < self.currentContainer.Slots(); i++ {
			item := self.currentContainer.Item(i)
			if item != nil {
				self.DrawItem(t, item.quantity, item.item, self.containerRects[i])
			}
		}

		gl.PushMatrix()
		gl.LoadIdentity()
		gl.Translated(self.containerRects[0].x, self.containerRects[0].y+diam, 0)
		inventoryItemFont.Print(self.currentContainer.Label())
		gl.PopMatrix()

	}

	var mousex, mousey int
	mousestate := sdl.GetMouseState(&mousex, &mousey)
	self.HandleMouse(mousex, mousey, mousestate)

	gl.PopMatrix()
}
예제 #24
0
func (t *Light) Disable() {
	gl.Disable(getLightName(t.id))
	GFreeIds[t.id] = true
	t.enabled = false
	t.id = -1
}