Example #1
0
// OpenWindow opens a new window with the given size.
func OpenWindow(w, h int) error {
	glfw.OpenWindowHint(glfw.WindowNoResize, 1)

	r, g, b := 0, 0, 0 // defaults
	a := 8             // 8-bit alpha channel
	d, s := 0, 0       // no depth or stencil buffers
	m := glfw.Windowed
	if err := glfw.OpenWindow(w, h, r, g, b, a, d, s, m); err != nil {
		return err
	}

	if gl.Init() != 0 {
		return errors.New("Failed to initialize OpenGL")
	}

	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, 0.0)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(-h), -1, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translated(0, float64(-h), 0)
	return nil
}
Example #2
0
File: main.go Project: sycoso/glfw
func drawScene() {
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.LoadIdentity()
	gl.Translatef(-1.5, 0, -6)
	gl.Rotatef(trisAngle, 0, 1, 0)

	gl.Begin(gl.TRIANGLES)
	gl.Color3f(1, 0, 0)
	gl.Vertex3f(0, 1, 0)
	gl.Color3f(0, 1, 0)
	gl.Vertex3f(-1, -1, 0)
	gl.Color3f(0, 0, 1)
	gl.Vertex3f(1, -1, 0)
	gl.End()

	gl.LoadIdentity()
	gl.Translatef(1.5, 0, -6)
	gl.Rotatef(quadAngle, 1, 0, 0)
	gl.Color3f(0.5, 0.5, 1.0)

	gl.Begin(gl.QUADS)
	gl.Vertex3f(-1, 1, 0)
	gl.Vertex3f(1, 1, 0)
	gl.Vertex3f(1, -1, 0)
	gl.Vertex3f(-1, -1, 0)
	gl.End()

	trisAngle += 0.2
	quadAngle -= 0.15

	glfw.SwapBuffers()
}
Example #3
0
func (self *Picker) DrawPlayerItems(t int64) {

	gl.PushMatrix()
	gl.LoadIdentity()

	for i := 0; i < 5; i++ {

		item := ThePlayer.equippedItems[i]
		if item != ITEM_NONE {
			angle := -(float64(i) + 1.5) * math.Pi / 4
			gl.LoadIdentity()
			x := self.x - self.actionItemRadius*float32(math.Sin(angle))
			y := self.y + self.actionItemRadius*float32(math.Cos(angle))
			gl.Translatef(x, y, 0)

			gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 1.0, 0.0, 0.0)
			gl.Rotatef(360*float32(math.Cos(float64(t)/1e10+float64(i))), 0.0, 1.0, 0.0)
			gl.Rotatef(360*float32(math.Sin(float64(t)/1e10+float64(i))), 0.0, 0.0, 1.0)
			gl.Scalef(blockscale, blockscale, blockscale)
			gVertexBuffer.Reset()
			TerrainCube(gVertexBuffer, 0, 0, 0, [18]uint16{}, item, FACE_NONE)
			gVertexBuffer.RenderDirect(false)

			gl.LoadIdentity()
			gl.Translatef(x-17*PIXEL_SCALE, y-19*PIXEL_SCALE, 20)
			consoleFont.Print(fmt.Sprintf("%d", ThePlayer.inventory[item]))

		}
	}
	gl.PopMatrix()

}
Example #4
0
File: glfps.go Project: shogg/glfps
func drawDigits(x, y int, digits []int8) {

	s := sdl.GetVideoSurface()
	lft, rgt, btm, top := 0.0, float64(s.W), float64(s.H), 0.0

	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()
	gl.Ortho(lft, rgt, btm, top, 0.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()

	w := digitImages[0].Rect.Dx()
	for i := 0; i < len(digits); i++ {
		img := digitImages[digits[i]]
		drawImage(x-w*i-i, y, img)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.PopMatrix()

	gl.MatrixMode(gl.PROJECTION)
	gl.PopMatrix()
}
Example #5
0
// Handle the window being resized.
func reshape(width int, height int) {
	// Render into the entire window.
	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	// Configure the Frustrum so the front face of the rendering
	// volume fills the screen.

	w := float64(width)
	h := float64(height)
	depth := (w + h) / 2
	near := depth / 2.0
	right := w / 4.0
	top := h / 4.0
	far := 4 * depth
	gl.Frustum(-right, right, -top, top, near, far)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	// Center the rendering volume in the viewport.  Its origin
	// is at the far lower left corner.

	gl.Translated(-w/2, -h/2, -2*depth)
}
Example #6
0
/* new window size or exposure */
func (self *Viewport) Reshape(width int, height int) {
	self.selectionDirty = false
	self.screenWidth = width
	self.screenHeight = height

	gl.Viewport(0, 0, width, height)

	viewWidth := float64(self.screenWidth) / float64(SCREEN_SCALE)
	viewHeight := float64(self.screenHeight) / float64(SCREEN_SCALE)

	self.lplane = -viewWidth / 2
	self.rplane = viewWidth / 2
	self.bplane = -viewHeight / 4
	self.tplane = 3 * viewHeight / 4

	println("self.lplane:", self.lplane, "self.rplane", self.rplane)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(self.lplane, self.rplane, self.bplane, self.tplane, -60, 60)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	picker.x = float32(viewport.rplane) - picker.radius + blockscale*0.5
	picker.y = float32(viewport.bplane) + picker.radius - blockscale*0.5

}
Example #7
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)
}
// reset our viewport after a window resize
func resizeWindow(width, height int) {
	// protect against a divide by zero
	if height == 0 {
		height = 1
	}

	// Setup our viewport
	gl.Viewport(0, 0, int(width), int(height))

	// change to the projection matrix and set our viewing volume.
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	// aspect ratio
	aspect := gl.GLdouble(gl.GLfloat(width) / gl.GLfloat(height))

	// Set our perspective.
	// This code is equivalent to using gluPerspective as in the original tutorial.
	var fov, near, far gl.GLdouble
	fov = 45.0
	near = 0.1
	far = 100.0
	top := gl.GLdouble(math.Tan(float64(fov*math.Pi/360.0))) * near
	bottom := -top
	left := aspect * bottom
	right := aspect * top
	gl.Frustum(float64(left), float64(right), float64(bottom), float64(top), float64(near), float64(far))

	// Make sure we're changing the model view and not the projection
	gl.MatrixMode(gl.MODELVIEW)

	// Reset the view
	gl.LoadIdentity()
}
Example #9
0
func (self *Inventory) DrawItem(t int64, quantity uint16, itemid ItemId, x float64, y float64) {
	gl.PushMatrix()
	gl.LoadIdentity()

	// angle := -90.0
	const blocksize = float32(0.3)

	gl.Translated(x, y, 0)

	//gl.Rotated(angle, 1.0, 0.0, 0.0)
	gl.Rotated(90, 1.0, 0.0, 0.0)
	gl.Rotated(30*math.Sin(float64(t)/1e9+float64(itemid)/2), 0.0, 1.0, 0.0)
	gl.Scalef(blocksize, blocksize, blocksize)
	self.drawBuffer.Reset()

	if itemid < 256 {
		TerrainCube(self.drawBuffer, Vectori{}, [18]BlockId{BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_DIRT, BLOCK_AIR, BLOCK_DIRT, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR, BLOCK_AIR}, NewBlockDefault(BlockId(itemid)), FACE_NONE)
	} else {
		RenderItemFlat(self.drawBuffer, Vectori{}, BlockId(itemid))
	}
	self.drawBuffer.RenderDirect(false)

	gl.LoadIdentity()
	gl.Translated(x+2*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), y-7*PIXEL_SCALE-48*PIXEL_SCALE*float64(blocksize), 0)
	inventoryItemFont.Print(fmt.Sprintf("%d", quantity))

	gl.PopMatrix()

}
Example #10
0
/* new window size or exposure */
func (self *Viewport) Reshape(width int, height int) {
	self.selectionDirty = false
	self.screenWidth = width
	self.screenHeight = height

	gl.Viewport(0, 0, width, height)

	viewWidth := float64(self.screenWidth) / float64(SCREEN_SCALE)
	viewHeight := float64(self.screenHeight) / float64(SCREEN_SCALE)

	self.lplane = -viewWidth / 2
	self.rplane = viewWidth / 2
	self.bplane = -viewHeight / 4
	self.tplane = 3 * viewHeight / 4

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(self.lplane, self.rplane, self.bplane, self.tplane, -60, 60)

	// self.Perspective(90, 1, 0.01,1000);

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	picker.x = float32(viewport.rplane) - picker.radius + BLOCK_SCALE*0.5
	picker.y = float32(viewport.bplane) + picker.radius - BLOCK_SCALE*0.5

}
Example #11
0
// Initialize the OpenGL configuration with the information from the current window.
func InitGLWindow(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Example #12
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()
}
Example #13
0
File: main.go Project: sycoso/glfw
func onResize(w, h int) {
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Viewport(0, 0, w, h)
	gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0)
	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Example #14
0
File: main.go Project: 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()
	}
}
Example #15
0
File: main.go Project: sycoso/glfw
func onResize(w, h int) {
	if h == 0 {
		h = 1
	}

	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Example #16
0
/* new window size or exposure */
func reshape(width int, height int) {

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

	gl.Viewport(0, 0, width, height)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(0.0, 0.0, -40.0)
}
Example #17
0
File: ca.go Project: 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)
}
Example #18
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(-1.5, 0.0, -6.0)
	gl.Rotatef(float32(rtri), 0.0, 1.0, 0.0) // Rotate the triangle on the Y axis

	gl.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Color3f(1.0, 0.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Color3f(0.0, 1.0, 0.0)    // Set The Color To Red
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Color3f(0.0, 0.0, 1.0)    // Set The Color To Red
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -6.0)
	gl.Color3f(0.5, 0.5, 1.0)                 // Set The Color To Blue One Time Only
	gl.Rotatef(float32(rquad), 1.0, 0.0, 0.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)           // draw quads
	gl.Vertex3f(-1.0, 1.0, 0.0)  // top left
	gl.Vertex3f(1.0, 1.0, 0.0)   // top right
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.End()                     // done drawing the quad

	// Draw to the screen
	sdl.GL_SwapBuffers()

	rtri += 0.2   // Increase The Rotation Variable For The Triangle
	rquad -= 0.15 // Decrease The Rotation Variable For The Quad

	// 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 #19
0
func initScreen() {
	sdl.Init(sdl.INIT_VIDEO)
	const (
		resx int = 640
		resy int = 480
	)
	var (
		screen = sdl.SetVideoMode(resx, resy, 16, sdl.OPENGL)
	)

	if screen == nil {
		sdl.Quit()
		panic("Couldn't set GL video mode: " + sdl.GetError() + "\n")
	}

	if gl.Init() != 0 {
		panic("gl error")
	}

	gl.MatrixMode(gl.PROJECTION)
	//gl.MatrixMode(gl.MODELVIEW)

	gl.Viewport(0, 0, int(screen.W), int(screen.H))
	gl.LoadIdentity()
	gl.Ortho(0, float64(screen.W), float64(screen.H), 0, -1.0, 1.0)
	//gl.DepthRange(-1, 1)

	gl.ClearColor(0, 0, 0, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)
}
Example #20
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)
}
Example #21
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()
		}
	}
}
Example #22
0
func positionCamera() {
	gl.LoadIdentity()
	x, y, z := player.Position()
	gl.Translated(-x, -y+4, -z)

	gl.Lightfv(gl.LIGHT1, gl.POSITION, []float32{float32(x), float32(y), float32(z) + 0.5, 1})
}
Example #23
0
func (this *Window) SetProjection2D() {
	gl.MatrixMode(gl.PROJECTION)
	gl.Viewport(0, 0, int(this.Width()), int(this.Height()))
	gl.LoadIdentity()
	gl.Ortho(0, float64(this.Width()), 0, float64(this.Height()), -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
}
Example #24
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()

}
Example #25
0
func (this *Window) resetModelViewMatrix() {
	if globals.UseShader {
		program.SetModelMatrix(mat4.Identity())
	}
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
}
Example #26
0
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()

}
Example #27
0
func (self *Inventory) DrawItemSlot(t int64, r Rect) {
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Color4ub(16, 16, 16, 255)
	gl.Begin(gl.QUADS)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.End()

	gl.Color4ub(6, 6, 6, 255)
	gl.Begin(gl.LINES)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x, r.y)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.End()

	gl.Color4ub(64, 64, 64, 255)
	gl.Begin(gl.LINES)
	gl.Vertex2d(r.x+r.sizex, r.y)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.Vertex2d(r.x, r.y+r.sizey)
	gl.Vertex2d(r.x+r.sizex, r.y+r.sizey)
	gl.End()

	gl.PopMatrix()
}
Example #28
0
File: fontdemo.go Project: tmc/glut
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()
}
Example #29
0
func size_window(x, y int, fov, aspect, min_cull, max_cull float64) {
	gl.Viewport(0, 0, x, y)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	glu.Perspective(fov, aspect, min_cull, max_cull)
	gl.Enable(gl.DEPTH_TEST)
}
Example #30
0
File: fontdemo.go Project: tmc/glut
func reshape(w, h int) {
	gl.Viewport(0, 0, w, h)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, float64(w), 0, float64(h), -1, 1)
	gl.Scalef(1, -1, 1)
	gl.Translatef(0, float32(-h), 0)
	gl.MatrixMode(gl.MODELVIEW)
}