func initOGL() { display = egl.GetDisplay(egl.DEFAULT_DISPLAY) if ok := egl.Initialize(display, nil, nil); !ok { egl.LogError(egl.GetError()) } if ok := egl.ChooseConfig(display, attr, &config, 1, &numConfig); !ok { egl.LogError(egl.GetError()) } if ok := egl.GetConfigAttrib(display, config, egl.NATIVE_VISUAL_ID, &vid); !ok { egl.LogError(egl.GetError()) } egl.BindAPI(egl.OPENGL_ES_API) context = egl.CreateContext(display, config, egl.NO_CONTEXT, &ctxAttr[0]) screen_width, screen_height = egl.GraphicsGetDisplaySize(0) log.Printf("Display size W: %d H: %d\n", screen_width, screen_height) dstRect.X = 0 dstRect.Y = 0 dstRect.Width = int32(screen_width) dstRect.Height = int32(screen_height) srcRect.X = 0 srcRect.Y = 0 srcRect.Width = int32(screen_width << 16) srcRect.Height = int32(screen_height << 16) dispman_display := egl.VCDispmanxDisplayOpen(0 /* LCD */) dispman_update := egl.VCDispmanxUpdateStart(0) dispman_element := egl.VCDispmanxElementAdd( dispman_update, dispman_display, 0, /*layer */ &dstRect, 0, /*src */ &srcRect, egl.DISPMANX_PROTECTION_NONE, nil, /*alpha */ nil, /*clamp */ 0 /*transform */) check() nativeWindow.Element = dispman_element nativeWindow.Width = int(screen_width) nativeWindow.Height = int(screen_height) egl.VCDispmanxUpdateSubmitSync(dispman_update) check() surface = egl.CreateWindowSurface( display, config, egl.NativeWindowType(unsafe.Pointer(&nativeWindow)), nil) assert(surface != egl.NO_SURFACE) // connect the context to the surface result := egl.MakeCurrent(display, surface, surface, context) assert(result) var val int32 if ok := egl.QuerySurface(display, &val, egl.WIDTH, surface); !ok { egl.LogError(egl.GetError()) } if ok := egl.QuerySurface(display, &val, egl.HEIGHT, surface); !ok { egl.LogError(egl.GetError()) } if ok := egl.GetConfigAttrib(display, config, egl.SURFACE_TYPE, &val); !ok { egl.LogError(egl.GetError()) } gl.ClearColor(0.0, 0.0, 0.0, 1.0) gl.Viewport(0, 0, gl.Sizei(screen_width), gl.Sizei(screen_height)) }
func initOGL(state *CubeState) { var ( config egl.Config numConfig int32 dstRect, srcRect egl.VCRect nativeWindow egl.EGLDispmanxWindow ) attr := []int32{ egl.RED_SIZE, 8, egl.GREEN_SIZE, 8, egl.BLUE_SIZE, 8, egl.ALPHA_SIZE, 8, egl.SURFACE_TYPE, egl.WINDOW_BIT, egl.NONE, } egl.BCMHostInit() state.display = egl.GetDisplay(0) egl.Initialize(state.display, nil, nil) egl.ChooseConfig(state.display, attr, &config, 1, &numConfig) egl.BindAPI(egl.OPENGL_ES_API) context := egl.CreateContext(state.display, config, egl.NO_CONTEXT, nil) state.screen_width, state.screen_height = egl.GraphicsGetDisplaySize(0) log.Printf("Display size W: %d H: %d\n", state.screen_width, state.screen_height) dstRect.X = 0 dstRect.Y = 0 dstRect.Width = int32(state.screen_width) dstRect.Height = int32(state.screen_height) srcRect.X = 0 srcRect.Y = 0 srcRect.Width = int32(state.screen_width << 16) srcRect.Height = int32(state.screen_height << 16) dispman_display := egl.VCDispmanxDisplayOpen(0 /* LCD */) dispman_update := egl.VCDispmanxUpdateStart(0) dispman_element := egl.VCDispmanxElementAdd( dispman_update, dispman_display, 0, /*layer */ &dstRect, 0, /*src */ &srcRect, egl.DISPMANX_PROTECTION_NONE, nil, /*alpha */ nil, /*clamp */ 0 /*transform */) log.Printf("DispmanDisplay 0x%x DispmanUpdate 0x%x DispmanElement 0x%x\n", dispman_display, dispman_update, dispman_element) nativeWindow.Element = dispman_element nativeWindow.Width = int(state.screen_width) nativeWindow.Height = int(state.screen_height) egl.VCDispmanxUpdateSubmitSync(dispman_update) surface := egl.CreateWindowSurface( state.display, config, egl.NativeWindowType(unsafe.Pointer(&nativeWindow)), nil) log.Printf("Surface 0x%x\n", surface) // preserve the buffers on swap egl.SurfaceAttrib(state.display, surface, egl.SWAP_BEHAVIOR, egl.BUFFER_PRESERVED) // connect the context to the surface result := egl.MakeCurrent(state.display, surface, surface, context) log.Printf("MakeCurrent result %d\n", result) var fb uint32 var rb uint32 gl.GenFramebuffers(1, &fb) gl.BindFramebuffer(gl.FRAMEBUFFER, fb) gl.GenRenderbuffers(1, &rb) gl.BindRenderbuffer(gl.RENDERBUFFER, rb) gl.RenderbufferStorage(gl.RENDERBUFFER, gl.RGBA4, gl.Sizei(state.screen_width), gl.Sizei(state.screen_height)) // Set background color and clear buffers gl.ClearColor(0.15, 0.25, 0.35, 1.0) gl.Clear(gl.COLOR_BUFFER_BIT) gl.BindFramebuffer(gl.FRAMEBUFFER, fb) gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.RENDERBUFFER, rb) gl.BindFramebuffer(gl.FRAMEBUFFER, 0) gl.Viewport(0, 0, gl.Sizei(state.screen_width), gl.Sizei(state.screen_height)) }