def set_background(self, r, g, b, alpha): """Set the Display background. **NB the actual drawing of the background happens during the rendering of the framebuffer by the shader so if no draw() is done by anything during each Display loop the screen will remain black** If you want to see just the background you will have to draw() something out of view (i.e. behind) the Camera. *r, g, b* Color values for the display *alpha* Opacity of the color. An alpha of 0 means a transparent background, an alpha of 1 means full opaque. """ opengles.glClearColor(GLclampf(r), GLclampf(g), GLclampf(b), GLclampf(alpha)) opengles.glColorMask(GLboolean(1), GLboolean(1), GLboolean(1), GLboolean(alpha < 1.0))
def set_background(self, r, g, b, alpha): """Set the Display background. **NB the actual drawing of the background happens during the rendering of the framebuffer by the shader so if no draw() is done by anything during each Display loop the screen will remain black** If you want to see just the background you will have to draw() something out of view (i.e. behind) the Camera. *r, g, b* Color values for the display *alpha* Opacity of the color. An alpha of 0 means a transparent background, an alpha of 1 means full opaque. """ opengles.glClearColor(c_float(r), c_float(g), c_float(b), c_float(alpha)) opengles.glColorMask(1, 1, 1, int(alpha < 1.0))
def set_background(self, r, g, b, alpha): """Set the Display background. **NB the actual drawing of the background happens during the rendering of the framebuffer by the shader so if no draw() is done by anything during each Display loop the screen will remain black** If you want to see just the background you will have to draw() something out of view (i.e. behind) the Camera. *r, g, b* Color values for the display *alpha* Opacity of the color. An alpha of 0 means a transparent background, an alpha of 1 means full opaque. """ if alpha < 1.0 and (not self.opengl.use_glx) and (not PLATFORM == PLATFORM_PI): LOGGER.warning("create Display with (...use_glx=True) for transparent background on x11 window. libGLX needs to be available") opengles.glClearColor(GLclampf(r), GLclampf(g), GLclampf(b), GLclampf(alpha)) opengles.glColorMask(GLboolean(1), GLboolean(1), GLboolean(1), GLboolean(alpha < 1.0))
def create_display(self, x=0, y=0, w=0, h=0, depth=24, samples=4, layer=0, display_config=DISPLAY_CONFIG_DEFAULT, window_title='', use_glx=False): self.use_glx = use_glx and ( X_WINDOW and hasattr(glx, 'glXChooseFBConfig') ) # only use glx if x11 window and glx available self.display_config = display_config self.window_title = window_title.encode() if not self.use_glx: self.display = openegl.eglGetDisplay(EGL_DEFAULT_DISPLAY) assert self.display != EGL_NO_DISPLAY and self.display is not None for smpl in [ samples, 0 ]: # try with samples first but ANGLE dll can't cope so drop to 0 for windows r = openegl.eglInitialize(self.display, None, None) attribute_list = (EGLint * 19)( EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8, EGL_BLUE_SIZE, 8, EGL_DEPTH_SIZE, depth, EGL_ALPHA_SIZE, 8, EGL_BUFFER_SIZE, 32, EGL_SAMPLES, smpl, EGL_STENCIL_SIZE, 8, EGL_SURFACE_TYPE, EGL_WINDOW_BIT, EGL_NONE) numconfig = EGLint(0) poss_configs = (EGLConfig * 5)(*(EGLConfig() for _ in range(5))) r = openegl.eglChooseConfig(self.display, attribute_list, poss_configs, EGLint(len(poss_configs)), byref(numconfig)) context_attribs = (EGLint * 3)(EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE) if numconfig.value > 0: self.config = poss_configs[0] self.context = openegl.eglCreateContext( self.display, self.config, EGL_NO_CONTEXT, context_attribs) if self.context != EGL_NO_CONTEXT: break assert self.context != EGL_NO_CONTEXT and self.context is not None self.create_surface(x, y, w, h, layer) opengles.glDepthRangef(GLfloat(0.0), GLfloat(1.0)) opengles.glClearColor(GLfloat(0.3), GLfloat(0.3), GLfloat(0.7), GLfloat(1.0)) opengles.glBindFramebuffer(GL_FRAMEBUFFER, GLuint(0)) # get GL v GLES and version num for shader translation version = opengles.glGetString(GL_VERSION) version = ctypes.cast(version, c_char_p).value if b"ES" in version: for s in version.split(): if b'.' in s: self.gl_id = b"GLES" + s.split(b'.')[0] break #Setup default hints opengles.glEnable(GL_CULL_FACE) opengles.glCullFace(GL_BACK) opengles.glFrontFace(GL_CW) opengles.glEnable(GL_DEPTH_TEST) if b"GLES" not in self.gl_id: if b"2" in self.gl_id: opengles.glEnable(GL_VERTEX_PROGRAM_POINT_SIZE) else: opengles.glEnable(GL_PROGRAM_POINT_SIZE) # only in > GL3 opengles.glEnable(GL_POINT_SPRITE) opengles.glDepthFunc(GL_LESS) opengles.glDepthMask(GLboolean(True)) opengles.glHint(GL_GENERATE_MIPMAP_HINT, GL_NICEST) opengles.glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, 1, GL_ONE_MINUS_SRC_ALPHA) opengles.glColorMask(GLboolean(True), GLboolean(True), GLboolean(True), GLboolean(False)) #opengles.glEnableClientState(GL_VERTEX_ARRAY) #opengles.glEnableClientState(GL_NORMAL_ARRAY) self.max_texture_size = GLint(0) opengles.glGetIntegerv(GL_MAX_TEXTURE_SIZE, byref(self.max_texture_size)) self.active = True