func (m *Model) Render() { if globals.UseShader { program.SetModelMatrix(m.Mat) m.data.Render() } else { gl.PushMatrix() gl.MultMatrixf(m.Mat.Ptr32()) m.data.Render() gl.PopMatrix() } }
func (t *Nurbs) Render() { t.vbo.Enable() if globals.UseShader { program.SetModelMatrix(mat4.Identity()) t.vbo.Draw(gl.TRIANGLES) } else { gl.PushMatrix() gl.MultMatrixf(mat4.Identity().Ptr32()) t.vbo.Draw(gl.TRIANGLES) gl.PopMatrix() } t.vbo.Disable() }
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++ }
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() }