def render(self, x, y, w=None, h=None, z=0.0, opacity=1.0): if w is None: w = self.w if h is None: h = self.h self.bind() fs_emu_texturing(True) if self.gl_type == gl.GL_RGBA or opacity < 1.0: fs_emu_blending(True) else: fs_emu_blending(False) gl.glBegin(gl.GL_QUADS) if opacity < 1.0: gl.glColor4f(opacity, opacity, opacity, opacity) else: gl.glColor3f(1.0, 1.0, 1.0) gl.glTexCoord(0.0, 1.0) gl.glVertex3f(x, y, z) gl.glTexCoord(1.0, 1.0) gl.glVertex3f(x + w, y, z) gl.glTexCoord(1.0, 0.0) gl.glVertex3f(x + w, y + h, z) gl.glTexCoord(0.0, 0.0) gl.glVertex3f(x, y + h, z) gl.glEnd()
def render_one(cls, notification): notification.show() w = 500 h = 100 x = START_X y = cls.y z = 0.9 y -= h gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor(1.0, 1.0, 0.5, 0.8) gl.glVertex3f(x, y, z) gl.glVertex3f(x + w, y, z) gl.glVertex3f(x + w, y + h, z) gl.glVertex3f(x, y + h, z) gl.glEnd() lines = notification.text.split("\n") y += h - 23 for line in lines: tw, th = Render.get().measure_text(line, cls.font) y -= th Render.get().text( line, cls.font, x + 23, y, color=(0.2, 0.2, 0.0, 1.0) ) y -= 2 # cls.y += h + 15 cls.y -= h + 20 gl.glEnable(gl.GL_DEPTH_TEST)
def render_one(cls, notification): notification.show() w = 500 h = 100 x = 1920 - w y = cls.y z = 0.9 fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor(1.0, 1.0, 0.5, 0.8) gl.glVertex3f(x, y, z) gl.glVertex3f(x + w, y, z) gl.glVertex3f(x + w, y + h, z) gl.glVertex3f(x, y + h, z) gl.glEnd() lines = notification.text.split("\n") y += h - 23 for line in lines: tw, th = Render.get().measure_text(line, cls.font) y -= th Render.get().text(line, cls.font, x + 23, y, color=(0.2, 0.2, 0.0, 1.0)) y -= 2 cls.y += h + 15
def render(self): Render.get().hd_perspective() if self.throbber_start_time == 0: self.throbber_start_time = State.get().time dt = State.get().time - self.throbber_start_time # run animation with 15 fps self.throbber_progress = int(dt * 15) bg_fade = (State.get().time - State.get().dialog_time) / 0.5 if bg_fade > 1.0: bg_fade = 1.0 elif bg_fade < 0.0: bg_fade = 0.0 fs_emu_texturing(False) fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDepthMask(False) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1020) gl.glVertex2f(0, 1020) gl.glEnd() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade * 0.5) gl.glVertex2f(0, 1020) gl.glVertex2f(1920, 1020) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() # y = 0.0 # tw, th = Render.get().text("LAUNCHING GAME", self.title_font, # 0.0, y, w=32 / 9, h=self.height, # color=(1.0, 1.0, 1.0, 1.0), halign=0.0) # fs_emu_blending(True) # if bg_fade > 0.5: # self.throbber_opacity = (bg_fade - 0.5) / 0.5 # #self.throbber_opacity = bg_fade # self.render_throbber() # if bg_fade == 1.0: if State.get().time - State.get().dialog_time > 1.0: # gradually show over 1/4 second self.throbber_opacity = ( State.get().time - State.get().dialog_time - 1.0) * 4 if self.throbber_opacity > 1.0: self.throbber_opacity = 1.0 self.render_throbber() gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(True) # fs_emu_texturing(1) # fs_emu_blending(0) # print("Setting dirty..") Render.get().dirty = True
def render(self): Render.get().hd_perspective() if self.throbber_start_time == 0: self.throbber_start_time = State.get().time dt = State.get().time - self.throbber_start_time # run animation with 15 fps self.throbber_progress = int(dt * 15) bg_fade = (State.get().time - State.get().dialog_time) / 0.5 if bg_fade > 1.0: bg_fade = 1.0 elif bg_fade < 0.0: bg_fade = 0.0 fs_emu_texturing(False) fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) gl.glDepthMask(False) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1020) gl.glVertex2f(0, 1020) gl.glEnd() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, bg_fade * 0.5) gl.glVertex2f(0, 1020) gl.glVertex2f(1920, 1020) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() # y = 0.0 # tw, th = Render.get().text("LAUNCHING GAME", self.title_font, # 0.0, y, w=32 / 9, h=self.height, # color=(1.0, 1.0, 1.0, 1.0), halign=0.0) # fs_emu_blending(True) # if bg_fade > 0.5: # self.throbber_opacity = (bg_fade - 0.5) / 0.5 # #self.throbber_opacity = bg_fade # self.render_throbber() # if bg_fade == 1.0: if State.get().time - State.get().dialog_time > 1.0: # gradually show over 1/4 second self.throbber_opacity = (State.get().time - State.get().dialog_time - 1.0) * 4 if self.throbber_opacity > 1.0: self.throbber_opacity = 1.0 self.render_throbber() gl.glEnable(gl.GL_DEPTH_TEST) gl.glDepthMask(True) # fs_emu_texturing(1) # fs_emu_blending(0) # print("Setting dirty..") Render.get().dirty = True
def render_cell(self, index, x, y): color = self.throbber_colors[(self.throbber_progress + index) % 8] color *= self.throbber_opacity gl.glColor4f(color, color, color, self.throbber_opacity) gl.glBegin(gl.GL_QUADS) gl.glVertex2f(x, y) gl.glVertex2f(x + 32, y) gl.glVertex2f(x + 32, y + 32) gl.glVertex2f(x, y + 32) gl.glEnd()
def texture_rectangle(x, y, w, h, z=0.0, s1=0.0, s2=1.0, t1=1.0, t2=0.0): gl.glBegin(gl.GL_QUADS) gl.glTexCoord(s1, t1) gl.glVertex3f(x, y, z) gl.glTexCoord(s2, t1) gl.glVertex3f(x + w, y, z) gl.glTexCoord(s2, t2) gl.glVertex3f(x + w, y + h, z) gl.glTexCoord(s1, t2) gl.glVertex3f(x, y + h, z) gl.glEnd()
def render_fade(r=0.0, g=0.0, b=0.0, a=0.0): Render.get().hd_perspective() fs_emu_blending(True) fs_emu_texturing(False) gl.glBegin(gl.GL_QUADS) gl.glColor4f(r * a, g * a, b * a, a) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd()
def render(self): z = -0.999 fs_emu_texturing(False) fs_emu_blending(False) gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.0, 0.0, 0.0) # glVertex3f(0, 365, z) # glVertex3f(1270, 365, z) gl.glVertex3f(0, 400, z) gl.glVertex3f(1270, 400, z) gl.glColor3f(0.25, 0.25, 0.25) gl.glVertex3f(1270, 1080 - 60, z) gl.glVertex3f(0, 1080 - 60, z) gl.glEnd()
def render_func(): render_screen() Render.get().ortho_perspective() fs_emu_blending(True) fs_emu_texturing(False) gl.glDisable(gl.GL_DEPTH_TEST) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, alpha) gl.glVertex2f(-10.0, -1.0) gl.glVertex2f(10.0, -1.0) gl.glVertex2f(10.0, 1.0) gl.glVertex2f(-10.0, 1.0) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST) # fs_emu_blending(False) fs_emu_texturing(True) swap_buffers() Render.get().dirty = True
def render_debug_square(): global debug_x Render.get().hd_perspective() fs_emu_texturing(False) gl.glBegin(gl.GL_QUADS) gl.glColor3f(1.0, 1.0, 1.0) x = debug_x debug_x += 1 if debug_x >= 1920: debug_x = 0 y = 989 z = 0.99 gl.glVertex3f(x, y, z) gl.glVertex3f(x + 20, y, z) gl.glVertex3f(x + 20, y + 20, z) gl.glVertex3f(x, y + 20, z) gl.glEnd() fs_emu_texturing(True)
def render_debug_square_2(): global debug_x_2 Render.get().hd_perspective() fs_emu_texturing(False) gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.2, 0.2, 0.2) x = debug_x_2 debug_x_2 += 1 if debug_x_2 >= 1920: debug_x_2 = 0 y = 989 + 5 z = 0.99 gl.glVertex3f(x, y, z) gl.glVertex3f(x + 20, y, z) gl.glVertex3f(x + 20, y + 10, z) gl.glVertex3f(x, y + 10, z) gl.glEnd() fs_emu_texturing(True)
def render_background(self): if self.background_texture: gl.glBindTexture(gl.GL_TEXTURE_2D, self.background_texture) gl.glColor3f(1.0, 1.0, 1.0) else: gl.glBindTexture(gl.GL_TEXTURE_2D, 0) # r, g, b a = self.background_color gl.glColor4f(*self.background_color) gl.glBegin(gl.GL_QUADS) bgx, bgy = self.background_texture_offset gl.glTexCoord(bgx + 0.0, bgy + 1.0) gl.glVertex2f(0, 0) gl.glTexCoord(bgx + 1.0, bgy + 1.0) gl.glVertex2f(self.width, 0) gl.glTexCoord(bgx + 1.0, bgy + 0.0) gl.glVertex2f(self.width, self.height) gl.glTexCoord(bgx + 0.0, bgy + 0.0) gl.glVertex2f(0, self.height) gl.glEnd()
def render_wall(): # brightness=1.0): # glClearColor(0.1, 0.1, 0.1, 1.0) # glClear(GL_DEPTH_BUFFER_BIT); Render.get().hd_perspective() # fs_emu_ortho(); # fs_emu_blending(FALSE); # fs_emu_texturing(FALSE); z = -0.999 # glPushMatrix() # glTranslate(0.0, 0.0, 1.0) # transition y-coordinate between floor and wall split = 361 fs_emu_blending(False) fs_emu_texturing(False) gl.glBegin(gl.GL_QUADS) gl.glColor3f(39.0 / 255.0, 44.0 / 255.0, 51.0 / 255.0) gl.glVertex3f(0, split, z) gl.glVertex3f(1920, split, z) color = 0 gl.glColor3f(color, color, color) gl.glVertex3f(1920, 1020, z) gl.glVertex3f(0, 1020, z) gl.glVertex3f(0, 1020, z) gl.glVertex3f(1920, 1020, z) gl.glVertex3f(1920, 1080, z) gl.glVertex3f(0, 1080, z) color = 0 gl.glColor3f(color, color, color) gl.glVertex3f(0, 0, z) gl.glVertex3f(1920, 0, z) gl.glColor3f(20.0 / 255.0, 22.0 / 255.0, 26.0 / 255.0) gl.glVertex3f(1920, split, z) gl.glVertex3f(0, split, z) gl.glEnd()
def render_wall(): # brightness=1.0): # glClearColor(0.1, 0.1, 0.1, 1.0) # glClear(GL_DEPTH_BUFFER_BIT); Render.get().hd_perspective() # fs_emu_ortho(); # fs_emu_blending(FALSE); # fs_emu_texturing(FALSE); z = -0.999 # glPushMatrix() # glTranslate(0.0, 0.0, 1.0) # transition y-coordinate between floor and wall splt = 361 fs_emu_blending(False) fs_emu_texturing(False) gl.glBegin(gl.GL_QUADS) gl.glColor3f(39.0 / 255.0, 44.0 / 255.0, 51.0 / 255.0) gl.glVertex3f(0, splt, z) gl.glVertex3f(1920, splt, z) color = 0 gl.glColor3f(color, color, color) gl.glVertex3f(1920, 1020, z) gl.glVertex3f(0, 1020, z) gl.glVertex3f(0, 1020, z) gl.glVertex3f(1920, 1020, z) gl.glVertex3f(1920, 1080, z) gl.glVertex3f(0, 1080, z) color = 0 gl.glColor3f(color, color, color) gl.glVertex3f(0, 0, z) gl.glVertex3f(1920, 0, z) gl.glColor3f(20.0 / 255.0, 22.0 / 255.0, 26.0 / 255.0) gl.glVertex3f(1920, splt, z) gl.glVertex3f(0, splt, z) gl.glEnd()
def render_item_gloss(alpha, ratio=1.0, brightness=1.0, area=None): if State.get().max_ratio: ratio = min(State.get().max_ratio, ratio) if State.get().force_portrait and ratio > 1.0: ratio = 1.0 / ratio ba = brightness * alpha gl.glColor4f(ba, ba, ba, alpha) fs_emu_blending(True) fs_emu_texturing(True) creating_list = DisplayLists.call_or_create("gloss", ratio) if not creating_list: return gl.glPolygonOffset(0.0, -4.0) gl.glEnable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(False) # glBindTexture(GL_TEXTURE_2D, Texture.gloss) texture = Texture.gloss texture.bind() area = area or 0.8 height = math.sqrt(area / ratio) width = ratio * height gl.glTranslatef(-width / 2.0, -0.5, 0.0) gl.glBegin(gl.GL_QUADS) gl.glTexCoord(0.0, 1.0) gl.glVertex3f(0.0, 0.0, 0.0) gl.glTexCoord(1.0, 1.0) gl.glVertex3f(width, 0.0, 0.0) gl.glTexCoord(1.0, 0.0) gl.glVertex3f(width, height, 0.0) gl.glTexCoord(0.0, 0.0) gl.glVertex3f(0.0, height, 0.0) gl.glEnd() gl.glPolygonOffset(0.0, 0.0) gl.glDisable(gl.GL_POLYGON_OFFSET_FILL) gl.glDepthMask(True) # fs_emu_blending(False) if creating_list: gl.glEndList()
def render_transparent(self, data): last_menu = State.get().history[-2] last_menu.render_transparent(self.last_menu_data) if Transition.value < 1.0: opacity = 1.0 - Transition.value opacity *= 1.25 if opacity > 1.0: opacity = 1.0 Render.get().hd_perspective() gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, opacity) gl.glVertex2f(0.0, 0.0) gl.glVertex2f(1920.0, 0.0) gl.glVertex2f(1920.0, 1020.0) gl.glVertex2f(0.0, 1020.0) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST) self.config_list.render(Transition.value)
def text(self, text, font, x, y, w=0, h=0, color=(1.0, 1.0, 1.0, 1.0), shadow=False, shadow_color=(0, 0, 0), halign=-1): if not text: return 0, 0 # if len(color) == 3: # color = (color[0], color[1], color[2], 1.0 try: alpha = color[3] except IndexError: alpha = 1.0 color = (int(round(color[0] * 255)), int(round(color[1] * 255)), int(round(color[2] * 255))) cache_key = (text, hash(font), font.size, color, alpha) try: self.text_cache_history.remove(cache_key) except ValueError: texture = None else: texture, txtsize = self.text_cache[cache_key] fs_emu_blending(True) fs_emu_texturing(True) gl.glDisable(gl.GL_DEPTH_TEST) if texture: gl.glBindTexture(gl.GL_TEXTURE_2D, texture) else: txtdata, txtsize = TextRenderer(font).render_text(text, color) texture = Render.get().create_texture() gl.glBindTexture(gl.GL_TEXTURE_2D, texture) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, txtsize[0], txtsize[1], 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, txtdata) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR) tw, th = (txtsize[0] * self.ortho_pscalex, txtsize[1] * self.ortho_pscaley) tx = x ty = y if w > 0: if tw > w: tw = w else: if halign == 0: tx += (w - tw) / 2 if h > 0: ty += (h - th) / 2 # ts = 4 / cls.display_height # Step # glDisable(GL_TEXTURE_RECTANGLE_ARB) # glTexEnv(GL_TEXTURE_2D, GL_MODULATE) # glDisable(GL_TEXTURE_RECTANGLE) # fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(alpha, alpha, alpha, alpha) gl.glTexCoord2f(0.0, 0.0) gl.glVertex2f(tx, ty + th) gl.glTexCoord2f(1.0, 0.0) gl.glVertex2f(tx + tw, ty + th) gl.glTexCoord2f(1.0, 1.0) gl.glVertex2f(tx + tw, ty) gl.glTexCoord2f(0.0, 1.0) gl.glVertex2f(tx, ty) # glRasterPos2f(tx, ty) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, GL_UNSIGNED_BYTE, # txtdata) gl.glEnd() # fs_emu_blending(False) gl.glEnable(gl.GL_DEPTH_TEST) self.text_cache_history.append(cache_key) self.text_cache[cache_key] = texture, txtsize if len(self.text_cache) > TEXT_CACHE_SIZE: cache_key = self.text_cache_history.pop(0) texture, txtsize = self.text_cache.pop(cache_key) Render.get().delete_texture_list.append(texture) # # FIXME: # shadow = False # # glDisable(GL_DEPTH_TEST) # fs_emu_blending(True) # #text = current_menu.selected_item.title # #if shadow: # txtdata, txtsize = TextRenderer(font).render_text(text, shadow_color) # tw, th = txtsize[0] * ortho_pscalex, txtsize[1] * ortho_pscaley # tx = x # ty = y # if w > 0: # tx = tx + (w - tw) / 2 # if h > 0: # ty = ty + (h - th) / 2 # #tx = 0 - tw / 2 # #ty = -0.67 # ts = 4 / State.get().display_height # Step # if shadow: # glPixelTransferf(GL_ALPHA_SCALE, 0.04) # for fx, fy in [(1, 1), (-1, -1), (1, -1), (-1, 1), (1, 0), (-1, # 0), # (0, -1), (0, 1)]: # glRasterPos2f(tx - fx * ts, ty - fy * ts) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, # GL_UNSIGNED_BYTE, # txtdata) # glPixelTransferf(GL_ALPHA_SCALE, 0.01) # for fx, fy in [(0, 2), (2, 0), (0, -2), (-2, 0), # (1, 2), (2, 1), (-1, 2), (-2, 1), (1, -2), # (2, -1), (-1, -2), (-2, -1)]: # glRasterPos2f(tx - fx * ts, ty - fy * ts) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, # GL_UNSIGNED_BYTE, # txtdata) # glPixelTransferf(GL_ALPHA_SCALE, alpha) # rendered = font.render(text, True, color) # txtsize = rendered.get_size() # txtdata = pygame.image.tostring(rendered, "RGBA", 1) # glRasterPos2f(tx, ty) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, GL_UNSIGNED_BYTE, # txtdata) # #glPopAttrib() # glPixelTransferf(GL_ALPHA_SCALE, 1.0) # fs_emu_blending(False) # glEnable(GL_DEPTH_TEST) return tw, th
def render_transparent(self, data): # print("GameMenu.render_transparent") last_menu = State.get().history[-2] last_menu.render_transparent(self.last_menu_data) if exit_transition.value < 1.0: opacity = 1.0 - exit_transition.value opacity *= 1.25 if opacity > 1.0: opacity = 1.0 Render.get().hd_perspective() gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, opacity) gl.glVertex2f(0.0, 0.0) gl.glVertex2f(1920.0, 0.0) gl.glVertex2f(1920.0, 1020.0) gl.glVertex2f(0.0, 1020.0) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST) alpha = enter_transition.value * 0.75 Render.get().hd_perspective() gl.glDisable(gl.GL_DEPTH_TEST) fs_emu_texturing(False) fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, alpha) # Covers, left gl.glVertex2f(0.0, 366.0) gl.glVertex2f(746.0, 366.0) gl.glVertex2f(746.0, 1020.0) gl.glVertex2f(0.0, 1020.0) # Covers, right gl.glVertex2f(1920.0 - 746.0, 366.0) gl.glVertex2f(1920.0, 366.0) gl.glVertex2f(1920.0, 1020.0) gl.glVertex2f(1920.0 - 746.0, 1020.0) # Bottom gl.glColor4f(0.0, 0.0, 0.0, 0.50) gl.glVertex2f(0.0, 0.0) gl.glVertex2f(1920.0, 0.0) gl.glVertex2f(1920.0, 366.0) gl.glVertex2f(0.0, 366.0) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST) transition = enter_transition.value if exit_transition.value < 1.0: # transition = exit_transition.value transition = 1.0 + 3.0 - exit_transition.value * 3.0 # print("render, transition = ", transition) self.config_list.render(transition) if exit_transition.value <= 0.0: exit_transition.value = 0.0 # finished = 1.0 exit_transition.start = 0 exit_transition.on_finish()
def render_content(self): Render.get().dirty = True # #x1 = -16 / 9 + 0.1 # x1 = 0.1 # #x2 = 16 / 9 - 0.1 # x2 = self.width - 0.1 # #y1 = 0.7 # #y2 = 0.9 # y1 = 1.6 # y2 = 1.9 x1 = 0 x2 = self.width y1 = 1.7 y2 = 2.0 w = 0.03 # t = (pygame.time.get_ticks() - self.start_time) // 1000 alert_color = (1.0, 0.8, 0.0) t = int((time.time() - self.start_time * 1.6)) if t % 2 == 0: gl.glBegin(gl.GL_QUADS) gl.glColor3f(*alert_color) gl.glVertex2f(x1, y1) gl.glVertex2f(x2, y1) gl.glVertex2f(x2, y2) gl.glVertex2f(x1, y2) gl.glColor3f(0.0, 0.0, 0.0) gl.glVertex2f(x1 + w, y1 + w) gl.glVertex2f(x2 - w, y1 + w) gl.glVertex2f(x2 - w, y2 - w) gl.glVertex2f(x1 + w, y2 - w) gl.glEnd() text = "Software Failure. Press BACKSPACE or back button to continue." Render.get().text(text, self.guru_font, 0.2, 1.85, color=alert_color) text = self.splitted[-1] text = "Guru Meditation #{0}".format(text) Render.get().text(text, self.guru_font, 0.2, 1.77, color=alert_color) x = 0.2 y = 0.15 tw, th = Render.get().measure_text("M", self.detail_font) y += th lines = [] max_line_size = 129 for line in self.splitted: line = line.rstrip() while len(line) > max_line_size: lines.append(line[:max_line_size]) line = line[max_line_size:] lines.append(line) for i, line in enumerate(reversed(lines)): if i == MAX_LINE: break s = (MAX_LINE - i) / MAX_LINE tw, th = Render.get().text( line, self.detail_font, x, y, color=(s, s, s, 1.0) ) y += th
def render(self, text, x, y, r=1.0, g=1.0, b=1.0, alpha=1.0): global text_cache if not text: return 0 # find cached text entry, if any for i, item in enumerate(text_cache): if item["text"] == text and item["font"] == self: text_cache.pop(i) break else: item = None if item: fs_emu_blending(True) fs_emu_texturing(True) w = item["w"] h = item["h"] gl.glBindTexture(gl.GL_TEXTURE_2D, item["texture"]) gl.glBegin(gl.GL_QUADS) gl.glColor4f(r * alpha, g * alpha, b * alpha, alpha) gl.glTexCoord2d(0.0, 0.0) gl.glVertex2d(x, y) gl.glTexCoord2d(1.0, 0.0) gl.glVertex2d(x + w, y) gl.glTexCoord2d(1.0, 1.0) gl.glVertex2d(x + w, y + h) gl.glTexCoord2d(0.0, 1.0) gl.glVertex2d(x, y + h) gl.glEnd() # re-insert item at front text_cache.insert(0, item) return w, h # calculate size of text required_width, required_height = self.measure(text) # setup fbo render_texture = gl.glGenTextures(1) gl.glBindTexture(gl.GL_TEXTURE_2D, render_texture) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, required_width, required_height, 0, gl.GL_RGBA, gl.GL_UNSIGNED_INT, None, ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_S, gl.GL_CLAMP_TO_EDGE ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_WRAP_T, gl.GL_CLAMP_TO_EDGE ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR ) # FIXME: Mipmapping? mip_mapping = 0 if mip_mapping: gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR_MIPMAP_LINEAR, ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_GENERATE_MIPMAP, gl.GL_TRUE ) gl.glGenerateMipmapEXT(gl.GL_TEXTURE_2D) else: gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR ) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) # Set up some renderbuffer state frame_buffer = gl.GLuint() gl.glGenFramebuffersEXT(1, frame_buffer) gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, frame_buffer) gl.glFramebufferTexture2DEXT( gl.GL_FRAMEBUFFER_EXT, gl.GL_COLOR_ATTACHMENT0_EXT, gl.GL_TEXTURE_2D, render_texture, 0, ) status = gl.glCheckFramebufferStatusEXT(gl.GL_FRAMEBUFFER_EXT) if status != gl.GL_FRAMEBUFFER_COMPLETE_EXT: print("glCheckFramebufferStatusEXT error", status) gl.glPushMatrix() gl.glLoadIdentity() gl.glPushAttrib(int(gl.GL_VIEWPORT_BIT) | int(gl.GL_ENABLE_BIT)) gl.glViewport(0, 0, required_width, required_height) gl.glMatrixMode(gl.GL_PROJECTION) gl.glPushMatrix() gl.glLoadIdentity() gl.gluOrtho2D(0, required_width, 0, required_height) gl.glClearColor(0.0, 0.0, 0.0, 0.0) gl.glClear(gl.GL_COLOR_BUFFER_BIT) gl.glEnable(gl.GL_BLEND) gl.glEnable(gl.GL_TEXTURE_2D) self.texture.bind() tw = self.texture.w th = self.texture.h gl.glBegin(gl.GL_QUADS) gl.glColor4f(1.0, 1.0, 1.0, 1.0) x2 = 0 h = self.h for ch in text: c = ord(ch) w = self.w[c] s1 = self.x[c] / tw s2 = (self.x[c] + w) / tw t1 = (self.y[c]) / th t2 = (self.y[c] + h) / th gl.glTexCoord2d(s1, t2) gl.glVertex2d(x2, 0) gl.glTexCoord2d(s2, t2) gl.glVertex2d(x2 + w, 0) gl.glTexCoord2d(s2, t1) gl.glVertex2d(x2 + w, h) gl.glTexCoord2d(s1, t1) gl.glVertex2d(x2, h) x2 += w gl.glEnd() gl.glPopMatrix() gl.glMatrixMode(gl.GL_MODELVIEW) gl.glPopAttrib() gl.glBindFramebufferEXT(gl.GL_FRAMEBUFFER_EXT, 0) gl.glPopMatrix() gl.glDeleteFramebuffersEXT(1, frame_buffer) if mip_mapping: gl.glBindTexture(gl.GL_TEXTURE_2D, render_texture) gl.glGenerateMipmapEXT(gl.GL_TEXTURE_2D) gl.glBindTexture(gl.GL_TEXTURE_2D, 0) new_item = { "font": self, "text": text, "w": required_width, "h": required_height, "texture": render_texture, } text_cache.insert(0, new_item) item = text_cache.pop() if item["texture"]: gl.glDeleteTextures([item["texture"]]) # now the text is in the cache, so call function again return self.render(text, x, y, r, g, b, alpha)
def render_item_shadow(ratio=1.0, brightness=1.0, area=None): if State.get().max_ratio: ratio = min(State.get().max_ratio, ratio) if State.get().force_portrait and ratio > 1.0: ratio = 1.0 / ratio gl.glColor4f(brightness, brightness, brightness, brightness) creating_list = DisplayLists.call_or_create("shadow", ratio, area) if not creating_list: return gl.glTranslatef(0.0, -0.5, 0.0) area = area or 0.8 height = math.sqrt(area / ratio) width = ratio * height wh = width / 2 t1 = 120 / 512 t2 = (512 - 120) / 512 gl.glBegin(gl.GL_QUADS) # left gl.glTexCoord(0.0, t2) gl.glVertex3f(-wh - 0.1, 0.02, 0.0) gl.glTexCoord(t1, t2) gl.glVertex3f(-wh + 0.02, 0.02, 0.0) gl.glTexCoord(t1, t1) gl.glVertex3f(-wh + 0.02, height - 0.02, 0.0) gl.glTexCoord(0.0, t1) gl.glVertex3f(-wh - 0.1, height - 0.02, 0.0) # top left gl.glTexCoord(0.0, t1) gl.glVertex3f(-wh - 0.1, height - 0.02, 0.0) gl.glTexCoord(t1, t1) gl.glVertex3f(-wh + 0.02, height - 0.02, 0.0) gl.glTexCoord(t1, 0.0) gl.glVertex3f(-wh + 0.02, height + 0.1, 0.0) gl.glTexCoord(0.0, 0.0) gl.glVertex3f(-wh - 0.1, height + 0.1, 0.0) # top gl.glTexCoord(t1, t1) gl.glVertex3f(-wh + 0.02, height - 0.02, 0.0) gl.glTexCoord(t2, t1) gl.glVertex3f(wh - 0.02, height - 0.02, 0.0) gl.glTexCoord(t2, 0.0) gl.glVertex3f(wh - 0.02, height + 0.1, 0.0) gl.glTexCoord(t1, 0.0) gl.glVertex3f(-wh + 0.02, height + 0.1, 0.0) # top right gl.glTexCoord(t2, t1) gl.glVertex3f(wh - 0.02, height - 0.02, 0.0) gl.glTexCoord(1.0, t1) gl.glVertex3f(wh + 0.1, height - 0.02, 0.0) gl.glTexCoord(1.0, 0.0) gl.glVertex3f(wh + 0.1, height + 0.1, 0.0) gl.glTexCoord(t2, 0.0) gl.glVertex3f(wh - 0.02, height + 0.1, 0.0) # right gl.glTexCoord(t2, t2) gl.glVertex3f(wh - 0.02, 0.02, 0.0) gl.glTexCoord(1.0, t2) gl.glVertex3f(wh + 0.1, 0.02, 0.0) gl.glTexCoord(1.0, t1) gl.glVertex3f(wh + 0.1, height - 0.02, 0.0) gl.glTexCoord(t2, t1) gl.glVertex3f(wh - 0.02, height - 0.02, 0.0) # bottom right gl.glTexCoord(t2, 1.0) gl.glVertex3f(wh - 0.02, -0.1, 0.0) gl.glTexCoord(1.0, 1.0) gl.glVertex3f(wh + 0.1, -0.1, 0.0) gl.glTexCoord(1.0, t2) gl.glVertex3f(wh + 0.1, 0.02, 0.0) gl.glTexCoord(t2, t2) gl.glVertex3f(wh - 0.02, 0.02, 0.0) # bottom gl.glTexCoord(t1, 1.0) gl.glVertex3f(-wh + 0.02, -0.1, 0.0) gl.glTexCoord(t2, 1.0) gl.glVertex3f(wh - 0.02, -0.1, 0.0) gl.glTexCoord(t2, t2) gl.glVertex3f(wh - 0.02, 0.02, 0.0) gl.glTexCoord(t1, t2) gl.glVertex3f(-wh + 0.02, 0.02, 0.0) # bottom left gl.glTexCoord(0.0, 1.0) gl.glVertex3f(-wh - 0.1, -0.1, 0.0) gl.glTexCoord(t1, 1.0) gl.glVertex3f(-wh + 0.02, -0.1, 0.0) gl.glTexCoord(t1, t2) gl.glVertex3f(-wh + 0.02, 0.02, 0.0) gl.glTexCoord(0.0, t2) gl.glVertex3f(-wh - 0.1, 0.02, 0.0) gl.glEnd() # end list if creating_list: gl.glEndList()
def render(self): if self.first_shown_at == 0: self.first_shown_at = State.get().time # FIXME: # from .gamemenu import render_wall, render_screen # glClear(GL_DEPTH_BUFFER_BIT) # render_wall() # render_screen() Render.get().hd_perspective() if len(self.controller.ports) == 0: color = (1.0, 0.0, 0.0, 1.0) text = "No input configuration needed" Render.get().text(text, Font.main_path_font, 200, 730, 400, color=color, halign=0) text = "Press enter or primary key to start game" Render.get().text(text, Font.main_path_font, 200, 670, 400, color=color, halign=0) return if self.device_list_version != InputDevices.device_list_version: print(" -- device list version changed") # self.devices, info = InputDevice.get_input_devices("", 0, 100, # version=2) self.devices = DeviceManager.instance().get_devices() self.device_list_version = InputDevices.device_list_version # [{"index": 0} for x in self.devices] device_ids = set() for device in self.devices: device_ids.add(device.id) try: self.device_data[device.id]["device"] = device except KeyError: print(" -- add device info for", device.id) self.device_data[device.id] = { "port": 0, "device": device} self.check_device(self.device_data[device.id]) for data_key in self.device_data.keys(): if not data_key in device_ids: print(" -- removing device_data for", data_key) del self.device_data[data_key] for input in self.controller.ports: if not input["device_id"] in device_ids: print(" -- removing device from input", input.device_id) input["device_id"] = None for port, input in enumerate(self.controller.ports): center_x = 400 + 400 * port text = input.name.upper() color = (1.0, 0.0, 0.0, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 760, 400, color=color, halign=0) text = input.description.upper() color = (1.0, 0.0, 0.0, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 730, 400, color=color, halign=0) if input.device_id: device = self.device_data[input.device_id]["device"] color = (1.0, 0.5, 0.5, 1.0) text = device.name.upper() Render.get().text(text, Font.main_path_font, center_x - 200, 680, 400, color=color, halign=0) for j, device in enumerate(self.devices): device_data = self.device_data[device.id] # print(1, repr(device)) if device_data["port"] != port: continue text = device.name.upper() if device_data["ok"]: color = (1.0, 1.0, 1.0, 1.0) else: color = (0.5, 0.5, 0.5, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 600 - j * 40, 400, color=color, halign=0) fade = 1.0 - (State.get().time - self.first_shown_at) * 3.0 if fade > 0.0: Render.get().dirty = True fs_emu_blending(True) fs_emu_texturing(False) gl.glDisable(gl.GL_DEPTH_TEST) Render.get().hd_perspective() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST)
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 item_top = 1080 - 90 item_left = 1920 - 560 + 40 item_left += Texture.sidebar_background_shadow.w * ( 1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h) gl.glDepthMask(True) gl.glPopMatrix() # x = x + 70 # w = w - 70 x = item_left y = item_top - 60 w = 560 - 40 - 40 h = 60 for i, item in enumerate(self.items): if item.group: if i > 0: # skip one half row before group heading y -= h / 2 selected = i == self.index and State.get().navigatable == self z = 0.71 fs_emu_texturing(False) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) gl.glVertex3f(x, y + 4, z) gl.glVertex3f(x + w, y + 4, z) gl.glVertex3f(x + w, y + h - 4, z) gl.glVertex3f(x, y + h - 4, z) # glColor3f(0.6, 0.6, 0.6) # glVertex3f(x, y + 4, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x + w, y + h, z) # glVertex3f(x, y + h, z) gl.glEnd() else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) if item.group: BitmapFont.menu_font.render( text, x + 20, y + 14, r=0.0, g=0x99 / 0xff, b=0xcc / 0xff) else: BitmapFont.menu_font.render(text, x + 20, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= h
def render(self, transition=1.0): Render.get().hd_perspective() # w = 560 # h = 92 # x = 1920 - w * transition # y = 1080 - 60 - h # y = 1080 - 60 - h - 44 # z = -0.9 item_top = 1080 - 90 item_left = 1920 - 560 + 40 item_left += Texture.sidebar_background_shadow.w * (1.0 - transition) gl.glPushMatrix() gl.glTranslate(0.0, 0.0, 0.7) # glTranslated((1.0 - transition) * g_tex_sidebar_background->width, # 0, 0) # fs_emu_set_texture(g_tex_sidebar_background) # fs_emu_render_texture_with_size(g_tex_sidebar_background, # 1920 - g_tex_sidebar_background->width, # 0, g_tex_sidebar_background->width, # g_tex_sidebar_background->height) # fs_emu_render_sidebar() fs_emu_blending(True) fs_emu_texturing(True) gl.glDepthMask(False) Texture.sidebar_background_shadow.render( 1920 - Texture.sidebar_background_shadow.w * transition, 0, Texture.sidebar_background_shadow.w, Texture.sidebar_background_shadow.h) gl.glDepthMask(True) gl.glPopMatrix() # x = x + 70 # w = w - 70 x = item_left y = item_top - 60 w = 560 - 40 - 40 h = 60 for i, item in enumerate(self.items): if item.group: if i > 0: # skip one half row before group heading y -= h / 2 selected = i == self.index and State.get().navigatable == self z = 0.71 fs_emu_texturing(False) if selected: fg_color = [1.0, 1.0, 1.0, 1.0] gl.glBegin(gl.GL_QUADS) gl.glColor3f(0.00, 0x99 / 0xff, 0xcc / 0xff) gl.glVertex3f(x, y + 4, z) gl.glVertex3f(x + w, y + 4, z) gl.glVertex3f(x + w, y + h - 4, z) gl.glVertex3f(x, y + h - 4, z) # glColor3f(0.6, 0.6, 0.6) # glVertex3f(x, y + 4, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x + w, y + h, z) # glVertex3f(x, y + h, z) gl.glEnd() else: fg_color = [1.0, 1.0, 1.0, 1.0] # glBegin(GL_QUADS) # glColor3f(0.4, 0.4, 0.4) # glVertex3f(x, y, z) # glVertex3f(x + w, y, z) # glVertex3f(x + w, y + 4, z) # glVertex3f(x, y + 4, z) # glEnd() # fs_emu_texturing(True) if i > 0: fg_color[3] *= 0.35 text = item.title # FIXME: REMOVE # fs_emu_blending(False) # fs_emu_blending(True) gl.glDisable(gl.GL_DEPTH_TEST) if item.group: BitmapFont.menu_font.render(text, x + 20, y + 14, r=0.0, g=0x99 / 0xff, b=0xcc / 0xff) else: BitmapFont.menu_font.render(text, x + 20, y + 14) gl.glEnable(gl.GL_DEPTH_TEST) # text = item.title.upper() # tw, th = Render.get().text(text, Font.main_path_font, # x + 40, y + 43, color=fg_color) # text = item.subtitle.upper() # fg_color[3] = fg_color[3] * 0.4 # text = item.title.upper() # tw, th = Render.get().text(text, Font.list_subtitle_font, # x + 40, y + 18, color=fg_color) y -= h
def text( self, text, font, x, y, w=0, h=0, color=(1.0, 1.0, 1.0, 1.0), shadow=False, shadow_color=(0, 0, 0), halign=-1, ): if not text: return 0, 0 # if len(color) == 3: # color = (color[0], color[1], color[2], 1.0 try: alpha = color[3] except IndexError: alpha = 1.0 color = ( int(round(color[0] * 255)), int(round(color[1] * 255)), int(round(color[2] * 255)), ) cache_key = (text, hash(font), font.size, color, alpha) try: self.text_cache_history.remove(cache_key) except ValueError: texture = None else: texture, txtsize = self.text_cache[cache_key] fs_emu_blending(True) fs_emu_texturing(True) gl.glDisable(gl.GL_DEPTH_TEST) if texture: gl.glBindTexture(gl.GL_TEXTURE_2D, texture) else: txtdata, txtsize = TextRenderer(font).render_text(text, color) texture = Render.get().create_texture() gl.glBindTexture(gl.GL_TEXTURE_2D, texture) gl.glTexImage2D( gl.GL_TEXTURE_2D, 0, gl.GL_RGBA, txtsize[0], txtsize[1], 0, gl.GL_BGRA, gl.GL_UNSIGNED_BYTE, txtdata, ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MIN_FILTER, gl.GL_LINEAR ) gl.glTexParameteri( gl.GL_TEXTURE_2D, gl.GL_TEXTURE_MAG_FILTER, gl.GL_LINEAR ) tw, th = ( txtsize[0] * self.ortho_pscalex, txtsize[1] * self.ortho_pscaley, ) tx = x ty = y if w > 0: if tw > w: tw = w else: if halign == 0: tx += (w - tw) / 2 if h > 0: ty += (h - th) / 2 # ts = 4 / cls.display_height # Step # glDisable(GL_TEXTURE_RECTANGLE_ARB) # glTexEnv(GL_TEXTURE_2D, GL_MODULATE) # glDisable(GL_TEXTURE_RECTANGLE) # fs_emu_blending(True) gl.glBegin(gl.GL_QUADS) gl.glColor4f(alpha, alpha, alpha, alpha) gl.glTexCoord2f(0.0, 0.0) gl.glVertex2f(tx, ty + th) gl.glTexCoord2f(1.0, 0.0) gl.glVertex2f(tx + tw, ty + th) gl.glTexCoord2f(1.0, 1.0) gl.glVertex2f(tx + tw, ty) gl.glTexCoord2f(0.0, 1.0) gl.glVertex2f(tx, ty) # glRasterPos2f(tx, ty) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, GL_UNSIGNED_BYTE, # txtdata) gl.glEnd() # fs_emu_blending(False) gl.glEnable(gl.GL_DEPTH_TEST) self.text_cache_history.append(cache_key) self.text_cache[cache_key] = texture, txtsize if len(self.text_cache) > TEXT_CACHE_SIZE: cache_key = self.text_cache_history.pop(0) texture, txtsize = self.text_cache.pop(cache_key) Render.get().delete_texture_list.append(texture) # # FIXME: # shadow = False # # glDisable(GL_DEPTH_TEST) # fs_emu_blending(True) # #text = current_menu.selected_item.title # #if shadow: # txtdata, txtsize = TextRenderer(font).render_text(text, shadow_color) # tw, th = txtsize[0] * ortho_pscalex, txtsize[1] * ortho_pscaley # tx = x # ty = y # if w > 0: # tx = tx + (w - tw) / 2 # if h > 0: # ty = ty + (h - th) / 2 # #tx = 0 - tw / 2 # #ty = -0.67 # ts = 4 / State.get().display_height # Step # if shadow: # glPixelTransferf(GL_ALPHA_SCALE, 0.04) # for fx, fy in [(1, 1), (-1, -1), (1, -1), (-1, 1), (1, 0), (-1, # 0), # (0, -1), (0, 1)]: # glRasterPos2f(tx - fx * ts, ty - fy * ts) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, # GL_UNSIGNED_BYTE, # txtdata) # glPixelTransferf(GL_ALPHA_SCALE, 0.01) # for fx, fy in [(0, 2), (2, 0), (0, -2), (-2, 0), # (1, 2), (2, 1), (-1, 2), (-2, 1), (1, -2), # (2, -1), (-1, -2), (-2, -1)]: # glRasterPos2f(tx - fx * ts, ty - fy * ts) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, # GL_UNSIGNED_BYTE, # txtdata) # glPixelTransferf(GL_ALPHA_SCALE, alpha) # rendered = font.render(text, True, color) # txtsize = rendered.get_size() # txtdata = pygame.image.tostring(rendered, "RGBA", 1) # glRasterPos2f(tx, ty) # glDrawPixels(txtsize[0], txtsize[1], GL_RGBA, GL_UNSIGNED_BYTE, # txtdata) # #glPopAttrib() # glPixelTransferf(GL_ALPHA_SCALE, 1.0) # fs_emu_blending(False) # glEnable(GL_DEPTH_TEST) return tw, th
def render(self): if self.first_shown_at == 0: self.first_shown_at = State.get().time # FIXME: # from .gamemenu import render_wall, render_screen # glClear(GL_DEPTH_BUFFER_BIT) # render_wall() # render_screen() Render.get().hd_perspective() if len(self.controller.ports) == 0: color = (1.0, 0.0, 0.0, 1.0) text = "No input configuration needed" Render.get().text(text, Font.main_path_font, 200, 730, 400, color=color, halign=0) text = "Press enter or primary key to start game" Render.get().text(text, Font.main_path_font, 200, 670, 400, color=color, halign=0) return if self.device_list_version != InputDevices.device_list_version: print(" -- device list version changed") # self.devices, info = InputDevice.get_input_devices("", 0, 100, # version=2) self.devices = DeviceManager.instance().get_devices() self.device_list_version = InputDevices.device_list_version # [{"index": 0} for x in self.devices] device_ids = set() for device in self.devices: device_ids.add(device.id) try: self.device_data[device.id]["device"] = device except KeyError: print(" -- add device info for", device.id) self.device_data[device.id] = {"port": 0, "device": device} self.check_device(self.device_data[device.id]) for data_key in self.device_data.keys(): if not data_key in device_ids: print(" -- removing device_data for", data_key) del self.device_data[data_key] for input in self.controller.ports: if not input["device_id"] in device_ids: print(" -- removing device from input", input.device_id) input["device_id"] = None for port, input in enumerate(self.controller.ports): center_x = 400 + 400 * port text = input.name.upper() color = (1.0, 0.0, 0.0, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 760, 400, color=color, halign=0) text = input.description.upper() color = (1.0, 0.0, 0.0, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 730, 400, color=color, halign=0) if input.device_id: device = self.device_data[input.device_id]["device"] color = (1.0, 0.5, 0.5, 1.0) text = device.name.upper() Render.get().text(text, Font.main_path_font, center_x - 200, 680, 400, color=color, halign=0) for j, device in enumerate(self.devices): device_data = self.device_data[device.id] # print(1, repr(device)) if device_data["port"] != port: continue text = device.name.upper() if device_data["ok"]: color = (1.0, 1.0, 1.0, 1.0) else: color = (0.5, 0.5, 0.5, 1.0) Render.get().text(text, Font.main_path_font, center_x - 200, 600 - j * 40, 400, color=color, halign=0) fade = 1.0 - (State.get().time - self.first_shown_at) * 3.0 if fade > 0.0: Render.get().dirty = True fs_emu_blending(True) fs_emu_texturing(False) gl.glDisable(gl.GL_DEPTH_TEST) Render.get().hd_perspective() gl.glBegin(gl.GL_QUADS) gl.glColor4f(0.0, 0.0, 0.0, fade) gl.glVertex2f(0, 0) gl.glVertex2f(1920, 0) gl.glVertex2f(1920, 1080) gl.glVertex2f(0, 1080) gl.glEnd() gl.glEnable(gl.GL_DEPTH_TEST)