func size_window(x, y int, fov, aspect, min_cull, max_cull float64) { gl.Viewport(0, 0, x, y) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() glu.Perspective(fov, aspect, min_cull, max_cull) gl.Enable(gl.DEPTH_TEST) }
func display() { gl.Clear(gl.COLOR_BUFFER_BIT) bitmap_output(40, 35, "This is written in a GLUT bitmap font.", glut.BITMAP_TIMES_ROMAN_24) bitmap_output(30, 210, "More bitmap text is a fixed 9 by 15 font.", glut.BITMAP_9_BY_15) bitmap_output(70, 240, " Helvetica is yet another bitmap font.", glut.BITMAP_HELVETICA_18) gl.MatrixMode(gl.PROJECTION) gl.PushMatrix() gl.LoadIdentity() glu.Perspective(40.0, 1.0, 0.1, 20.0) gl.MatrixMode(gl.MODELVIEW) gl.PushMatrix() glu.LookAt(0.0, 0.0, 4.0, /* eye is at (0,0,30) */ 0.0, 0.0, 0.0, /* center is at (0,0,0) */ 0.0, 1.0, 0.0) /* up is in postivie Y direction */ gl.PushMatrix() gl.Translatef(0, 0, -4) gl.Rotatef(50, 0, 1, 0) stroke_output(-2.5, 1.1, " This is written in a", glut.STROKE_ROMAN) stroke_output(-2.5, 0, " GLUT stroke font.", glut.STROKE_ROMAN) stroke_output(-2.5, -1.1, "using 3D perspective.", glut.STROKE_ROMAN) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) gl.PopMatrix() gl.MatrixMode(gl.PROJECTION) gl.PopMatrix() gl.MatrixMode(gl.MODELVIEW) gl.Flush() }
// Initialize the OpenGL configuration with the information from the current window. func InitGLWindow(w, h int) { gl.Viewport(0, 0, w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() }
func main() { var err error if err = glfw.Init(); err != nil { fmt.Fprintf(os.Stderr, "[e] %v\n", err) return } defer glfw.Terminate() // Open window with FSAA samples (if possible). glfw.OpenWindowHint(glfw.FsaaSamples, 4) if err = glfw.OpenWindow(400, 400, 0, 0, 0, 0, 0, 0, glfw.Windowed); err != nil { fmt.Fprintf(os.Stderr, "[e] %v\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle("Aliasing Detector") glfw.SetSwapInterval(1) if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 { fmt.Fprintf(os.Stdout, "Context reports FSAA is supported with %d samples\n", samples) } else { fmt.Fprintf(os.Stdout, "Context reports FSAA is unsupported\n") } gl.MatrixMode(gl.PROJECTION) glu.Perspective(0, 1, 0, 1) for glfw.WindowParam(glfw.Opened) == 1 { time := float32(glfw.Time()) gl.Clear(gl.COLOR_BUFFER_BIT) gl.LoadIdentity() gl.Translatef(0.5, 0, 0) gl.Rotatef(time, 0, 0, 1) gl.Enable(GL_MULTISAMPLE_ARB) gl.Color3f(1, 1, 1) gl.Rectf(-0.25, -0.25, 0.25, 0.25) gl.LoadIdentity() gl.Translatef(-0.5, 0, 0) gl.Rotatef(time, 0, 0, 1) gl.Disable(GL_MULTISAMPLE_ARB) gl.Color3f(1, 1, 1) gl.Rectf(-0.25, -0.25, 0.25, 0.25) glfw.SwapBuffers() } }
func onResize(w, h int) { if h == 0 { h = 1 } gl.Viewport(0, 0, w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() glu.Perspective(45.0, float64(w)/float64(h), 0.1, 100.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() }
func reshape(width, height int) { shift, aspect := 0, float64(width)/float64(height) if aspect > 2 { aspect = 2 shift = width/2 - height width = height * 2 } gl.Viewport(shift, 0, width, height) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.COLOR_MATERIAL) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() glu.Perspective(45, aspect, NEAR_Z, FAR_Z) gl.Enable(gl.LIGHTING) gl.Lightfv(gl.LIGHT0, gl.POSITION, []float32{-2, -3, 5, 0}) gl.Lightfv(gl.LIGHT0, gl.AMBIENT, []float32{0.1, 0.1, 0.2, 1}) gl.Lightfv(gl.LIGHT0, gl.DIFFUSE, []float32{0.4, 0.35, 0.2, 1}) gl.Lightfv(gl.LIGHT0, gl.SPECULAR, []float32{1, 1, 1, 1}) gl.Enable(gl.LIGHT0) gl.Rotatef(-30, 1, 0, 0) gl.Translatef(0, 0, -5) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Lightfv(gl.LIGHT1, gl.AMBIENT, []float32{0, 0, 0, 1}) gl.Lightfv(gl.LIGHT1, gl.DIFFUSE, []float32{0.4, 0.4, 0.4, 1}) gl.Lightfv(gl.LIGHT1, gl.SPECULAR, []float32{1, 1, 1, 1}) gl.Enable(gl.LIGHT1) }