// NewOpenGl initializes the Gl bindings and returns an OpenGl instance. func NewOpenGl() *OpenGl { opengl := &OpenGl{} if err := gl.Init(); err != nil { panic(err) } return opengl }
func (w Window) init() error { sdl.GL_SetAttribute(sdl.GL_DOUBLEBUFFER, 1) sdl.GL_SetAttribute(sdl.GL_RED_SIZE, 8) sdl.GL_SetAttribute(sdl.GL_GREEN_SIZE, 8) sdl.GL_SetAttribute(sdl.GL_BLUE_SIZE, 8) sdl.GL_SetAttribute(sdl.GL_ALPHA_SIZE, 8) if err := gl.Init(); err != nil { return errors.New("Cannot initialize OGL: ") } gl.Viewport(0, 0, int32(w.Width), int32(w.Height)) Opengl.CreateBuffers(w.Width, w.Height) return nil }
func main() { var ( err error window *sdl.Window context sdl.GLContext ) if err = sdl.Init(sdl.INIT_EVERYTHING); err != nil { panic(err) } defer sdl.Quit() sdl.GL_SetAttribute(sdl.GL_CONTEXT_MAJOR_VERSION, 3) sdl.GL_SetAttribute(sdl.GL_CONTEXT_MINOR_VERSION, 2) sdl.GL_SetAttribute(sdl.GL_CONTEXT_PROFILE_MASK, sdl.GL_CONTEXT_PROFILE_CORE) window, err = sdl.CreateWindow(winTitle, sdl.WINDOWPOS_UNDEFINED, sdl.WINDOWPOS_UNDEFINED, winWidth, winHeight, sdl.WINDOW_OPENGL) if err != nil { panic(err) } defer window.Destroy() context, err = sdl.GL_CreateContext(window) if err != nil { panic(err) } defer sdl.GL_DeleteContext(context) if err = sdl.GL_MakeCurrent(window, context); err != nil { panic(err) } if err = gl.Init(); err != nil { panic(err) } printGLInfo() cameraMatrixUniform := setupGL() windowLoop(window, cameraMatrixUniform) }