func Main(username, uuid, accessToken string) { if err := glfw.Init(); err != nil { panic(err) } defer glfw.Terminate() console.ExecConf("conf.cfg") if username != "" { clientUsername.SetValue(username) } if uuid != "" { clientUUID.SetValue(uuid) } if accessToken != "" { clientAccessToken.SetValue(accessToken) skipLogin = true } initResources() setUIScale() startWindow() }
func main() { if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(640, 480, "tut03", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } t0 := time.Now() program := initResources() for { curFade = float32(math.Sin(time.Now().Sub(t0).Seconds()*2*math.Pi/5)/2 + 0.5) onDisplay(program) window.SwapBuffers() glfw.PollEvents() } gl.DeleteProgram(program) gl.DeleteBuffers(1, &vboTriangle) }
func Run(g *Game) error { if g.Scene == nil { return fmt.Errorf("Scene property of given Game struct is empty") } // GLFW event handling must run on the main OS thread runtime.LockOSThread() if err := glfw.Init(); err != nil { return fmt.Errorf("glfw.Init failed: %s", err) } defer glfw.Terminate() glfw.WindowHint(glfw.ContextVersionMajor, OpenGLVerMinor) glfw.WindowHint(glfw.ContextVersionMinor, OpenGLVerMinor) glfw.WindowHint(glfw.Resizable, glfw.False) if g.Resizable { glfw.WindowHint(glfw.Resizable, glfw.True) } glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) window, err := glfw.CreateWindow(int(g.Width), int(g.Height), g.Title, nil, nil) if err != nil { return fmt.Errorf("glfw.CreateWindow failed: %s", err) } window.MakeContextCurrent() // Initialize Glow if err := gl.Init(); err != nil { return fmt.Errorf("gl.Init failed:", err) } version := gl.GoStr(gl.GetString(gl.VERSION)) log.Println("gl.Init successful, OpenGL version:", version) var previousTime, deltaTime, time float32 previousTime = float32(glfw.GetTime()) - 1.0/60.0 g.Scene.Setup() for !window.ShouldClose() { time = float32(glfw.GetTime()) deltaTime = time - previousTime glfw.PollEvents() gl.ClearColor(0.2, 0.3, 0.3, 0.5) gl.Clear(gl.COLOR_BUFFER_BIT) g.Scene.Update(deltaTime) g.Scene.Draw(deltaTime) previousTime = time window.SwapBuffers() } return nil }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() width, height = 800, 800 window, err := glfw.CreateWindow(width, height, "Show RoundedRect", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() window.SetSizeCallback(reshape) window.SetKeyCallback(onKey) window.SetCharCallback(onChar) glfw.SwapInterval(1) err = gl.Init() if err != nil { panic(err) } reshape(window, width, height) for !window.ShouldClose() { if redraw { display() window.SwapBuffers() redraw = false } glfw.PollEvents() // time.Sleep(2 * time.Second) } }
// RenderLinesWithEvents renders multiple channels of samples to screen, and draws events. func (s *Screen) RenderLinesWithEvents(lines []Line, events <-chan interface{}, sampleRate int) { s.lines = lines runtime.LockOSThread() // NOTE: It appears that glfw 3.1 uses its own internal error callback. // glfw.SetErrorCallback(func(err glfw.ErrorCode, desc string) { // log.Fatalf("%v: %s\n", err, desc) // }) if err := glfw.Init(); err != nil { log.Fatalf("Can't init glfw: %v!", err) } defer glfw.Terminate() window, err := glfw.CreateWindow(s.width, s.height, "Muse", nil, nil) if err != nil { log.Fatalf("CreateWindow failed: %s", err) } if aw, ah := window.GetSize(); aw != s.width || ah != s.height { log.Fatalf("Window doesn't have the requested size: want %d,%d got %d,%d", s.width, s.height, aw, ah) } window.MakeContextCurrent() // Must gl.Init() *after* MakeContextCurrent if err := gl.Init(); err != nil { log.Fatalf("Can't init gl: %v!", err) } // Set window up to be [0, -1.0] -> [width, 1.0], black. gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Translated(-1, 0, 0) gl.Scaled(2/float64(s.width), 1.0, 1.0) gl.ClearColor(0.0, 0.0, 0.0, 0.0) // Actually start writing data to the buffer for i, _ := range s.lines { s.lines[i].valueBuffer = types.NewBuffer(int(float64(s.width) / s.pixelsPerSample)) s.lines[i].valueBuffer.GoPushChannel(s.lines[i].Values, sampleRate) } if events != nil { s.eventBuffer.GoPushChannel(events, sampleRate) } // Keep drawing while we still can (and should). for !window.ShouldClose() && !s.bufferFinished() { if window.GetKey(glfw.KeyEscape) == glfw.Press { break } gl.Clear(gl.COLOR_BUFFER_BIT) s.drawSignal() window.SwapBuffers() glfw.PollEvents() } // Keep window around, only close on esc. for !window.ShouldClose() && window.GetKey(glfw.KeyEscape) != glfw.Press { glfw.PollEvents() } }
func main() { if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(800, 600, "Create Window Example", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } window.SetKeyCallback(keypress) window.SetMouseButtonCallback(mousepress) gl.Viewport(0, 0, 800, 600) for !window.ShouldClose() { draw() window.SwapBuffers() glfw.PollEvents() } }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() w, err := glfw.CreateWindow(640, 480, "Testing", nil, nil) if err != nil { panic(err) } w.MakeContextCurrent() glfw.SwapInterval(1) w.SetCharCallback(charCallBack) if err := gl.Init(); err != nil { panic(err) } setupScene(w) fmt.Println("Press 'q' to quit") for !w.ShouldClose() { // Do OpenGL stuff. time.Sleep(10 * time.Millisecond) drawScene(w) w.SwapBuffers() glfw.PollEvents() } }
func main() { if err := glfw.Init(); err != nil { log.Fatalln("failed to inifitialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 4) glfw.WindowHint(glfw.ContextVersionMinor, 1) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) window, err := glfw.CreateWindow(windowWidth, windowHeight, "basic shaders", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() // Initialize Glow (go function bindings) if err := gl.Init(); err != nil { panic(err) } window.SetKeyCallback(keyCallback) err = programLoop(window) if err != nil { log.Fatal(err) } }
func main() { if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(640, 480, "tut01", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } program, coords := initResources() for { onDisplay(program, uint32(coords)) window.SwapBuffers() } }
func main() { if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(800, 600, "Cube", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } texture = newTexture("square.png") defer gl.DeleteTextures(1, &texture) setupScene() for !window.ShouldClose() { drawScene() window.SwapBuffers() glfw.PollEvents() } }
func CreateContext(width int, height int) (*Context, error) { if err := glfw.Init(); err != nil { fmt.Println("failed to initialize glfw:", err) } glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 4) glfw.WindowHint(glfw.ContextVersionMinor, 1) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) window, err := glfw.CreateWindow(width, height, "flamingo", nil, nil) if err != nil { glfw.Terminate() return nil, err } window.MakeContextCurrent() // Initialize Glow if err = gl.Init(); err != nil { glfw.Terminate() return nil, err } version := gl.GoStr(gl.GetString(gl.VERSION)) fmt.Println("OpenGL version", version) return &Context{window}, nil }
// InitGraphics creates an OpenGL window and initializes the required graphics libraries. // It will either succeed or panic. func (app *ExampleApp) InitGraphics(title string, w int, h int) { err := glfw.Init() if err != nil { panic("Can't init glfw! " + err.Error()) } // request a OpenGL 3.3 core context glfw.WindowHint(glfw.Samples, 0) glfw.WindowHint(glfw.ContextVersionMajor, 3) glfw.WindowHint(glfw.ContextVersionMinor, 3) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // do the actual window creation app.MainWindow, err = glfw.CreateWindow(w, h, title, nil, nil) if err != nil { panic("Failed to create the main window! " + err.Error()) } app.MainWindow.MakeContextCurrent() glfw.SwapInterval(0) // make sure that all of the GL functions are initialized err = gl.Init() if err != nil { panic("Failed to initialize GL! " + err.Error()) } // set the app window dimensions app.Width = w app.Height = h gl.FrontFace(gl.CCW) gl.CullFace(gl.BACK) gl.Enable(gl.CULL_FACE) }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } window.SetKeyCallback(game.OnKey) game.Init() for !window.ShouldClose() { game.Render() window.SwapBuffers() glfw.PollEvents() } }
func glInit() { window.Set("cls", false) if err = glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } checkMon() win.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } win.SetPos(projMonitor.GetPos()) setupScene() qml.Func1 = func() int { if !win.ShouldClose() { //glfw.PollEvents() drawSlide() win.SwapBuffers() return 0 } win.Hide() //win.Destroy() //glfw.Terminate() return 1 } }
func initGraphics() error { if err := gl.Init(); err != nil { return err } if err := glfw.Init(); err != nil { return err } glfw.WindowHint(glfw.Resizable, glfw.False) var err error window, err = glfw.CreateWindow(64*scaleRatio, 32*scaleRatio, "CHIP-8 Emulator", nil, nil) if err != nil { return err } window.MakeContextCurrent() gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, 64, 32, 0, 0, 1) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() clear() window.SwapBuffers() return nil }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() w, err := glfw.CreateWindow(640, 480, "Testing 3+", nil, nil) if err != nil { panic(err) } w.MakeContextCurrent() glfw.SwapInterval(1) w.SetCharCallback(charCallBack) if err := gl.Init(); err != nil { panic(err) } r := makeResources() gl.ClearColor(.5, .5, .5, 0) fmt.Println("Press 'q' to quit") for !w.ShouldClose() { time.Sleep(10 * time.Millisecond) render(w, r) w.SwapBuffers() glfw.PollEvents() } }
func (self *Application) run() error { if err := glfw.Init(); err != nil { return err } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 4) glfw.WindowHint(glfw.ContextVersionMinor, 1) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) window, err := glfw.CreateWindow(512, 512, "GL", nil, nil) if err != nil { return err } window.MakeContextCurrent() if err := gl.Init(); err != nil { return err } if err := self.setup(); err != nil { return err } for !window.ShouldClose() { self.display() window.SwapBuffers() glfw.PollEvents() } return nil }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } // int width, height // glfw.GetFramebufferSize(window, &width, &height) for !window.ShouldClose() { // Do OpenGL stuff. gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.Color3f(1, 1, 0) gl.Rectf(-0.75, 0.75, 0.75, -0.75) gl.Color3f(1, 0, 1) gl.Rectf(-0.5, 0.5, 0.5, -0.5) window.SwapBuffers() glfw.PollEvents() } }
func main() { flag.Parse() go func() { http.ListenAndServe("localhost:6060", nil) }() if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.True) glfw.WindowHint(glfw.Visible, glfw.False) // do not steal focus glfw.WindowHint(glfw.ContextVersionMajor, 2) glfw.WindowHint(glfw.ContextVersionMinor, 1) window, err := glfw.CreateWindow(800, 600, "Spector", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() window.Restore() window.SetPos(32, 64) if err := gl.Init(); err != nil { panic(err) } state := NewState() for !window.ShouldClose() { if window.GetKey(glfw.KeyEscape) == glfw.Press { return } if window.GetKey(glfw.KeyR) == glfw.Press { state.Stop() state = NewState() } start := time.Now() state.Update(1.0 / 60.0) updateTime := time.Since(start) start = time.Now() state.Render(window) renderTime := time.Since(start) text := fmt.Sprintf("update: %.2fms render: %.2fms", float32(updateTime)/float32(time.Millisecond), float32(renderTime)/float32(time.Millisecond)) w, h := window.GetSize() state.Backend.SetFontColor(ui.ColorHex(0xFF0000FF)) size := state.Backend.Measure(text) state.Backend.Text(text, ui.Block(float32(w)-size.X, float32(h)-size.Y, size.X, size.Y)) window.SwapBuffers() glfw.PollEvents() } }
func main() { width := 1024 height := 768 title := "Simple Triangle" if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } defer glfw.Terminate() glfw.WindowHint(glfw.Samples, 4) // 4x antialiasing glfw.WindowHint(glfw.ContextVersionMajor, 3) // We want OpenGL 3.3 glfw.WindowHint(glfw.ContextVersionMinor, 3) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) // To make MacOS happy; should not be needed glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) //We don't want the old OpenGL window, err := glfw.CreateWindow(width, height, title, nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } window.SetKeyCallback(keypress) window.SetMouseButtonCallback(mousepress) gl.Viewport(0, 0, 1024, 768) for !window.ShouldClose() { draw() window.SwapBuffers() glfw.PollEvents() } }
func Init() { runtime.LockOSThread() err := glfw.Init() if err != nil { panic(fmt.Sprintf("glfw.Init() fails: %v", err)) } glfw.WindowHint(glfw.Visible, glfw.False) glfw.WindowHint(glfw.Resizable, glfw.False) // As start, create an window with temporary size to create OpenGL context thread. window, err := glfw.CreateWindow(16, 16, "", nil, nil) if err != nil { panic(err) } u := &userInterface{ window: window, funcs: make(chan func()), } go func() { runtime.LockOSThread() u.window.MakeContextCurrent() glfw.SwapInterval(1) for f := range u.funcs { f() } }() currentUI = u }
func (glr *GlRenderer) initSystem() { // Lock goroutine to main thread - required for GL runtime.LockOSThread() var err error if err = glfw.Init(); err != nil { panic(err) } glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 3) glfw.WindowHint(glfw.ContextVersionMinor, 3) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) glr.window, err = glfw.CreateWindow(glr.width, glr.height, "rt", nil, nil) if err != nil { panic(err) } glr.window.MakeContextCurrent() if err = gl.Init(); err != nil { panic(err) } version := gl.GoStr(gl.GetString(gl.VERSION)) fmt.Println("OpenGL version", version) }
func (me *Core) Init() { if err := glfw.Init(); err != nil { panic(err) } if err := gl.Init(); err != nil { panic(err) } }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() fp, err := os.Open("example.tmx") if err != nil { panic(err) } m, err := tmx.NewMap(fp) if err != nil { panic(err) } var monitor *glfw.Monitor window, err := glfw.CreateWindow(screenWidth, screenHeight, "Map Renderer", monitor, nil) if err != nil { panic(err) } window.MakeContextCurrent() if err := gl.Init(); err != nil { panic(err) } width, height := window.GetFramebufferSize() gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.ClearColor(1.0, 1.0, 1.0, 1.0) gl.Viewport(0, 0, int32(width), int32(height)) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, float64(width), float64(height), 0, -1, 1) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) canvas := newOpenGLCanvas(width, height, float32(width)/float32(screenWidth), float32(height)/float32(screenHeight)) renderer := tmx.NewRenderer(*m, canvas) fps := 0 startTime := time.Now().UnixNano() timer := tmx.CreateTimer() timer.Start() for !window.ShouldClose() { elapsed := float64(timer.GetElapsedTime()) / (1000 * 1000) renderer.Render(int64(math.Ceil(elapsed))) fps++ if time.Now().UnixNano()-startTime > 1000*1000*1000 { log.Println(fps) startTime = time.Now().UnixNano() fps = 0 } window.SwapBuffers() glfw.PollEvents() timer.UpdateTime() } }
func CreateRenderer(windowWidth, windowHeight int) *Renderer { if err := glfw.Init(); err != nil { log.Fatalln("failed to initialize glfw:", err) } // defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.False) glfw.WindowHint(glfw.ContextVersionMajor, 4) glfw.WindowHint(glfw.ContextVersionMinor, 1) glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True) if windowWidth == 0 && windowHeight == 0 { windowWidth, windowHeight = glfw.GetPrimaryMonitor().GetPhysicalSize() } fmt.Println("Window Width -", windowWidth, "Window Height -", windowHeight) window, err := glfw.CreateWindow(windowWidth, windowHeight, "Karma", glfw.GetPrimaryMonitor(), nil) if err != nil { panic(err) } window.MakeContextCurrent() window.SetKeyCallback(testCallback) // Initialize Glow if err := gl.Init(); err != nil { panic(err) } version := gl.GoStr(gl.GetString(gl.VERSION)) fmt.Println("OpenGL version", version) shaders := Shaders{} textureFlatUniforms := []string{"projection", "camera", "modelView", "tex"} textureFlatAttributes := []string{"vert", "vertTexCoord"} fmt.Println(textureFlatUniforms) fmt.Println(textureFlatAttributes) shader, err := createProgram("./assets/shaders/texture_flat.vs", "./assets/shaders/texture_flat.fs", textureFlatUniforms, textureFlatAttributes) if err != nil { panic(err) } shaders.textureFlat = shader meshes := []*Mesh{} previousTime := glfw.GetTime() return &Renderer{ PreviousTime: previousTime, Window: window, Shaders: &shaders, Meshes: meshes, } }
func main() { runtime.LockOSThread() if err := glfw.Init(); err != nil { log.Fatal(err) } defer glfw.Terminate() if err := gl.Init(); err != nil { log.Fatal(err) } window, err := glfw.CreateWindow(WindowWidth, WindowHeight, "Texture Demo", nil, nil) if err != nil { log.Fatal(err) } window.MakeContextCurrent() const vertShader = `#version 120 uniform mat4 proj; attribute vec3 vertex_position; attribute vec2 vertex_texture; varying vec2 texture_coordinates; void main() { gl_Position = proj * vec4(vertex_position, 1); texture_coordinates = vertex_texture; } ` const fragShader = `#version 120 uniform sampler2D tex_loc; varying vec2 texture_coordinates; void main() { gl_FragColor = texture2D(tex_loc, texture_coordinates); } ` texture, err := newImageTexture("sq.png") if err != nil { log.Fatal(err) } scene, err := NewScene(vertShader, fragShader, texture) if err != nil { log.Fatal(err) } for !window.ShouldClose() { scene.Draw() glfw.PollEvents() window.SwapBuffers() } }
func Run() { if err := glfw.Init(); err != nil { glog.Fatalln("failed to initialize glfw", err) } defer glfw.Terminate() setupWindowOptions() window, err := glfw.CreateWindow(WindowWidth, WindowHeight, "Game", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() //initilize Glow if err := gl.Init(); err != nil { panic(err) } version := gl.GoStr(gl.GetString(gl.VERSION)) fmt.Println("OpenGL version", version) shaderSource, err := ReadShaders("colorShader") if err != nil { panic(err) } program, err := NewProgram(shaderSource) if err != nil { panic(err) } program.Use() sprite := &SpriteComponent{-.5, -.5, 1, 1} sprite.ReloadGraphics() vertAttrib := uint32(gl.GetAttribLocation(program.program, CStr("vertPosition"))) gl.EnableVertexAttribArray(vertAttrib) gl.VertexAttribPointer(vertAttrib, 3, gl.FLOAT, false, 0, gl.PtrOffset(0)) gl.Enable(gl.DEPTH_TEST) gl.DepthFunc(gl.LESS) gl.ClearColor(1.0, 1.0, 1.0, 1.0) for !window.ShouldClose() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) program.Use() gl.BindVertexArray(sprite.vaoID) gl.DrawArrays(gl.TRIANGLES, 0, 2*3) window.SwapBuffers() glfw.PollEvents() } }
func main() { err := glfw.Init() if err != nil { panic(err) } defer glfw.Terminate() glfw.WindowHint(glfw.Resizable, glfw.True) glfw.WindowHint(glfw.ContextVersionMajor, 3) glfw.WindowHint(glfw.ContextVersionMinor, 3) window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil) if err != nil { panic(err) } defer window.Destroy() window.MakeContextCurrent() glfw.SwapInterval(1) window.SetSizeCallback(func(w *glfw.Window, width int, height int) { fmt.Printf("resize: %d, %d\n", width, height) gl.Viewport(0, 0, int32(width), int32(height)) }) window.SetCursorPosCallback(func(w *glfw.Window, xpos float64, ypos float64) { fmt.Printf("mouse: %f, %f\n", xpos, ypos) }) window.SetFocusCallback(func(w *glfw.Window, focused bool) { fmt.Printf("focus: %t\n", focused) }) window.SetKeyCallback(func(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) { if key == glfw.KeyEscape { window.SetShouldClose(true) } fmt.Printf("key\n") }) window.SetMouseButtonCallback(func(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) { fmt.Printf("mouse\n") }) window.SetCharCallback(func(w *glfw.Window, char rune) { fmt.Printf("char: '%c'\n", char) }) if err := gl.Init(); err != nil { panic(err) } for !window.ShouldClose() { draw() window.SwapBuffers() glfw.PollEvents() } }
func main() { runtime.LockOSThread() if err := glfw.Init(); err != nil { panic(err) } defer glfw.Terminate() window, err := glfw.CreateWindow(800, 600, "fontstash example", nil, nil) if err != nil { panic(err) } window.MakeContextCurrent() glfw.SwapInterval(1) gl.Init() data, err := ioutil.ReadFile(filepath.Join("..", "ClearSans-Regular.ttf")) if err != nil { panic(err) } gl.Enable(gl.TEXTURE_2D) tmpBitmap := make([]byte, 512*512) cdata, err, _, tmpBitmap := truetype.BakeFontBitmap(data, 0, 32, tmpBitmap, 512, 512, 32, 96) var ftex uint32 gl.GenTextures(1, &ftex) gl.BindTexture(gl.TEXTURE_2D, ftex) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, 512, 512, 0, gl.ALPHA, gl.UNSIGNED_BYTE, unsafe.Pointer(&tmpBitmap[0])) gl.ClearColor(0.3, 0.3, 0.32, 1.) for !window.ShouldClose() { gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(0, 800, 600, 0, 0, 1) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Disable(gl.DEPTH_TEST) gl.Color4ub(255, 255, 255, 255) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) my_print(100, 100, "The quick brown fox jumps over the fence", ftex, cdata) window.SwapBuffers() glfw.PollEvents() } }
func main() { runtime.LockOSThread() if err := glfw.Init(); err != nil { log.Fatal(err) } defer glfw.Terminate() if err := gl.Init(); err != nil { log.Fatal(err) } window, err := glfw.CreateWindow(WindowWidth, WindowHeight, "Tetris", nil, nil) if err != nil { log.Fatal(err) } window.MakeContextCurrent() const vshader = `#version 120 uniform mat4 proj, model; attribute vec3 vertex_position; attribute vec2 vertex_texture; varying vec2 texture_coordinates; void main() { gl_Position = proj * model * vec4(vertex_position, 1); texture_coordinates = vertex_texture; } ` const fshader = `#version 120 uniform sampler2D tex_loc; varying vec2 texture_coordinates; void main() { gl_FragColor = texture2D(tex_loc, texture_coordinates); } ` tetris, err := NewTetris(vshader, fshader) if err != nil { log.Fatal(err) } window.SetKeyCallback(tetris.handleKeyInput) for !window.ShouldClose() { tetris.Draw() glfw.PollEvents() window.SwapBuffers() } }