示例#1
0
	def __init__(self, title='', fps=60, fullscreen=False, size=(800, 600), offset=(0, 0)):
		self.title = title
		self.fps = fps
		self.fullscreen = fullscreen
		self.size = size
		self.width, self.height = offset

		self.delta = 0
		self.currentFrame = self.get_time()
		self.lastFrame = self.get_time()
		if self.fullscreen:
			self.surface = pygame.display.set_mode(self.size, FULLSCREEN | HWSURFACE | DOUBLEBUF | OPENGL)
		else:
			self.surface = pygame.display.set_mode(self.size, DOUBLEBUF | OPENGL)

		pygame.display.set_caption(self.title)
		ratio = (self.width ** 2 + self.height ** 2) / 325
		glClearColor(0.83137254902, 0.83137254902, 0.83137254902, 1)
		gluPerspective(60, (size[0] / size[1]), 0.1, 1000.0)
		gluLookAt(0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0)
		gluLookAt(4 * ratio, 4 * ratio, 8 * ratio, 0, 0, 0, 0, 0, 1)

		glRotatef(135, 0, 0, 1)
		glRotatef(5, 0, 0, 1)
		glTranslatef(-self.width / 2, self.height / 2 + 1, 0)
		glEnable(GL_DEPTH_TEST)
		glEnable(GL_LINE_SMOOTH)
		glEnable(GL_POLYGON_SMOOTH)
		glHint(GL_LINE_SMOOTH_HINT, GL_NICEST)
		glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST)
		glEnable(GL_BLEND)
		glLineWidth(1)
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)
示例#2
0
def init():
    glEnable(GL_DEPTH_TEST) #enable the Z buffer
    glClearColor(1.0, 1.0, 1.0, 1.0) #clear color, which is the color of the parts of the screen that aren’t drawn to, color value: 0 - 1.0
    glShadeModel(GL_FLAT)
    glEnable(GL_COLOR_MATERIAL)
    glEnable(GL_LIGHTING)
    glEnable(GL_LIGHT0)
    glLight(GL_LIGHT0, GL_POSITION, (0, 1, 1, 0))
示例#3
0
def main():
    if not glfw.init():
        return -1

    glfw.window_hint(glfw.CONTEXT_VERSION_MAJOR, 4)
    glfw.window_hint(glfw.CONTEXT_VERSION_MINOR, 3)
    glfw.window_hint(glfw.OPENGL_PROFILE, glfw.OPENGL_CORE_PROFILE)

    window  = glfw.create_window(960, 540, "Window", None, None)

    if not window:
        glfw.terminate()
        return -1

    glfw.make_context_current(window)
    glfw.swap_interval(1)
    version = glGetString(GL_VERSION).decode('utf-8')
    print(version)

    glEnable(GL_BLEND)
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

    renderer = Renderer.Renderer()

    gui = Gui.Gui(window)

    testMenu = Test.TestMenu()
    testMenu.RegisterTest("Clear Color", TestClearColor.TestClearColor)
    testMenu.RegisterTest("Texture2D", TestTexture2D.TestTexture2D)
    currentTest = testMenu

    while not glfw.window_should_close(window):
        glClearColor(0.0, 0.0, 0.0, 1.0)
        renderer.Clear()
        gui.NewFrame()
        if currentTest:
            currentTest.OnUpdate()
            currentTest.OnRender()
            Gui.begin("Tests")
            if not currentTest == testMenu and Gui.button("<-"):
                currentTest = testMenu
                testMenu.m_CurrentTest = None
            currentTest.OnImGuiRender()
            if testMenu.m_CurrentTest and not (currentTest == testMenu.m_CurrentTest):
                currentTest = testMenu.m_CurrentTest
            Gui.end()
        Gui.framerate()
        gui.EndFrame()
        glfw.swap_buffers(window)
        glfw.poll_events()
    del currentTest
    del testMenu
    gui.endGui()
    glfw.terminate()

    return 0
示例#4
0
 def update(self):
     # init render
     glClearColor(*self.clear_color)
     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
     # in render
     for renderer in self.renderers:
         if not renderer.is_initialized:
             renderer.initialize()
             renderer.is_initialized = True
         renderer.on_render()
         self.draw_array(renderer.vao)
     # fini render
     pass  # import glfw
     pass  # glfw.swap_buffers(G.appm.window_handle)
示例#5
0
    def initializeGL(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glShadeModel(GL_SMOOTH)

        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glEnable(GL_ALPHA_TEST)
        glAlphaFunc(GL_NOTEQUAL, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        glOrtho(-50.0, 50.0, -50.0, 50.0, -1, 1)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.myNave = Nave(self.animation_propellant_enemy, self.player_x)
        self.in_scene.append(self.myNave)

        self.myNave2 = Nave(self.animation_propellant_enemy, self.player2_x)
        self.in_scene.append(self.myNave2)

        self.imageID_back = self.loadImage("img/Background.png")

        for i in range(EXPLOSION_FRAMES):
            self.animation_explosion[i] = self.loadImage("img/explosion/Comp" +
                                                         str(i) + ".png")

        for i in range(PROPELLANT_FRAMES):
            self.animation_propellant_enemy[i] = self.loadImage(
                "img/fire/Comp" + str(i) + ".png")

        self.img_nave_amarela = self.loadImage("img/nave4.png")
        self.img_nave_azul = self.loadImage("img/nave1.png")
        self.img_nave_preta = self.loadImage("img/nave3.png")
        self.img_tiro_amarelo = self.loadImage("img/nave4_pow.png")
        self.img_tiro_preto = self.loadImage("img/nave3_pow.png")
        self.img_tiro_azul = self.loadImage("img/nave1_pow.png")
        self.img_tiro = self.loadImage("img/nave2_pow.png")
        self.logo_init = self.loadImage("img/SpaceCute.png")
        self.logo_end = self.loadImage("img/YouDied.png")

        self.myLogo_i.load("inicio", self.logo_init, self.logo_end)
        self.ornaments.append(self.myLogo_i)
        self.myLogo_i.inited = True

        self.myLogo_e.load("fim", self.logo_init, self.logo_end)

        self.init_queue()
示例#6
0
    def show(self, clear_color=(.2, .3, .3, 1), clear=gl.GL_COLOR_BUFFER_BIT):
        """
        Run entering a blocking main loop
        """

        start_time = time.time()
        current_time = start_time
        prev_time = start_time
        frame_time = 0

        while not self.is_closing:
            current_time, prev_time = time.time(), current_time
            frame_time = max(current_time - prev_time, 1 / 1000)
            glClear(clear)
            glClearColor(*clear_color)

            self.on_input(self.window)
            self.on_draw(current_time - start_time, frame_time)
            self.swap_buffers()

        duration = time.time() - start_time
        self.destroy()
        print("Duration: {0:.2f}s @ {1:.2f} FPS".format(
            duration, self.frames / duration))
示例#7
0
    def initializeGL(self):
        glClearColor(0.0, 0.0, 0.0, 0.0)
        glShadeModel(GL_SMOOTH)
        glEnable(GL_DEPTH_TEST)
        glEnable(GL_BLEND)
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)

        glEnable(GL_ALPHA_TEST)
        glAlphaFunc(GL_NOTEQUAL, 0.0)

        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()

        gluPerspective(45, 1.65, 0.1, 500)
        gluLookAt(0, -100, 50, 0, 0, 0, 0, 1, 0)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        self.myNave = Nave(self.animation_propellant_enemy, 0)
        self.in_scene.append(self.myNave)

        for i in range(EXPLOSION_FRAMES):
            self.animation_explosion[i] = self.loadImage("img/explosion/Comp" +
                                                         str(i) + ".png")

        for i in range(PROPELLANT_FRAMES):
            self.animation_propellant_enemy[i] = self.loadImage(
                "img/fire/Comp" + str(i) + ".png")

        for i in range(10):
            self.img_planets[i] = self.loadImage("img/planets/planeta" +
                                                 str(i) + ".png")

        self.img_nave_amarela = self.loadImage("img/nave4.png")
        self.img_nave_azul = self.loadImage("img/nave1.png")
        self.img_nave_preta = self.loadImage("img/nave3.png")
        self.img_tiro_amarelo = self.loadImage("img/nave4_pow.png")
        self.img_tiro_preto = self.loadImage("img/nave3_pow.png")
        self.img_tiro_azul = self.loadImage("img/nave1_pow.png")
        self.img_tiro = self.loadImage("img/nave2_pow.png")
        self.logo_init = self.loadImage("img/SpaceCute.png")
        self.logo_end = self.loadImage("img/YouDied.png")
        self.power_up_vida = self.loadImage("img/power_up_life.png")
        self.power_up_shoot = self.loadImage("img/power_up_shot.png")
        self.power_up_speed = self.loadImage("img/power_up_speed.png")

        self.myLogo_i.load("inicio", self.logo_init, self.logo_end)
        self.ornaments.append(self.myLogo_i)
        self.myLogo_i.inited = True

        self.myLogo_e.load("fim", self.logo_init, self.logo_end)

        self.init_queue()

        # Arrumando erros de frict
        fix_p = self.propellant_queue.pop()
        fix_p.load(self.animation_propellant_enemy, 1000, 1000, "fix")
        self.ornaments.append(fix_p)

        new_explosion = self.explosion_queue.pop()
        new_explosion.load(self.animation_explosion, 1000, 1000, "fix")
        self.ornaments.append(new_explosion)

        tx = 0
        ambiente = [0.2, 0.2, 0.2, 1.0]
        difusa = [0.7, 0.7, 0.7, 1.0]
        especular = [1.0, 1.0, 1.0, 1.0]
        posicao = [0.0, 3.0, 2.0, 0.0]
        lmodelo_ambiente = [0.2, 0.2, 0.2, 1.0]

        glLightfv(GL_LIGHT0, GL_AMBIENT, ambiente)
        glLightfv(GL_LIGHT0, GL_DIFFUSE, difusa)
        glLightfv(GL_LIGHT0, GL_POSITION, posicao)
        glLightfv(GL_LIGHT0, GL_SPECULAR, especular)
        glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodelo_ambiente)
        glEnable(GL_LIGHTING)
        glEnable(GL_LIGHT0)
        glEnable(GL_COLOR_MATERIAL)
示例#8
0
 def initializeGL(self):
     glClearColor(0.0, 0.0, 1.0, 0.0)
     glClearDepth(1.0)