def engine_init(): global al, channel try: gs.LoadPlugins(gs.get_default_plugins_path()) except: pass render.init(demo_screen_size[0], demo_screen_size[1], "pkg.core") # mount the system file driver gs.MountFileDriver(gs.StdFileDriver("assets/"), "@assets/") al = None channel = None
def engine_init(): global al, channel, plus try: gs.LoadPlugins(gs.get_default_plugins_path()) except: pass plus = gs.GetPlus() plus.RenderInit(demo_screen_size[0], demo_screen_size[1], 1, demo_screen_size[2]) # mount the system file driver gs.MountFileDriver(gs.StdFileDriver("assets/"), "@assets/") al = None channel = None
import gs import gs.plus import gs.plus.render as render import gs.plus.camera as camera import gs.plus.input as input import gs.plus.scene as scene import gs.plus.clock as clock from math import pi, cos, sin, asin import codecs filename_out = "../src/simulation" scale_factor = 5.0 gs.plus.create_workers() gs.LoadPlugins(gs.get_default_plugins_path()) render.init(1280, 720, "../pkg.core") scn = scene.new_scene() cam = scene.add_camera(scn, gs.Matrix4.TranslationMatrix(gs.Vector3(0, 3.5, -12.5))) cam.GetTransform().SetRotation( gs.Vector3(pi * 5.0 / 180.0, pi * -5.0 / 180.0, 0)) scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.65, -0.45, 0)), gs.Light.Model_Linear, 150) scene.add_light(scn, gs.Matrix4.RotationMatrix(gs.Vector3(0.55, pi, 0.2)), gs.Light.Model_Linear, diffuse=gs.Color(0.3, 0.3, 0.4)) scene.add_physic_plane(scn)
import gs from project import ProjectHandler plus = gs.GetPlus() plus.CreateWorkers() plus.RenderInit(1280, 720) gs.MountFileDriver(gs.StdFileDriver()) gs.LoadPlugins() project = ProjectHandler(plus) project.OnSetup() # scn = plus.NewScene() # cam = plus.AddCamera(scn, gs.Matrix4.TranslationMatrix((0, 1, -10))) # scn.Load("assets/master_scene/master_scene.scn", gs.SceneLoadContext(plus.GetRenderSystem())) # fps = gs.FPSController(0, 2, -10) while not plus.IsAppEnded(): dt = plus.UpdateClock() project.OnUpdate(dt) # fps.UpdateAndApplyToNode(cam, dt) # plus.UpdateScene(scn, dt) # g_plus.Text2D(5, 5, "Move around with QSZD, left mouse button to look around") plus.Flip()
def main(): pc_screen_windowed = True pc_screen_width = 1280 pc_screen_height = 720 plus = gs.GetPlus() plus.CreateWorkers() DemoSimulation.print_ascii_intro(None) if getattr(sys, 'frozen', False): # frozen dir_ = dirname(sys.executable) else: # unfrozen dir_ = dirname(realpath(__file__)) window_mode = pymsgbox.confirm(text='Select your screen mode', title='System Zoetrope', buttons=['Windowed', 'Fullscreen']) if window_mode == 'Windowed': pc_screen_windowed = True screen_resolutions = ['640x480', '720x568', '800x600', '1280x800'] elif window_mode == 'Fullscreen': pc_screen_windowed = False screen_resolutions = [ '640x480', '800x600', '1280x720', '1280x800', '1920x1080' ] else: return False screen_res = pymsgbox.confirm(text='Select your screen resolution', title='System Zoetrope', buttons=screen_resolutions) if screen_res is not None: pc_screen_width = int(screen_res.split('x')[0]) pc_screen_height = int(screen_res.split('x')[1]) else: return False demo_screen_width = 720 // 2 demo_screen_height = 568 // 2 amiga_screen_ratio = demo_screen_height / demo_screen_width overscan_factor = gs.Vector4( 16 / demo_screen_width, 4 / demo_screen_height, (demo_screen_width - 16) / demo_screen_width, (demo_screen_height - 28) / demo_screen_height) # in pixels if pc_screen_windowed: pc_screen_width = int(pc_screen_height * (demo_screen_width / demo_screen_height)) # mount the system file driver # gs.GetFilesystem().Mount(gs.StdFileDriver("pkg.core"), "@core") gs.MountFileDriver(gs.StdFileDriver()) gs.LoadPlugins(gs.get_default_plugins_path()) # create the renderer and render system if pc_screen_windowed: w_mode = gs.Window.Windowed else: w_mode = gs.Window.Fullscreen plus.RenderInit(pc_screen_width, pc_screen_height, 1, w_mode) egl = plus.GetRendererAsync() # create the font object font = gs.RasterFont("@core/fonts/default.ttf", 48, 512) # Init demo simulation demo = DemoSimulation(demo_screen_width, demo_screen_height) # # load a simple 2d shader outputting a single color # shader = egl.LoadShader("res/shader_2d_single_texture.isl") # # # Create index buffer # data = gs.BinaryBlob() # data.WriteShorts([0, 1, 2, 0, 2, 3]) # # idx = egl.NewBuffer() # egl.CreateBuffer(idx, data, gs.GpuBuffer.Index) # # # Create vertex buffer # # Create vertex buffer # vtx_layout = gs.VertexLayout() # vtx_layout.AddAttribute(gs.VertexAttribute.Position, 3, gs.VertexFloat) # vtx_layout.AddAttribute(gs.VertexAttribute.UV0, 2, gs.VertexUByte, True) # UVs are sent as normalized 8 bit unsigned integer (range [0;255]) # # def custom_uv(u, v): # return [int(Clamp(u, 0, 1) * 255), int(Clamp(v, 0, 1) * 255)] # # data = gs.BinaryBlob() # x, y = 1, 1 # data.WriteFloats([-x, -y, 0.5]) # data.WriteUnsignedBytes(custom_uv(overscan_factor.x, overscan_factor.w)) # data.WriteFloats([-x, y, 0.5]) # data.WriteUnsignedBytes(custom_uv(overscan_factor.x, overscan_factor.y)) # data.WriteFloats([x, y, 0.5]) # data.WriteUnsignedBytes(custom_uv(overscan_factor.z, overscan_factor.y)) # data.WriteFloats([x, -y, 0.5]) # data.WriteUnsignedBytes(custom_uv(overscan_factor.z, overscan_factor.w)) # # vtx = egl.NewBuffer() # egl.CreateBuffer(vtx, data, gs.GpuBuffer.Vertex) # demo bitmaps demo.load_textures() demo_screen_tex = egl.NewTexture("demo_screen_texture") res = egl.CreateTexture(demo_screen_tex, demo.screen_pic) print("CreateTexture() returned ", res) # play music al = gs.MixerAsync(gs.ALMixer()) al.Open() channel_state = gs.MixerChannelState(0, 1, gs.MixerRepeat) al.Stream("res/music_loop.ogg", channel_state) mode_switch = "DMODE_SW_UBOB" while not plus.IsAppEnded( plus.EndOnDefaultWindowClosed) and not plus.KeyPress( gs.InputDevice.KeyEscape): dt = plus.UpdateClock() plus.Clear() # Demo simulation (re-creation) demo.update_dt(dt.to_sec()) demo.clear_screen() demo.draw_pixel_art_logo() demo.draw_checkerboard() if mode_switch == "DMODE_SW_UBOB": if not demo.draw_unlimited_bobs(): if demo.figure_mode % 2 == 0: mode_switch = "DMODE_SW_CLEAR_FROM_TOP" else: mode_switch = "DMODE_SW_CLEAR_FROM_BOTTOM" elif mode_switch == "DMODE_SW_CLEAR_FROM_TOP": if demo.clear_playfield(True): mode_switch = "DMODE_SW_NEXT_UBOB" elif mode_switch == "DMODE_SW_CLEAR_FROM_BOTTOM": if demo.clear_playfield(False): mode_switch = "DMODE_SW_NEXT_UBOB" elif mode_switch == "DMODE_SW_NEXT_UBOB": demo.set_next_unlimited_bobs() mode_switch = "DMODE_SW_UBOB" demo.render_demo_text() egl.BlitTexture(demo_screen_tex, gs.BinaryBlobFromByteArray(demo.screen_pic.GetData()), demo_screen_width, demo_screen_height) if pc_screen_windowed: # egl.SetShader(shader) # egl.SetShaderTexture("u_tex", demo_screen_tex) # egl.DrawBuffers(6, idx, vtx, vtx_layout) plus.Quad2D(0, 0, 0, pc_screen_height, pc_screen_width, pc_screen_height, pc_screen_width, 0, gs.Color.White, gs.Color.White, gs.Color.White, gs.Color.White, demo_screen_tex, overscan_factor.x, overscan_factor.y, overscan_factor.z, overscan_factor.w) else: _x_offset = (pc_screen_width - pc_screen_width * amiga_screen_ratio) * 0.5 plus.Quad2D(_x_offset, 0, _x_offset, pc_screen_height, _x_offset + (pc_screen_width * amiga_screen_ratio), pc_screen_height, _x_offset + (pc_screen_width * amiga_screen_ratio), 0, gs.Color.White, gs.Color.White, gs.Color.White, gs.Color.White, demo_screen_tex, overscan_factor.x, overscan_factor.y, overscan_factor.z, overscan_factor.w) plus.Flip()