// 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 InitGL() error { defer tlog.FuncLog(tlog.Func("InitGL")) err := gl.Init() if err != nil { return err } gl.GetError() // cleanup gl error state version := gl.GoStr(gl.GetString(gl.VERSION)) tlog.Println("OpenGL version", version) gl.PolygonMode(gl.FRONT_AND_BACK, gl.FILL) Check() gl.ReadBuffer(gl.BACK) Check() gl.DrawBuffer(gl.BACK) Check() gl.FrontFace(gl.CW) Check() gl.CullFace(gl.BACK) Check() gl.Disable(gl.CULL_FACE) Check() gl.ClearColor(1, 1, 0.5, 0) Check() gl.ClearDepth(1.0) Check() gl.ClearStencil(0) Check() gl.Disable(gl.STENCIL_TEST) Check() gl.StencilMask(0xFFFFFFFF) Check() gl.StencilFunc(gl.EQUAL, 0x00000000, 0x00000001) Check() gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) Check() gl.Disable(gl.DITHER) Check() gl.Enable(gl.DEPTH_TEST) Check() gl.DepthFunc(gl.LEQUAL) Check() gl.DepthMask(true) Check() gl.DepthRange(0., 1.) Check() gl.Enable(gl.DEPTH_CLAMP) Check() gl.Enable(gl.BLEND) Check() gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) ForceCheck() return nil }