Beispiel #1
0
import glm
from pygame.locals import *
from gl import Renderer, Model
import shaders



deltaTime = 0.0

pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)


renderer = Renderer(screen)
renderer.camPosition.z = 3
renderer.pointLight.x = 5
#renderer.pointLight.x = -5

renderer.setShaders(shaders.vertex_shader, shaders.fragment_shader)


barrel = Model('models/barrel/barrel.obj', 'models/barrel/barrel.bmp')
barrel.scale = glm.vec3(0.5,0.5,0.5)
renderer.modelList.append(barrel)

key = Model('models/key/key.obj', 'models/key/key.bmp')
key.scale = glm.vec3(0.5,0.5,0.5)
key.rotation = glm.vec3(0,90,0)
renderer.modelList.append(key)
Beispiel #2
0
import pygame
from pygame.locals import *

from gl import Renderer
import shaders

deltaTime = 0.0

# Inicializacion de pygame
pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)

# Inicializacion de nuestro Renderer en OpenGL
r = Renderer(screen)
r.setShaders(shaders.vertex_shader, shaders.fragment_shader)
r.createObjects()

cubeX = 0
cubeZ = 0

isPlaying = True
while isPlaying:

    # Para revisar si una tecla esta presionada
    keys = pygame.key.get_pressed()
    if keys[pygame.K_a]:
        cubeX -= 2 * deltaTime
    if keys[pygame.K_d]:
        cubeX += 2 * deltaTime
Beispiel #3
0
import pygame
from pygame.locals import *

from gl import Renderer
import shaders

delta_time = 0.0

pygame.init()
clock = pygame.time.Clock()

SCREEN_SIZE = (960, 540)
SCREEN = pygame.display.set_mode(SCREEN_SIZE, DOUBLEBUF | OPENGL)

renderer = Renderer(SCREEN)
renderer.set_shaders(shaders.vertex_shader, shaders.fragment_shader)
renderer.create_objects()

cube_x = 0
cube_z = 0
camera_x = 0
camera_z = 3
camera_pitch = 0
camera_yaw = 0
camera_roll = 0


isRunning = True

while isRunning: 
    keys = pygame.key.get_pressed()
Beispiel #4
0
deltaTime = 0.0

changeY=False
changeX=False

# Inicializacion de pygame
pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, OPENGLBLIT | DOUBLEBUF | OPENGL)

#backgroung
#bgspace=pygame.image.load('spaceIm.jpg')

# Inicializacion de nuestro Renderer en OpenGL
r = Renderer(screen)
r.camPosition.z = 3
r.camPosition.x = 0
r.camPosition.y = 0
r.pointLight.x = 5


r.setShaders(shaders.vertex_shader, shaders.fragment_shader)

#r.modelList.append(Model('dogo.obj', 'dogo1.bmp'))

#Incluir audio
def Audio_rata():
        pygame.mixer.pre_init(44100, -16, 2, 2048)
        pygame.mixer.init()
        pygame.mixer.music.load("rata.mp3")
Beispiel #5
0
def render():
    # Initializr pygame and our own renderer based on OpenGl
    deltaTime = 0.0

    clock = pygame.time.Clock()
    screenSize = (960, 540)
    screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)
    pygame.display.set_caption('OpenGl')

    renderer = Renderer(screen)
    # Set shaders and create objects
    renderer.setShaders(shaders.vertex_shader, shaders.fragment_shader)

    renderer.modelList.append(
        Model('tri_coca.obj', 'coca.png', glm.vec3(0.4, 0.4, 0.4)))
    renderer.modelList.append(
        Model('tri_hamster.obj', 'hamster.bmp', glm.vec3(3 / 4, 3 / 4, 3 / 4),
              glm.vec3(0, 90, 0)))
    renderer.modelList.append(
        Model('tri_R2.obj', 'R2.bmp', glm.vec3(1.5 / 3, 1.5 / 3, 1.5 / 3)))
    renderer.modelList.append(
        Model('tri_apple.obj', 'apple.jpg', glm.vec3(15, 15, 15)))
    renderer.modelList.append(
        Model('tri_heart.obj', 'heart.png', glm.vec3(7, 7, 7)))

    #Initial Camera Position and Rotation
    renderer.camPos = glm.vec3(0, 0, 10)
    cameraX, cameraY, cameraZ = renderer.camPos
    pitch = renderer.pitchCam
    yaw = renderer.yawCam
    roll = renderer.rollCam
    renderer.pointLight.z = 20
    #Check if we are tryng to render the screen
    isRendering = True
    radius = 10
    camAngle = 0
    a = 1
    while isRendering:

        # Check if any key is pressed
        keys = pygame.key.get_pressed()

        #Movement in camera X, camera Y and camera Z.
        # if keys[pygame.K_a]:
        #     cameraX -= 2 * deltaTime
        # if keys[pygame.K_d]:
        #     cameraX += 2 * deltaTime
        # if keys[pygame.K_e]:
        #     if(cameraZ>4):
        #         cameraZ -= 2 * deltaTime
        # if keys[pygame.K_q]:
        #     if(cameraZ<15):
        #         cameraZ += 2 * deltaTime
        # if keys[pygame.K_s]:
        #     cameraY -= 2 * deltaTime
        # if keys[pygame.K_w]:
        #     cameraY += 2 * deltaTime

        if keys[pygame.K_a]:
            camAngle -= 1
            cameraX = sin(radians(camAngle)) * radius
            cameraZ = cos(radians(camAngle)) * radius
        if keys[pygame.K_d]:
            camAngle += 1
            cameraX = sin(radians(camAngle)) * radius
            cameraZ = cos(radians(camAngle)) * radius
        if keys[pygame.K_e]:
            if (radius > 4):
                radius -= 2 * deltaTime
                cameraX = sin(radians(camAngle)) * radius
                cameraZ = cos(radians(camAngle)) * radius
        if keys[pygame.K_q]:
            if (radius < 15):
                radius += 2 * deltaTime
                cameraX = sin(radians(camAngle)) * radius
                cameraZ = cos(radians(camAngle)) * radius
        if keys[pygame.K_s]:
            if (cameraY >= -radius):
                cameraY -= 5 * deltaTime
        if keys[pygame.K_w]:
            if (cameraY <= radius):
                cameraY += 5 * deltaTime
        #Reset Camera to Default
        if keys[pygame.K_r]:
            cameraX = 0
            cameraY = 0
            cameraZ = 10
            camAngle = 0
            radius = 10

        if (pygame.mouse.get_pressed()[0] == 1):
            mouseMove = pygame.mouse.get_rel()
            if (mouseMove[0] != 0):
                camAngle += mouseMove[0]
                cameraX = sin(radians(camAngle)) * radius
                cameraZ = cos(radians(camAngle)) * radius
            elif (mouseMove[1] != 0):
                if (mouseMove[1] > 0):
                    nextCamY = cameraY + abs(mouseMove[1] * 0.2)
                    if (not nextCamY >= radius):
                        cameraY = nextCamY
                else:
                    nextCamY = cameraY - abs(mouseMove[1] * 0.2)
                    if (not nextCamY <= -radius):
                        cameraY = nextCamY

        # #Rotation in camera
        # if keys[pygame.K_i]:
        #     pitch -= 10 * deltaTime
        # if keys[pygame.K_o]:
        #     pitch += 10 * deltaTime
        # if keys[pygame.K_k]:
        #     yaw -= 10 * deltaTime
        # if keys[pygame.K_l]:
        #     yaw += 10 * deltaTime
        # if keys[pygame.K_j]:
        #     roll -= 10 * deltaTime
        # if keys[pygame.K_h]:
        #     roll += 10 * deltaTime

        for ev in pygame.event.get():
            if ev.type == pygame.QUIT:
                isRendering = False
            elif ev.type == pygame.KEYDOWN:
                # Checking for any other key pressed to exit
                #Filled Mode
                if ev.key == pygame.K_1:
                    renderer.filledMode()
                #WireframeMode
                elif ev.key == pygame.K_2:
                    renderer.wireframeMode()
                #Change object
                elif ev.key == pygame.K_SPACE:
                    renderer.modelShow = (renderer.modelShow + 1) % len(
                        renderer.modelList)
                    if (renderer.modelShow == 4):
                        pygame.mixer.music.load("heartbeat.mp3")
                        pygame.mixer.music.play(-1)
                        # heart_shader didnt work:(
                        renderer.setShaders(shaders.vertex_shader,
                                            shaders.fragment_shader)
                    elif ((renderer.modelShow == 0)):
                        pygame.mixer.music.load("bgmusic.mp3")
                        pygame.mixer.music.play(-1)
                        renderer.setShaders(shaders.vertex_shader,
                                            shaders.fragment_shader)
                elif ev.key == pygame.K_ESCAPE:
                    isRendering = False
            #Mouse Movement
            elif ev.type == pygame.MOUSEBUTTONDOWN:
                if ev.button == 3:
                    #Reset cam pos
                    cameraX = 0
                    cameraY = 0
                    cameraZ = 10
                    camAngle = 0
                    radius = 10
                elif ev.button == 4:
                    if (radius > 4):
                        radius -= 10 * deltaTime
                        cameraX = sin(radians(camAngle)) * radius
                        cameraZ = cos(radians(camAngle)) * radius
                elif ev.button == 5:
                    if (radius < 15):
                        radius += 10 * deltaTime
                        cameraX = sin(radians(camAngle)) * radius
                        cameraZ = cos(radians(camAngle)) * radius

        # Traslate and rotate our camera
        renderer.translateCamera(cameraX, cameraY, cameraZ)
        renderer.rotateCamera(pitch, yaw, roll)

        # Render loop
        try:
            renderer.render()
        except Exception as e:
            print(e)
        pygame.display.flip()
        clock.tick(60)
        deltaTime = clock.get_time() / 1000
Beispiel #6
0
}, {
    'nameFile': 'tv.obj',
    'textureFile': 'tv.bmp',
    'init': 10,
}, {
    'nameFile': 'Panda.obj',
    'textureFile': 'pandas.bmp',
    'init': 12,
}, {
    'nameFile': 'bear.obj',
    'textureFile': 'bearskin.bmp',
    'init': 13,
}]

# Inicializacion de nuestro Renderer en OpenGL
r = Renderer(screen)
r.pointLight.x = 5
r.pointLight.z = 88

r.camPosition.z = modelos[r.temp]['init']
r.setShaders(shaders.vertex_shader, shaders.fragment_shader)

for modelo in modelos:
    print(modelo['nameFile'])
    r.modelList.append(Model(modelo['nameFile'], modelo['textureFile']))
#r.modelList.append(Model('model.obj', 'model.bmp'))

isPlaying = True
while isPlaying:

    # Para revisar si una tecla esta presionada
import pygame
from pygame.locals import *

from gl import Renderer
import shaders

deltaTime = 0.0

# Inicializacion de pygame
pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)

# Inicializacion de nuestro Renderer en OpenGL
r = Renderer(screen)
r.setShaders(shaders.vertex_shader, shaders.fragment_shader)
r.createObjects()

cubeX = 0
cubeY = 0
cubeZ = 0
cubeP = 0
cubeR = 0
cubeYawl = 0

isPlaying = True
while isPlaying:

    # Para revisar si una tecla esta presionada
    keys = pygame.key.get_pressed()
Beispiel #8
0
camY = 0
camZ = 0

rollAngle = 0
pitchAngle = 0
yawAngle = 0

pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, OPENGLBLIT | DOUBLEBUF | OPENGL)

pygame.mixer.music.load('background_music.mp3')
pygame.mixer.music.play(0)

r = Renderer(screen)
r.setShaders(shaders.vertex_shader, shaders.fragment_shader)

# cargar los modelos

fox= Model('models/ironman.obj', 'textures/ironman.tga')
fox.position = glm.vec3(0, -1, -8)
fox.rotation = glm.vec3(0, 0, 0)

nave = Model('models/coke.obj', 'textures/coke.png')
nave.position = glm.vec3(0,0,-4)
nave.rotation = glm.vec3(0, 0, 0)
nave.scale = glm.vec3(0.1, 0.1, 0.1)

r2 = Model('models/r2.obj','textures/R2.bmp')
r2.position = glm.vec3(0, 2, -15)
Beispiel #9
0
import glm
import pygame
import shaders
from pygame.locals import *
from gl import Renderer, Model


deltaTime = 0.0
all_shaders = [eval("shaders." + shader_name) for shader_name in dir(shaders) if not shader_name.startswith("__") and shader_name != "vertex_shader"]
actual_shader_index = 0
pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)

screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)
r = Renderer(screen)
r.camPosition.z = 3
r.pointLight.x = 10

r.setShaders(shaders.vertex_shader, shaders.fragment_shader)
model1 = Model("assets/beriev/BerievA50.obj", "assets/beriev/Beriev_2048.bmp", glm.vec3(0.01, 0.01, 0.01))
r.modelList.append(model1)

model2 = Model("assets/sign/Stool.obj", "assets/Face/model.bmp", glm.vec3(0.025, 0.025, 0.025))
r.modelList.append(model2)

model3 = Model("assets/sign/objSign.obj", "assets/Face/model.bmp", glm.vec3(0.25, 0.25, 0.25))
r.modelList.append(model3)

model3 = Model("assets/f16/F-16D.obj", "assets/f16/Albedo.bmp", glm.vec3(0.25, 0.25, 0.25))
r.modelList.append(model3)
Beispiel #10
0
def modelos():
    screenSize = (960, 540)
    screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)
    # Inicializacion de nuestro Renderer en OpenGL
    r = Renderer(screen)

    # HAMSTER
    r.camPosition.z = 1
    r.camPosition.y = 0
    r.pointLight.y = 50
    r.pointLight.z = 50

    r.setShaders(shaders.vertex_shader, shaders.fragment_shader)

    m = Model('./models/Hamster.obj', './models/Hamster.bmp')

    pygame.mixer.music.load('sonidos/caricatura.mp3')
    pygame.mixer.music.play(10)

    r.modelList.append(m)

    isPlaying = True
    while isPlaying:

        # Para revisar si una tecla esta presionada
        keys = pygame.key.get_pressed()

        # Movimientos de camara
        if keys[K_d]:
            r.camPosition.x += 1 * deltaTime
        if keys[K_a]:
            r.camPosition.x -= 1 * deltaTime
        if keys[K_w]:
            r.camPosition.z -= 1 * deltaTime
        if keys[K_s]:
            r.camPosition.z += 1 * deltaTime
        if keys[K_e]:
            r.camPosition.y -= 1 * deltaTime
        if keys[K_q]:
            r.camPosition.y += 1 * deltaTime
        if keys[K_r]:
            m.rotation.y += 3 * deltaTime
        if keys[K_t]:
            m.rotation.y -= 3 * deltaTime
        if keys[K_y]:
            m.rotation.x += 3 * deltaTime
        if keys[K_u]:
            m.rotation.x -= 3 * deltaTime
        if keys[K_i]:
            m.rotation.z += 3 * deltaTime
        if keys[K_o]:
            m.rotation.z -= 3 * deltaTime

        # REGRESAR A INSTRUCTIVO
        if keys[K_m]:
            intro()

        # cambiar de modelos
        if keys[K_c]:
            # MUJER 
            r.modelList.clear()
            r.camPosition.z = 50
            r.camPosition.y = 150
            r.pointLight.y = 0
            r.pointLight.z = 300
            m = Model('./models/mujer.obj', './models/mujer.bmp')
            r.modelList.append(m)
        if keys[K_v]:
            r.modelList.clear()
            # MUJER E HIJO
            r.camPosition.z = 50
            r.camPosition.y = 150
            r.pointLight.y = 0
            r.pointLight.z = 300
            m = Model('./models/mujer_hijo.obj', './models/mujer_hijo.bmp')
            r.modelList.append(m)
        if keys[K_b]:
            r.modelList.clear()
            # HAMSTER
            r.camPosition.z = 1
            r.camPosition.y = 0
            r.pointLight.y = 50
            r.pointLight.z = 50
            m = Model('./models/Hamster.obj', './models/Hamster.bmp')
            r.modelList.append(m)
        if keys[K_n]:
            r.modelList.clear()
            # HOMBRE
            r.camPosition.z = 50
            r.camPosition.y = 170
            r.camPosition.x = 5
            r.pointLight.y = 0
            r.pointLight.z = 300
            m = Model('./models/hombre.obj', './models/hombre.bmp')
            r.modelList.append(m)

        for ev in pygame.event.get():
            if ev.type == pygame.QUIT:
                isPlaying = False
            elif ev.type == pygame.KEYDOWN:
                # para revisar en el momento que se presiona una tecla
                if ev.key == pygame.K_1:
                    r.filledMode()
                elif ev.key == pygame.K_2:
                    r.wireframeMode()
                elif ev.key == pygame.K_ESCAPE:
                    isPlaying = False
            elif ev.type == pygame.MOUSEBUTTONDOWN:
                r.pointLight.x = -r.pointLight.x - 100
                r.pointLight.y = -r.pointLight.y - 100

        # Main Renderer Loop
        r.render()

        pygame.display.flip()
        clock.tick(60)
        deltaTime = clock.get_time() / 1000


    pygame.quit()
Beispiel #11
0
from pygame import mixer

from gl import Renderer, Model
import glm
import shaders

deltaTime = 0.0

# Inicializacion de pygame
pygame.init()
clock = pygame.time.Clock()
screenSize = (960, 540)
screen = pygame.display.set_mode(screenSize, DOUBLEBUF | OPENGL)

# Inicializacion de nuestro Renderer en OpenGL
r = Renderer(screen)
r.camPosition.z = 3
r.pointLight.x = 5

r.setShaders(shaders.vertex_shader, shaders.fragment_shader)

# Model 1: Face
r.modelList.append(
    Model('./Models/model.obj', './Models/model.bmp', scale=glm.vec3(1, 1, 1)))

# Model 2: Eye Ball
r.modelList.append(
    Model('./Models/eyeball.obj',
          './Models/Eye_D.bmp',
          scale=glm.vec3(0.5, 0.5, 0.5)))