// 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 } }
// 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 } }