// Set the GL modelview matrix to match view position and orientation. func UpdateViewpos() { gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(gl.Float(Viewpos[0]), gl.Float(Viewpos[1]), gl.Float(Viewpos[2])) gl.Rotatef(gl.Float(Rot[0]*2), 1, 0, 0) gl.Rotatef(gl.Float(Rot[1]*2), 0, 1, 0) gl.Rotatef(gl.Float(Rot[2]*2), 0, 0, 1) }
func DrawStarTex(t *data.Star) { // Find the center point of the texture to rotate around xav := (t.X1 + t.X2) / 2 yav := (t.Y1 + t.Y2) / 2 //Translate there, rotate, translate back gl.MatrixMode(gl.MODELVIEW) gl.Translatef(xav, yav, 0) gl.Rotatef(gl.Float(t.Theta), 0, 0, 1) gl.Translatef(-xav, -yav, 0) //Bind our texture to be drawn by id gl.Color3f(1, 1, 1) gl.Enable(gl.TEXTURE_2D) gl.BindTexture(gl.TEXTURE_2D, t.TexId) // Draw a rectangle with the texture stretched to the corners gl.Begin(gl.QUADS) // Stretch the texture to its 4 corners. gl.TexCoord2d(0, 0) gl.Vertex2f(t.X1, t.Y1) gl.TexCoord2d(0, 1) gl.Vertex2f(t.X1, t.Y2) gl.TexCoord2d(1, 1) gl.Vertex2f(t.X2, t.Y2) gl.TexCoord2d(1, 0) gl.Vertex2f(t.X2, t.Y1) gl.End() // Unbind the texture in case something else wants to draw gl.Disable(gl.TEXTURE_2D) // Reset the matrix gl.LoadIdentity() }
func initScene() { gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.LIGHTING) gl.ClearColor(0.1, 0.1, 0.6, 1.0) gl.ClearDepth(1) gl.DepthFunc(gl.LEQUAL) gl.Lightfv(gl.LIGHT0, gl.AMBIENT, &ambient[0]) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, &diffuse[0]) gl.Lightfv(gl.LIGHT0, gl.POSITION, &lightPos[0]) gl.Enable(gl.LIGHT0) gl.Viewport(0, 0, Width, Height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.0, 1000.0) gl.Rotatef(20, 1, 0, 0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.PushMatrix() return }
func drawScene() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0, 0, -3.0) gl.Rotatef(rotx, 1, 0, 0) gl.Rotatef(roty, 0, 1, 0) rotx += 0.5 roty += 0.5 gl.BindTexture(gl.TEXTURE_2D, texture) gl.Color4f(1, 1, 1, 1) gl.Begin(gl.QUADS) gl.Normal3f(0, 0, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, -1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(1, -1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, 1) gl.Normal3f(0, 0, -1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, 1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, 1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, -1) gl.Normal3f(0, 1, 0) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, 1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, -1) gl.Normal3f(0, -1, 0) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, -1, -1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, 1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, 1) gl.Normal3f(1, 0, 0) gl.TexCoord2f(1, 0) gl.Vertex3f(1, -1, -1) gl.TexCoord2f(1, 1) gl.Vertex3f(1, 1, -1) gl.TexCoord2f(0, 1) gl.Vertex3f(1, 1, 1) gl.TexCoord2f(0, 0) gl.Vertex3f(1, -1, 1) gl.Normal3f(-1, 0, 0) gl.TexCoord2f(0, 0) gl.Vertex3f(-1, -1, -1) gl.TexCoord2f(1, 0) gl.Vertex3f(-1, -1, 1) gl.TexCoord2f(1, 1) gl.Vertex3f(-1, 1, 1) gl.TexCoord2f(0, 1) gl.Vertex3f(-1, 1, -1) gl.End() }