Permalink
Browse files

Added Skybox, Fixed a Bug in obj.py that did not use self for itself.

  • Loading branch information...
1 parent 90caf17 commit 7e705c6bfed58480be46d0c34f3e9a994721e5f5 Fabián Heredia Montiel committed Apr 26, 2012
View
@@ -52,11 +52,11 @@ def init():
# Config de despliege
glClearColor(0.5, 0.5, 1.0, 1.0)
glMatrixMode(GL_PROJECTION)
- gluPerspective(45.0, config.wAncho/float(config.wAlto), 0.1, 100000.0)
+ gluPerspective(45.0, config.wAncho/float(config.wAlto), 0.1, 1000.0)
glMatrixMode(GL_MODELVIEW)
# Habilitando
- glEnable(GL_CULL_FACE)
+ # glEnable(GL_CULL_FACE)
glEnable(GL_DEPTH_TEST);
glEnable(GL_COLOR_MATERIAL)
glEnable(GL_LIGHTING)
@@ -65,9 +65,10 @@ def init():
# Shaders
glsl.add("shaders/vertex.glsl", GL_VERTEX_SHADER, True)
glsl.add("shaders/frag.glsl", GL_FRAGMENT_SHADER, True)
- glsl.toggle()
+ # glsl.toggle()
# Add objects
+ object.create("resources/models/skybox.obj", {"id": "skybox", "pos": [0, 0, 0, 100], "scale": 50})
object.create("resources/models/Pejuang_Final.obj", {"id": "player", "pos": [0, 0, 0, 100]})
object.create("resources/models/Pejuang_Final.obj", {"pos": [randint(0,360), randint(0,360), randint(0,360), 100]})
@@ -106,7 +107,7 @@ def display():
# Escena
glutSolidSphere(100,40, 40)
glTranslatef(0,-100,0)
- glutWireCube(100,100,1)
+ glutSolidCube(100,100,1)
# Pasar a pantalla
glutSwapBuffers()
View
@@ -2,6 +2,7 @@
# Bug Fixes:
# - Cuando Model llama a MTL, MTL no recibia el camino actual
# - MTL no podia estar vacio
+import pygame
from os.path import dirname
from OpenGL.GL import *
@@ -39,10 +40,10 @@ def MTL(filename):
class Model:
def __init__(self, filename, swapyz=False):
"""Loads a Wavefront OBJ file. """
- Model.vertices = []
- Model.normals = []
- Model.texcoords = []
- Model.faces = []
+ self.vertices = []
+ self.normals = []
+ self.texcoords = []
+ self.faces = []
material = None
for line in open(filename, "r"):
@@ -53,20 +54,20 @@ def __init__(self, filename, swapyz=False):
v = map(float, values[1:4])
if swapyz:
v = v[0], v[2], v[1]
- Model.vertices.append(v)
+ self.vertices.append(v)
elif values[0] == 'vn':
v = map(float, values[1:4])
if swapyz:
v = v[0], v[2], v[1]
- Model.normals.append(v)
+ self.normals.append(v)
elif values[0] == 'vt':
- Model.texcoords.append(map(float, values[1:3]))
+ self.texcoords.append(map(float, values[1:3]))
elif values[0] in ('usemtl', 'usemat'):
#Bugfix en caso de aterial en blanco
if len(values) == 1: material = ""
material = values[1]
elif values[0] == 'mtllib':
- Model.mtl = MTL(dirname(filename) + "/" + values[1])
+ self.mtl = MTL("resources/models/" + values[1])
elif values[0] == 'f':
face = []
texcoords = []
@@ -82,17 +83,17 @@ def __init__(self, filename, swapyz=False):
norms.append(int(w[2]))
else:
norms.append(0)
- Model.faces.append((face, norms, texcoords, material))
+ self.faces.append((face, norms, texcoords, material))
- Model.gl_list = glGenLists(1)
- glNewList(Model.gl_list, GL_COMPILE)
+ self.gl_list = glGenLists(1)
+ glNewList(self.gl_list, GL_COMPILE)
glEnable(GL_TEXTURE_2D)
glFrontFace(GL_CCW)
- for face in Model.faces:
+ for face in self.faces:
vertices, normals, texture_coords, material = face
# Bug Fix: Material por defect en caso de que no exista el material
- try: mtl = Model.mtl[material]
+ try: mtl = self.mtl[material]
except: mtl = {'Ka': [0.1, 0.1, 0.1], 'd': [1.0], 'Kd': [0.8, 0.8, 0.8], 'illum': [2.0], 'Ks': [0.8, 0.8, 0.8], 'Ns': [50.0]}
if 'texture_Kd' in mtl:
# use diffuse texmap
@@ -104,15 +105,15 @@ def __init__(self, filename, swapyz=False):
glBegin(GL_POLYGON)
for i in range(len(vertices)):
if normals[i] > 0:
- glNormal3fv(Model.normals[normals[i] - 1])
+ glNormal3fv(self.normals[normals[i] - 1])
if texture_coords[i] > 0:
- glTexCoord2fv(Model.texcoords[texture_coords[i] - 1])
- glVertex3fv(Model.vertices[vertices[i] - 1])
+ glTexCoord2fv(self.texcoords[texture_coords[i] - 1])
+ glVertex3fv(self.vertices[vertices[i] - 1])
glEnd()
glDisable(GL_TEXTURE_2D)
glEndList()
# Funcion Para dibujar
def draw(self = None):
- glCallList(Model.gl_list)
+ glCallList(self.gl_list)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
@@ -0,0 +1,13 @@
+# Blender MTL File: 'skybox.blend'
+# Material Count: 1
+newmtl skybox
+Ns 96.078431
+Ka 0.000000 0.000000 0.000000
+Kd 0.640000 0.640000 0.640000
+Ks 0.500000 0.500000 0.500000
+Ni 1.000000
+d 1.000000
+illum 2
+map_Kd resources/models/duskcontrast.jpg
+
+
Oops, something went wrong.

0 comments on commit 7e705c6

Please sign in to comment.