本文整理汇总了Golang中github.com/banthar/gl.Color4ub函数的典型用法代码示例。如果您正苦于以下问题:Golang Color4ub函数的具体用法?Golang Color4ub怎么用?Golang Color4ub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Color4ub函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: DrawItemSlot
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()
}
示例2: Draw
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: Draw
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: Render
func (f frame) Render(w, h, d float64) {
// Draw a wireframe around the arena
gl.Color4ub(255, 255, 255, 31)
gl.LineWidth(2.0)
gl.Begin(gl.LINE_STRIP)
gl.Vertex3d(0, 0, 0)
gl.Vertex3d(w, 0, 0)
gl.Vertex3d(w, h, 0)
gl.Vertex3d(0, h, 0)
gl.Vertex3d(0, 0, 0)
gl.Vertex3d(0, 0, d)
gl.Vertex3d(0, h, d)
gl.Vertex3d(w, h, d)
gl.Vertex3d(w, 0, d)
gl.Vertex3d(0, 0, d)
gl.End()
gl.Begin(gl.LINES)
gl.Vertex3d(0, h, 0)
gl.Vertex3d(0, h, d)
gl.Vertex3d(w, 0, 0)
gl.Vertex3d(w, 0, d)
gl.Vertex3d(w, h, 0)
gl.Vertex3d(w, h, d)
gl.End()
// Render the page.
if f.renderer != nil {
f.renderer.Render(w, h, d)
}
}
示例5: Draw
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()
}
示例6: Render
func (world *World) Render(w, h, d float64) {
gl.PushMatrix()
gl.Scaled(w, h, d)
// Draw the goal
gl.Begin(gl.POINTS)
gl.Color3ub(255, 0, 0)
gl.PointSize(6)
gl.Vertex2d(world.goal.X, world.goal.Y)
gl.End()
// Draw the obstacles
gl.Color4ub(0, 0, 255, 63)
world.obstacles.Render()
// Draw the percept
gl.Color4ub(0, 255, 0, 127)
gl.LineWidth(1.5)
gl.Begin(gl.LINES)
for _, pt := range world.percept {
gl.Vertex2d(world.robot.X, world.robot.Y)
gl.Vertex2d(world.robot.X+pt.X, world.robot.Y+pt.Y)
}
gl.End()
// Draw the map
gl.Color3ub(0, 0, 255)
gl.LineWidth(2)
// FIXME
// Draw the robot
gl.Color3ub(0, 255, 0)
gl.PointSize(4)
gl.Begin(gl.POINTS)
gl.Vertex2d(world.robot.X, world.robot.Y)
gl.End()
gl.PopMatrix()
}
示例7: DrawItemHighlight
func (self *Picker) DrawItemHighlight(t int64, position Action) {
gl.PushMatrix()
gl.LoadIdentity()
actionItemAngle := -(float64(position) - 1.5) * math.Pi / 4
gl.Begin(gl.TRIANGLE_FAN)
gl.Color4ub(64, 64, 64, 228)
gl.Vertex2f(self.x-self.actionItemRadius*float32(math.Sin(actionItemAngle)), self.y+self.actionItemRadius*float32(math.Cos(actionItemAngle)))
for angle := float64(0); angle <= 2*math.Pi; angle += math.Pi / 2 / 10 {
gl.Vertex2f(self.x-self.actionItemRadius*float32(math.Sin(actionItemAngle))-float32(math.Sin(angle))*self.selectionRadius, self.y+self.actionItemRadius*float32(math.Cos(actionItemAngle))+float32(math.Cos(angle))*self.selectionRadius)
}
gl.End()
gl.PopMatrix()
}
示例8: ShowTooltip
func (self *Inventory) ShowTooltip(x, y float64, str string) {
h, w := inventoryItemFont.Measure(str)
pad := 4 * PIXEL_SCALE
gl.PushMatrix()
gl.LoadIdentity()
gl.Color4ub(0, 0, 0, 255)
gl.Begin(gl.QUADS)
gl.Vertex2d(x, y)
gl.Vertex2d(x+w+pad, y)
gl.Vertex2d(x+w+pad, y+h)
gl.Vertex2d(x, y+h)
gl.End()
gl.Translated(x+pad/2, y+pad/2, 0)
inventoryItemFont.Print(str)
gl.PopMatrix()
}
示例9: Print
func (self *Font) Print(str string) {
for _, ch := range str {
self.textures[ch].Bind(gl.TEXTURE_2D)
h := float32(self.height) * PIXEL_SCALE
w := float32(self.widths[ch]) * PIXEL_SCALE
gl.Color4ub(255, 255, 255, 255)
gl.Begin(gl.QUADS)
gl.TexCoord2d(0, 0)
gl.Vertex2f(0, 0) // Bottom Left Of The Texture and Quad
gl.TexCoord2d(1, 0)
gl.Vertex2f(w, 0) // Bottom Right Of The Texture and Quad
gl.TexCoord2d(1, 1)
gl.Vertex2f(w, h) // Top Right Of The Texture and Quad
gl.TexCoord2d(0, 1)
gl.Vertex2f(0, h) // Top Left Of The Texture and Quad
gl.End()
gl.Translatef(w, 0, 0)
self.textures[ch].Unbind(gl.TEXTURE_2D)
}
}
示例10: Draw
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()
//.........这里部分代码省略.........
示例11: Render
func (s *Scatter) Render(w, h, d float64) {
gl.PushMatrix()
min, max := s.points.Bounds()
dim := max.Sub(min)
gl.Scaled(w/dim.X, h/dim.Y, d/dim.Z)
gl.Translated(-min.X, -min.Y, -min.Z)
// Draw axes: red X, green Y, blue Z.
gl.Begin(gl.LINES)
gl.LineWidth(1.5)
gl.Color3ub(255, 0, 0)
gl.Vertex3d(min.X, min.Y, min.Z)
gl.Vertex3d(max.X, min.Y, min.Z)
gl.Color3ub(0, 255, 0)
gl.Vertex3d(min.X, min.Y, min.Z)
gl.Vertex3d(min.X, max.Y, min.Z)
gl.Color3ub(0, 0, 255)
gl.Vertex3d(min.X, min.Y, min.Z)
gl.Vertex3d(min.X, min.Y, max.Z)
gl.End()
// Draw 2d plots on the XY, YZ, and XZ planes.
gl.PointSize(10.0)
gl.Begin(gl.POINTS)
// X plot
gl.Color4ub(255, 0, 0, 31)
for _, p := range s.points {
gl.Vertex3d(p.X, min.Y, min.Z)
}
// Y plot
gl.Color4ub(0, 255, 0, 31)
for _, p := range s.points {
gl.Vertex3d(min.X, p.Y, min.Z)
}
// Z plot
gl.Color4ub(0, 0, 255, 31)
for _, p := range s.points {
gl.Vertex3d(min.X, min.Y, p.Z)
}
// XY plot
gl.Color4ub(255, 255, 0, 63)
for _, p := range s.points {
gl.Vertex3d(p.X, p.Y, min.Z)
}
// YZ plot
gl.Color4ub(0, 255, 255, 63)
for _, p := range s.points {
gl.Vertex3d(min.X, p.Y, p.Z)
}
// XZ plot
gl.Color4ub(255, 0, 255, 63)
for _, p := range s.points {
gl.Vertex3d(p.X, min.Y, p.Z)
}
// XYZ plot
gl.Color4ub(255, 255, 255, 128)
for _, p := range s.points {
gl.Vertex3d(p.X, p.Y, p.Z)
}
gl.End()
gl.PopMatrix()
}
示例12: drawGLScene
// 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
}
}
示例13: Draw
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++
}
示例14: Draw
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()
}
示例15: Draw
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()
}