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 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 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_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_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_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 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): 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): 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_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 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)
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