def main(): global gl global test_model # Initialize the library if not glfwInit(): sys.exit() # Initilize GL gl = pygloo.init() if not gl: sys.exit() # Create a windowed mode window and its OpenGL context window = glfwCreateWindow(640, 480, "Hello World", None, None) if not window: glfwTerminate() sys.exit() # Make the window's context current glfwMakeContextCurrent(window) # Install a input handlers glfwSetKeyCallback(window, on_key) glfwSetMouseButtonCallback(window, on_mouse) glfwSetCursorPosCallback(window, on_mouse_move) glfwSetScrollCallback(window, on_scroll) # Load an obj # test_model = Geometry.from_OBJ(gl, "assets/sphere.obj") # Loop until the user closes the window while not glfwWindowShouldClose(window): # Render width, height = glfwGetFramebufferSize(window) gl.glViewport(0, 0, width, height) gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0) gl.glClearColor(1.0, 1.0, 1.0, 1.0) # white gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) gl.glEnable(GL_DEPTH_TEST) # gl.glDepthFunc(GL_LESS); gl.glDepthFunc(GL_LEQUAL) # Render # render(width, height) # Poll for and process events glfwPollEvents() # Swap front and back buffers glfwSwapBuffers(window) glfwTerminate()
def main(): global gl global test_model # Initialize the library if not glfwInit(): sys.exit() # Initilize GL gl = pygloo.init() if not gl: sys.exit() # Create a windowed mode window and its OpenGL context window = glfwCreateWindow(640, 480, "Hello World", None, None) if not window: glfwTerminate() sys.exit() # Make the window's context current glfwMakeContextCurrent(window) # Install a input handlers glfwSetKeyCallback(window, on_key) glfwSetMouseButtonCallback(window, on_mouse) glfwSetCursorPosCallback(window, on_mouse_move) glfwSetScrollCallback(window, on_scroll) # Load an obj # test_model = Geometry.from_OBJ(gl, "assets/sphere.obj") # Loop until the user closes the window while not glfwWindowShouldClose(window): # Render width, height = glfwGetFramebufferSize(window) gl.glViewport(0, 0, width, height) gl.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0); gl.glClearColor(1.0, 1.0, 1.0, 1.0) # white gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT) gl.glEnable(GL_DEPTH_TEST); # gl.glDepthFunc(GL_LESS); gl.glDepthFunc(GL_LEQUAL); # Render # render(width, height) # Poll for and process events glfwPollEvents() # Swap front and back buffers glfwSwapBuffers(window) glfwTerminate()
def run(): width = 1280 height = 1024 tick = 16 #milliseconds # Initilise pyGame and create window # pygame.init() clock = pygame.time.Clock() screen = pygame.display.set_mode((width, height), HWSURFACE|OPENGL|DOUBLEBUF|RESIZABLE) global gl gl = pygloo.init() gl._begin = True # Load geometry # ArcadeGame.Assets.load_inst_geometry(gl, "bullet", "Assets/Projectiles/ArrowHead.obj") ArcadeGame.Assets.load_inst_geometry(gl, "mine", "Assets/Mine/Mine.obj") ArcadeGame.Assets.load_inst_geometry(gl, "minesphere", "Assets/Mine/Sphere.obj") ArcadeGame.Assets.load_inst_geometry(gl, "asteroid1", "Assets/Asteroids/Asteroid1.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid2", "Assets/Asteroids/Asteroid2.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid3", "Assets/Asteroids/Asteroid3.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid4", "Assets/Asteroids/Asteroid4.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid5", "Assets/Asteroids/Asteroid5.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid6", "Assets/Asteroids/Asteroid6.obj", center=True) ArcadeGame.Assets.load_inst_geometry(gl, "asteroid7", "Assets/Asteroids/Asteroid7.obj", center=True) ArcadeGame.Assets.load_geometry(gl, "ship", "Assets/Ship/SHIP.obj") ArcadeGame.Assets.load_geometry(gl, "enemyship", "Assets/EnemyShip/EnemyShip.obj") ArcadeGame.Assets.load_inst_geometry(gl, "sphere", "Assets/Debug/Sphere/sphere.obj") # Load shader # ArcadeGame.Assets.load_shader(gl, "bullet", open("Assets/Shaders/bullet_shader.glsl").read()) ArcadeGame.Assets.load_shader(gl, "mine", open("Assets/Shaders/mine_shader.glsl").read(), shader_types=[GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER]) ArcadeGame.Assets.load_shader(gl, "asteroid", open("Assets/Shaders/asteroid_shader.glsl").read()) ArcadeGame.Assets.load_shader(gl, "ship", open("Assets/Shaders/default_shader.glsl").read(), shader_types=[GL_VERTEX_SHADER, GL_GEOMETRY_SHADER, GL_FRAGMENT_SHADER]) ArcadeGame.Assets.load_shader(gl, "sphere", open("Assets/Shaders/red_sphere_shader.glsl").read()) # Load Sound # ArcadeGame.Assets.load_sound("hitbybullet", "Assets/Audio/Effects/HitByBullet.wav") ArcadeGame.Assets.load_sound("hitbymine", "Assets/Audio/Effects/HitByMine.wav") ArcadeGame.Assets.load_sound("minedrop", "Assets/Audio/Effects/MineDrop.wav") ArcadeGame.Assets.load_sound("laser", "Assets/Audio/Effects/Laser.wav") ArcadeGame.Assets.load_sound("explosion1", "Assets/Audio/Effects/Explosion1.wav") ArcadeGame.Assets.load_sound("explosion2", "Assets/Audio/Effects/Explosion2.wav") ArcadeGame.Assets.load_sound("explosion3", "Assets/Audio/Effects/Explosion3.wav") ArcadeGame.Assets.load_sound("explosion4", "Assets/Audio/Effects/Explosion4.wav") ArcadeGame.Assets.load_sound("explosion5", "Assets/Audio/Effects/Explosion5.wav") ArcadeGame.Assets.load_sound("gameover", "Assets/Audio/Effects/GameOver.wav") #Load Music # ArcadeGame.Assets.load_music("music1", "Assets/Audio/Music/Music1.wav") global game game = ArcadeMenuState() global asciirenderer asciirenderer = ascii.AsciiRenderer(gl) old_time = clock.tick() # Create an input object (testing) # cont = Controller() # Enter game loop # while True: for event in pygame.event.get(): if event.type == QUIT: return if event.type == KEYUP and event.key == K_ESCAPE: return if event.type == VIDEORESIZE: width, height = event.size # this destroys and recreates the GL context on windows; undesirable if os.name != 'nt': screen = pygame.display.set_mode((width, height), HWSURFACE|OPENGL|DOUBLEBUF|RESIZABLE) if event.type == KEYDOWN: if event.key == K_BACKSPACE: global render render = { render_normal : render_ascii, render_ascii : render_normal }[render] # } # } # } # Get key presses and update # cont.tick() ngame = game.tick(cont) if ngame: game = ngame # Render # if width > 0 and height > 0: render(width, height) # Flip the double buffer # pygame.display.flip() # Update the clock to keep constant time # new_time = clock.tick() if old_time + tick > new_time: pygame.time.wait(new_time - (old_time + tick)) old_time = new_time