func main() { var err error if err = glfw.Init(); err != nil { log.Fatalf("%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 { log.Fatalf("%v\n", err) return } defer glfw.CloseWindow() glfw.SetWindowTitle("Aliasing Detector") glfw.SetSwapInterval(1) if samples := glfw.WindowParam(glfw.FsaaSamples); samples != 0 { fmt.Printf("Context reports FSAA is supported with %d samples\n", samples) } else { fmt.Printf("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() } }
// drawString draws the same string for each loaded font. func drawString(x, y float32, str string) error { for i := range fonts { if fonts[i] == nil { continue } // We need to offset each string by the height of the // font. To ensure they don't overlap each other. _, h := fonts[i].GlyphBounds() y := y + float32(i*h) // Draw a rectangular backdrop using the string's metrics. sw, sh := fonts[i].Metrics(SampleString) gl.Color4f(0.1, 0.1, 0.1, 0.7) gl.Rectf(x, y, x+float32(sw), y+float32(sh)) // Render the string. gl.Color4f(1, 1, 1, 1) err := fonts[i].Printf(x, y, str) if err != nil { return err } } return nil }
func (v *video) draw(pixels []byte) { // No need to clear the screen since I explicitly redraw all pixels, at // least currently. gl.MatrixMode(gl.POLYGON) for yline := 0; yline < screenHeight; yline++ { for xline := 0; xline < screenWidth; xline++ { x, y := float32(xline), float32(yline) if pixels[xline+yline*64] == 0 { gl.Color3f(0, 0, 0) } else { gl.Color3f(1, 1, 1) } gl.Rectf(x, y, x+1, y+1) } } glfw.SwapBuffers() }