Beispiel #1
0
func (c *PU_Chat) DrawChatList() {
	if sdl.GetTicks()-c.listBlinkLast >= 500 {
		c.listBlink = !c.listBlink
		c.listBlinkLast = sdl.GetTicks()
	}

	hasUpdate := false
	if c.listVisible {
		//top of the list
		y := 688 - ((len(c.channels) * 20) + 29)
		g_game.GetGuiImage(IMG_GUI_CHATLISTTOP).Draw(0, y)

		//channels
		y = 688 - (len(c.channels) * 20)
		i := 0
		for _, channel := range c.channels {
			if channel.closable {
				g_game.GetGuiImage(IMG_GUI_CHATLISTMIDX).Draw(0, y+(i*20))
			} else if channel.gamechannel {
				if channel.notifications {
					g_game.GetGuiImage(IMG_GUI_CHATLISTMIDLISTEN).Draw(0, y+(i*20))
				} else {
					g_game.GetGuiImage(IMG_GUI_CHATLISTMIDIGNORE).Draw(0, y+(i*20))
				}
			} else {
				g_game.GetGuiImage(IMG_GUI_CHATLISTMID).Draw(0, y+(i*20))
			}

			font := g_engine.GetFont(FONT_PURITANBOLD_14)
			if channel.updated && c.listBlink {
				hasUpdate = true
				font.SetColor(255, 0, 0)
			} else {
				font.SetColor(255, 255, 255)
			}

			font.DrawTextInRect(channel.name, 3, 3+y+(i*20), NewRect(3, y+(i*20), 80, 19))
			i++
		}
	}

	if c.listBlink && !hasUpdate {
		for _, channel := range c.channels {
			if channel.updated {
				hasUpdate = true
			}
		}
	}

	font := g_engine.GetFont(FONT_ARIALBLACK_10)
	if c.listBlink && hasUpdate {
		font.SetColor(255, 0, 0)
	} else {
		font.SetColor(0, 0, 0)
	}
	font.DrawText(c.channels[c.activeChannel].name, 28, 704)
}
Beispiel #2
0
func (t *PU_Textfield) Draw() {
	if !t.visible {
		return
	}

	if !t.transparent {
		g_engine.DrawFillRect(t.rect, &t.bgcolor, 200)
	}

	var caretX int

	//find the correct coordinates to draw at (when the element is embedded in another)
	top := NewRectFrom(t.rect)
	g_gui.GetTopRect(t, top)

	//draw text
	if len(t.text) > 0 {
		var drawText string
		if t.password {
			for i := 0; i < len(t.text); i++ {
				drawText += "*"
			}
		} else {
			drawText = t.text
		}

		//find out within what frame the text should be drawn
		clip := NewRectFrom(t.rect)
		g_gui.GetClipRect(t, clip)

		t.font.SetStyle(t.bold, t.italic, t.underlined)
		t.font.SetColor(t.color.R, t.color.G, t.color.B)
		t.font.DrawTextInRect(drawText, top.x, top.y, clip)

		caretX = top.x + t.font.GetStringWidth(drawText)
	}

	//draw caret
	if t.focus && t.caret && !t.readonly {
		image := g_game.GetGuiImage(IMG_GUI_CARET)
		if image != nil {
			if caretX == 0 {
				caretX = top.x
			}

			lineheight := t.font.GetStringHeight()
			drawRect := NewRect(caretX, top.y+1, int(image.w), lineheight)
			g_gui.DrawImage(t, image, drawRect, t.rect)
		}
	}
	if sdl.GetTicks()-t.caretLast >= 500 {
		t.caret = !t.caret
		t.caretLast = sdl.GetTicks()
	}
}
Beispiel #3
0
func (c *PU_Creature) UpdateAnimation() {
	if c.animationRunning {
		passedTicks := sdl.GetTicks() - c.animationLastTicks
		if passedTicks >= uint32(c.animationInterval) {
			c.frame++
			if c.frame > c.frames {
				c.frame = 0
			}

			c.animationLastTicks = sdl.GetTicks()
		}
	}
}
Beispiel #4
0
func (t *TextField) Draw(drawArea *Rect) {
	realRect := NewRect(t.Rect().X+drawArea.X, t.Rect().Y+drawArea.Y, t.Rect().Width, t.Rect().Height)
	inRect := drawArea.Intersection(realRect)

	if t.backgroundColor != nil {
		DrawFillRect(inRect, t.backgroundColor.R, t.backgroundColor.G, t.backgroundColor.B, 255)
	}

	if t.borderColor != nil {
		DrawRect(inRect, t.borderColor.R, t.borderColor.G, t.borderColor.B, 255)
	}

	if t.image != nil {
		t.image.DrawRectInRect(t.Rect(), drawArea)
	}

	caretX := 0
	textX := t.Rect().X + (t.font.GetStringWidth(" "))
	textY := t.Rect().Y + ((t.Rect().Height / 2) - (t.font.GetStringHeight() / 2))

	if t.text != "" && t.font != nil {
		var drawText string
		if t.password {
			for i := 0; i < len(t.text); i++ {
				drawText += "*"
			}
		} else {
			drawText = t.text
		}

		t.font.SetStyle(t.bold, t.italic, t.underlined)
		t.font.SetColor(t.fontColor.R, t.fontColor.G, t.fontColor.B)
		t.font.DrawTextInRect(drawText, drawArea.X+textX, drawArea.Y+textY, inRect)

		caretX = t.font.GetStringWidth(drawText)
	}

	//draw caret
	if t.caret && !t.readonly && t.focus {
		caretX += textX
		if inRect.Contains(drawArea.X+caretX, drawArea.Y+textY) {
			DrawLine(t.fontColor.R, t.fontColor.G, t.fontColor.B, 255, drawArea.X+caretX, drawArea.Y+textY, drawArea.X+caretX, drawArea.Y+textY+t.font.GetStringHeight())
		}
	}
	if sdl.GetTicks()-t.caretLast >= CARET_TIME {
		t.caret = !t.caret
		t.caretLast = sdl.GetTicks()
	}
}
Beispiel #5
0
func NewFramerate() *FPSmanager {
	return &FPSmanager{
		framecount: 0,
		rate:       FPS_DEFAULT,
		rateticks:  (1000.0 / float(FPS_DEFAULT)),
		lastticks:  sdl.GetTicks(),
	}
}
Beispiel #6
0
func (c *PU_Creature) SetDefault(_id uint64) {
	c.id = _id
	c.speed = 300
	c.direction = DIR_SOUTH
	c.frames = 3
	c.animationInterval = 150
	c.animationLastTicks = sdl.GetTicks()
}
Beispiel #7
0
func (manager *FPSmanager) FramerateDelay() {
	var current_ticks, target_ticks, the_delay uint32

	// next frame
	manager.framecount++

	// get/calc ticks
	current_ticks = sdl.GetTicks()
	target_ticks = manager.lastticks + uint32(float(manager.framecount)*manager.rateticks)

	if current_ticks <= target_ticks {
		the_delay = target_ticks - current_ticks
		sdl.Delay(the_delay)
	} else {
		manager.framecount = 0
		manager.lastticks = sdl.GetTicks()
	}
}
Beispiel #8
0
func NewTextField(x, y, width, height int) *TextField {
	textfield := &TextField{}
	textfield.Init(x, y, width, height)
	textfield.focusable = true
	textfield.SetFont(g_game.guiManager.defaultFont)
	textfield.fontColor = &sdl.Color{uint8(255), uint8(255), uint8(255), uint8(255)}
	textfield.caretLast = sdl.GetTicks()
	return textfield
}
Beispiel #9
0
func NewTextfield(_rect *PU_Rect, _font int) *PU_Textfield {
	textfield := &PU_Textfield{transparent: true,
		font:      g_engine.GetFont(_font),
		caretLast: sdl.GetTicks()}
	textfield.rect = _rect
	textfield.visible = true
	textfield.SetColor(0, 0, 0)
	g_gui.AddElement(textfield)
	return textfield
}
func NewOnscreenChat() *PU_OnscreenChat {
	chat := &PU_OnscreenChat{}
	chat.visible = true
	chat.messages = make([]*PU_OnscreenChatMessage, 0)
	g_gui.AddElement(chat)

	chat.lastTicks = sdl.GetTicks()

	return chat
}
Beispiel #11
0
func draw() {
	xtrans := -xpos
	ztrans := -zpos
	ytrans := -walkbias - 0.25
	scenroty := 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(lookupdown, 1.0, 0.0, 0.0)
	// Rotate depending on direction player is facing
	gl.Rotatef(scenroty, 0.0, 1.0, 0.0)
	// translate the scene based on player position
	gl.Translatef(xtrans, ytrans-1.75, ztrans)

	for _, chunk := range chunks {
		for y := 0; y < 16; y++ {
			for x := 0; x < 16; x++ {
				for z := 0; z <= 16; z++ {
					if len(chunk.Data[y][x]) > z && chunk.Data[y][x][z] != "" {
						gl.PushMatrix()
						gl.Translated(
							float64(16*chunk.X+x),
							float64(z),
							float64(16*chunk.Y+y))
						gl.CallList(cubes[chunk.Data[y][x][z]])
						gl.PopMatrix()
					}
				}
			}
		}
	}

	gl.PopMatrix()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
func (g *PU_OnscreenChat) Draw() {
	if !g.visible {
		return
	}

	if g_game.self == nil {
		return
	}

	ticks := int(sdl.GetTicks() - g.lastTicks)
	g.lastTicks = sdl.GetTicks()

	for i := 0; i < len(g.messages); {
		msg := g.messages[i]
		if msg != nil {
			if !msg.Draw(ticks) {
				g.messages = append(g.messages[:i], g.messages[i+1:]...)
			} else {
				i++
			}
		}
	}
}
// 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
	}
}
Beispiel #14
0
//Game loop
func (game *Game) Run() {
	defer game.Exit()

	if game.initFun == nil {
		fmt.Println("Go2D Warning: No init function set!")
	}

	if game.updateFun == nil {
		fmt.Println("Go2D Warning: No update function set!")
	}

	if game.drawFun == nil {
		fmt.Println("Go2D Warning: No draw function set!")
	}

	//Initialize the game
	game.initialize()

	var dt, old_t, now_t uint32 = 0, 0, 0

	for g_running {
		//Check for events and handle them
		for {
			event, present := sdl.PollEvent()
			if present {
				EventHandler(event)
			} else {
				break
			}
		}

		//Calculate time delta
		now_t = sdl.GetTicks()
		dt = now_t - old_t
		old_t = now_t

		//Update
		game.update(dt)

		//Draw
		game.draw()

		//Give the CPU some time to do other stuff
		sdl.Delay(1)
	}
}
// 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
	}
}
Beispiel #16
0
func draw() {

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

	gl.PushMatrix()
	gl.Rotated(view_rotx, 1.0, 0.0, 0.0)
	gl.Rotated(view_roty, 0.0, 1.0, 0.0)
	gl.Rotated(view_rotz, 0.0, 0.0, 1.0)

	gl.PushMatrix()
	gl.Translated(-3.0, -2.0, 0.0)
	gl.Rotated(angle, 0.0, 0.0, 1.0)
	gl.CallList(gear1)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(3.1, -2.0, 0.0)
	gl.Rotated(-2.0*angle-9.0, 0.0, 0.0, 1.0)
	gl.CallList(gear2)
	gl.PopMatrix()

	gl.PushMatrix()
	gl.Translated(-3.1, 4.2, 0.0)
	gl.Rotated(-2.0*angle-25.0, 0.0, 0.0, 1.0)
	gl.CallList(gear3)
	gl.PopMatrix()

	gl.PopMatrix()

	sdl.GL_SwapBuffers()

	Frames++
	{
		t := sdl.GetTicks()
		if t-T0 >= 5000 {
			seconds := (t - T0) / 1000.0
			fps := Frames / seconds
			print(Frames, " frames in ", seconds, " seconds = ", fps, " FPS\n")
			T0 = t
			Frames = 0
		}
	}
}
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	// reset the view
	gl.LoadIdentity()

	// 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
	}
}
// 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.Begin(gl.TRIANGLES)       // Draw triangles
	gl.Vertex3f(0.0, 1.0, 0.0)   // top
	gl.Vertex3f(-1.0, -1.0, 0.0) // bottom left
	gl.Vertex3f(1.0, -1.0, 0.0)  // bottom right
	gl.End()                     // finish drawing the triangle

	// Move right 3 units
	gl.Translatef(3.0, 0.0, 0.0)

	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()

	// 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
	}
}
Beispiel #19
0
func main() {
	sdl.Init(sdl.INIT_VIDEO)

	screen := sdl.SetVideoMode(640, 480, 32, 0)
	image := sdl.Load("../icon.bmp")
	image.SetColorKey(sdl.RLEACCEL|sdl.SRCCOLORKEY, image.MapRGB(255, 255, 255))

	x := make([]int16, NUM_SPRITES)
	y := make([]int16, NUM_SPRITES)
	vx := make([]int16, NUM_SPRITES)
	vy := make([]int16, NUM_SPRITES)

	rg := rand.New(rand.NewSource(0))

	for i := 0; i < NUM_SPRITES; i++ {
		//x[i] = rg.Intn(screen.w - image.w);
		//y[i] = rg.Intn(screen.h - image.h);
		x[i] = int16(rg.Intn(W))
		y[i] = int16(rg.Intn(H))
		vx[i] = 0
		vy[i] = 0
		for vx[i] == 0 && vy[i] == 0 {
			vx[i] = int16(rg.Intn(3) - 1)
			vy[i] = int16(rg.Intn(3) - 1)
		}
	}

	t := 0
	running := true
	start := sdl.GetTicks()
	//rect := sdl.Rect{ 0, 0, 0, 0 };
	//rectp := &rect;

	for running {
		t++

		e := &sdl.Event{}

		for e.Poll() {
			switch e.Type {
			case sdl.QUIT:
				running = false
			case sdl.KEYDOWN:
				if e.Keyboard().Keysym.Sym == sdl.K_ESCAPE {
					running = false
				}
			}
		}

		screen.FillRect(nil, 0)

		for i := 0; i < NUM_SPRITES; i++ {
			x[i] += vx[i]
			y[i] += vy[i]
			if x[i] < 0 || x[i] >= W {
				vx[i] = -vx[i]
				x[i] += vx[i]
			}
			if y[i] < 0 || y[i] >= H {
				vy[i] = -vy[i]
				y[i] += vy[i]
			}

			//rect.X = x[i];
			//rect.Y = y[i];
			//screen.Blit(rectp, image, nil);
			screen.Blit(&sdl.Rect{x[i], y[i], 0, 0}, image, nil)
		}

		screen.Flip()
	}

	elapsed := sdl.GetTicks() - start
	fmt.Printf("%f\n", float(t)/float(elapsed)*1000.0)

	image.Free()
	screen.Free()

	sdl.Quit()
}
// 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, -7.0)

  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 */
  gl.Rotatef(float32(zrot), 0.0, 0.0, 1.0) /* Rotate On The Z Axis */

  /* Select Our Texture */
  gl.BindTexture(gl.TEXTURE_2D, uint(texture))

  gl.Begin(gl.QUADS) // Draw a quad
  /* Front Face */
  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.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.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.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.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.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() // done drawing the quad

  // Draw to the screen
  sdl.GL_SwapBuffers()

  xrot += 0.3 /* X Axis Rotation */
  yrot += 0.2 /* Y Axis Rotation */
  zrot += 0.4 /* Z Axis Rotation */

  // 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
  }
}
// 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
	}
}
Beispiel #22
0
func GetTicks() uint32 {
	return sdl.GetTicks()
}
Beispiel #23
0
func main() {
	runtime.LockOSThread()
	flag.Parse()
	sdl.Init(sdl.INIT_VIDEO)
	defer sdl.Quit()

	sdl.GL_SetAttribute(sdl.GL_SWAP_CONTROL, 1)

	if sdl.SetVideoMode(640, 480, 32, sdl.OPENGL) == nil {
		panic("sdl error")
	}

	sdl.WM_SetCaption("Gotris", "Gotris")
	sdl.EnableKeyRepeat(250, 45)

	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Viewport(0, 0, 640, 480)
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 640, 480, 0, -1, 1)

	gl.ClearColor(0, 0, 0, 0)

	//-----------------------------------------------------------------------------

	font, err := LoadFontFromFile("dejavu.font")
	if err != nil {
		panic(err)
	}

	rand.Seed(int64(sdl.GetTicks()))

	gs := NewGameSession(*initLevel, font)
	lastTime := sdl.GetTicks()

	running := true
	for running {
		for ev := sdl.PollEvent(); ev != nil; ev = sdl.PollEvent() {
			switch e := ev.(type) {
			case *sdl.QuitEvent:
				running = false
			case *sdl.KeyboardEvent:
				if e.Type == sdl.KEYDOWN {
					running = gs.HandleKey(e.Keysym.Sym)
				}
			}
		}

		now := sdl.GetTicks()
		delta := now - lastTime
		lastTime = now

		gs.Update(delta)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		font.Draw(5, 5, fmt.Sprintf("Level: %d | Score: %d", gs.Level, gs.Score))
		gs.Draw()
		gl.Color3ub(255, 255, 255)
		sdl.GL_SwapBuffers()
	}
}
Beispiel #24
0
func main() {
	//Make sure that resources get released
	defer g_engine.Exit()

	//Permission to run on 2 CPU cores
	runtime.GOMAXPROCS(2)

	//Initialize SDL
	err := sdl.Init()
	if err != "" {
		fmt.Printf("Error in Init: %v", err)
		return
	}

	//Initialize the engine
	g_engine.Init()

	//Load data
	g_game.LoadFonts()
	Draw() //Draw the "please wait" text after loading the fonts
	g_game.LoadGuiImages()
	g_game.LoadTileImages()
	g_game.LoadCreatureImages()
	g_game.SetState(GAMESTATE_LOGIN)

	g_loginControls.Show()

	lastTime := sdl.GetTicks()

	frameTime := sdl.GetTicks()
	frameCount := 0

	//Handle events 
	for g_running {
		for {
			event, present := sdl.PollEvent()
			if present {
				EventHandler(event)
			} else {
				break
			}
		}

		//Render everything on screen
		Draw()

		//Give the CPU some time to do other stuff
		sdl.Delay(1)

		//Handle a network message
		g_conn.HandleMessage()

		//Handle a battle event
		if g_game.state == GAMESTATE_BATTLE {
			g_game.battle.ProcessEvents()
		}

		//Update frame time 
		g_frameTime = sdl.GetTicks() - lastTime
		lastTime = sdl.GetTicks()

		//Update FPS
		frameCount++
		if sdl.GetTicks()-frameTime >= 1000 {
			g_FPS = frameCount
			frameCount = 0
			frameTime = sdl.GetTicks()
		}
	}
	sdl.Quit()
}
// Here goes our drawing code
func drawGLScene() {
	// Clear the screen and depth buffer
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.BindTexture(gl.TEXTURE_2D, uint(texture))

	for loop, star := range stars {
		gl.LoadIdentity()
		gl.Translatef(0.0, 0.0, float32(zoom))
		gl.Rotatef(float32(tilt), 1.0, 0.0, 0.0)
		gl.Rotatef(float32(star.angle), 0.0, 1.0, 0.0)
		gl.Translatef(float32(star.dist), 0.0, 0.0)
		gl.Rotatef(float32(-star.angle), 0.0, 1.0, 0.0)
		gl.Rotatef(float32(-tilt), 1.0, 0.0, 0.0)

		if twinkle {
			other := stars[(num-loop)-1]
			gl.Color4ub(uint8(other.r), uint8(other.g), uint8(other.b), 255)
			gl.Begin(gl.QUADS)
			gl.TexCoord2f(0.0, 0.0)
			gl.Vertex3f(-1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 0.0)
			gl.Vertex3f(1.0, -1.0, 0.0)
			gl.TexCoord2f(1.0, 1.0)
			gl.Vertex3f(1.0, 1.0, 0.0)
			gl.TexCoord2f(0.0, 1.0)
			gl.Vertex3f(-1.0, 1.0, 0.0)
			gl.End()
		}

		gl.Rotatef(float32(spin), 0.0, 0.0, 1.0)
		gl.Color4ub(uint8(star.r), uint8(star.g), uint8(star.b), 255)
		gl.Begin(gl.QUADS)
		gl.TexCoord2f(0.0, 0.0)
		gl.Vertex3f(-1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 0.0)
		gl.Vertex3f(1.0, -1.0, 0.0)
		gl.TexCoord2f(1.0, 1.0)
		gl.Vertex3f(1.0, 1.0, 0.0)
		gl.TexCoord2f(0.0, 1.0)
		gl.Vertex3f(-1.0, 1.0, 0.0)
		gl.End()

		spin += 0.01
		star.angle += gl.GLfloat(loop) / gl.GLfloat(num)
		star.dist -= 0.01

		if star.dist < 0.0 {
			star.dist += 5.0
			star.r = gl.GLubyte(rand.Float32() * 255)
			star.g = gl.GLubyte(rand.Float32() * 255)
			star.b = gl.GLubyte(rand.Float32() * 255)
		}
	}

	// 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
	}
}
// 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)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Front)       */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0) /* Left Of Triangle (Front)      */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Right Of Triangle (Front)     */

	gl.Color3f(1.0, 0.0, 0.0)    /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)   /* Top Of Triangle (Right)       */
	gl.Color3f(0.0, 0.0, 1.0)    /* Blue                          */
	gl.Vertex3f(1.0, -1.0, 1.0)  /* Left Of Triangle (Right)      */
	gl.Color3f(0.0, 1.0, 0.0)    /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0) /* Right Of Triangle (Right)     */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Back)        */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(1.0, -1.0, -1.0)  /* Left Of Triangle (Back)       */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Right Of Triangle (Back)      */

	gl.Color3f(1.0, 0.0, 0.0)     /* Red                           */
	gl.Vertex3f(0.0, 1.0, 0.0)    /* Top Of Triangle (Left)        */
	gl.Color3f(0.0, 0.0, 1.0)     /* Blue                          */
	gl.Vertex3f(-1.0, -1.0, -1.0) /* Left Of Triangle (Left)       */
	gl.Color3f(0.0, 1.0, 0.0)     /* Green                         */
	gl.Vertex3f(-1.0, -1.0, 1.0)  /* Right Of Triangle (Left)      */

	gl.End() // finish drawing the triangle

	// Move right 3 units
	gl.LoadIdentity()
	gl.Translatef(1.5, 0.0, -7.0)
	gl.Rotatef(float32(rquad), 1.0, 1.0, 1.0) // rotate the quad on the X axis

	gl.Begin(gl.QUADS)            // draw quads
	gl.Color3f(0.0, 1.0, 0.0)     // Set The Color To Green
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Right Of The Quad (Top)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Left Of The Quad (Top)
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Bottom Left Of The Quad (Top)
	gl.Vertex3f(1.0, 1.0, 1.0)    // Bottom Right Of The Quad (Top)
	gl.Color3f(1.0, 0.5, 0.0)     // Set The Color To Orange
	gl.Vertex3f(1.0, -1.0, 1.0)   // Top Right Of The Quad (Bottom)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Top Left Of The Quad (Bottom)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Bottom)
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Right Of The Quad (Bottom)
	gl.Color3f(1.0, 0.0, 0.0)     // Set The Color To Red
	gl.Vertex3f(1.0, 1.0, 1.0)    // Top Right Of The Quad (Front)
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Top Left Of The Quad (Front)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Bottom Left Of The Quad (Front)
	gl.Vertex3f(1.0, -1.0, 1.0)   // Bottom Right Of The Quad (Front)
	gl.Color3f(1.0, 1.0, 0.0)     // Set The Color To Yellow
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Left Of The Quad (Back)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Right Of The Quad (Back)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Right Of The Quad (Back)
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Left Of The Quad (Back)
	gl.Color3f(0.0, 0.0, 1.0)     // Set The Color To Blue
	gl.Vertex3f(-1.0, 1.0, 1.0)   // Top Right Of The Quad (Left)
	gl.Vertex3f(-1.0, 1.0, -1.0)  // Top Left Of The Quad (Left)
	gl.Vertex3f(-1.0, -1.0, -1.0) // Bottom Left Of The Quad (Left)
	gl.Vertex3f(-1.0, -1.0, 1.0)  // Bottom Right Of The Quad (Left)
	gl.Color3f(1.0, 0.0, 1.0)     // Set The Color To Violet
	gl.Vertex3f(1.0, 1.0, -1.0)   // Top Right Of The Quad (Right)
	gl.Vertex3f(1.0, 1.0, 1.0)    // Top Left Of The Quad (Right)
	gl.Vertex3f(1.0, -1.0, 1.0)   // Bottom Left Of The Quad (Right)
	gl.Vertex3f(1.0, -1.0, -1.0)  // Bottom Right Of The Quad (Right)
	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
	}
}
Beispiel #27
0
func NewChat() *PU_Chat {
	chat := &PU_Chat{channels: make(map[int]*PU_ChatChannel),
		listBlinkLast: sdl.GetTicks()}
	chat.visible = true
	return chat
}