// reset our viewport after a window resize func resizeWindow(width, height int) { // protect against a divide by zero if height == 0 { height = 1 } // Setup our viewport gl.Viewport(0, 0, int(width), int(height)) // change to the projection matrix and set our viewing volume. gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() // aspect ratio aspect := gl.GLdouble(gl.GLfloat(width) / gl.GLfloat(height)) // Set our perspective. // This code is equivalent to using gluPerspective as in the original tutorial. var fov, near, far gl.GLdouble fov = 45.0 near = 0.1 far = 100.0 top := gl.GLdouble(math.Tan(float64(fov*math.Pi/360.0))) * near bottom := -top left := aspect * bottom right := aspect * top gl.Frustum(float64(left), float64(right), float64(bottom), float64(top), float64(near), float64(far)) // Make sure we're changing the model view and not the projection gl.MatrixMode(gl.MODELVIEW) // Reset the view gl.LoadIdentity() }
// Handle the window being resized. func reshape(width int, height int) { // Render into the entire window. gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() // Configure the Frustrum so the front face of the rendering // volume fills the screen. w := float64(width) h := float64(height) depth := (w + h) / 2 near := depth / 2.0 right := w / 4.0 top := h / 4.0 far := 4 * depth gl.Frustum(-right, right, -top, top, near, far) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() // Center the rendering volume in the viewport. Its origin // is at the far lower left corner. gl.Translated(-w/2, -h/2, -2*depth) }
/* new window size or exposure */ func reshape(width int, height int) { h := float64(height) / float64(width) gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0.0, 0.0, -40.0) }
func (self *Viewport) Perspective(fovy, aspect, zNear, zFar float64) { gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() var xmin, xmax, ymin, ymax float64 ymax = zNear * math.Tan(fovy*math.Pi/360.0) ymin = -ymax xmin = ymin * aspect xmax = ymax * aspect gl.Frustum(xmin, xmax, ymin, ymax, zNear, zFar) gl.MatrixMode(gl.MODELVIEW) gl.Hint(gl.PERSPECTIVE_CORRECTION_HINT, gl.NICEST) gl.DepthMask(true) }
func initGl() { h := float64(height) / float64(width) gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1.0, 1.0, -h, h, 5.0, 60.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translatef(0.0, 0.0, -6.0) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) gl.VertexPointer(3, 0, &vertices[0][0]) gl.TexCoordPointer(2, 0, &texCoords[0][0]) }
func setup_opengl(width, height int) { ratio := float64(width) / float64(height) gl.ShadeModel(gl.SMOOTH) gl.CullFace(gl.BACK) gl.FrontFace(gl.CCW) gl.Enable(gl.CULL_FACE) gl.ClearColor(0, 0, 0, 0) gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gluPerspective := func(fovy, aspect, zNear, zFar float64) { top := math.Tan(fovy*0.5) * zNear bottom := -top left := aspect * bottom right := -left gl.Frustum(left, right, bottom, top, zNear, zFar) } gluPerspective(60.0, ratio, 1.0, 1024.0) }