Skip to content

Commit

Permalink
agrego texturas
Browse files Browse the repository at this point in the history
  • Loading branch information
ggayan committed Jul 4, 2010
1 parent 487afca commit 79dc4c6
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 18 deletions.
13 changes: 7 additions & 6 deletions patch.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from OpenGL.GL import glVertex3f
import math

from variables import *
from OpenGL.GL import *

#implementado como triangulo
class Patch:
Expand Down Expand Up @@ -71,11 +72,11 @@ def draw(self):
p2 = self.p2
p3 = self.p3
p4 = self.p4
glVertex3f(p1.x, p1.y, p1.z)
glVertex3f(p2.x, p2.y, p2.z)
glVertex3f(p3.x, p3.y, p3.z)
glVertex3f(p4.x, p4.y, p4.z)
glTexCoord2f(0.0, 0.0); glVertex3f(p1.x, p1.y, p1.z)
glTexCoord2f(1.0, 0.0); glVertex3f(p2.x, p2.y, p2.z)
glTexCoord2f(1.0, 1.0); glVertex3f(p3.x, p3.y, p3.z)
glTexCoord2f(0.0, 1.0); glVertex3f(p4.x, p4.y, p4.z)

# retorna el radio de la circunferencia circunscrita
def _pradio(self):
# d1 = self.center.resta(self.p1,1).modulo()
Expand Down
52 changes: 41 additions & 11 deletions radiosity.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
from OpenGL.GLU import *
from numpy import *

import Image
import cPickle
import os
import sys
import math
import time
Expand Down Expand Up @@ -59,13 +61,16 @@ def init(width, height):
print "segundos= ",time.time()-ITIME
print strftime("%a, %d %b %Y %H:%M:%S", gmtime(time.time()-3600*4))


LoadTextures()
glEnable(GL_TEXTURE_2D)
glClearColor(0.0, 0.0, 0.0, 0.0) # Color negro, sin transparencia

glClearDepth(1.0) # Enables Clearing Of The Depth Buffer
glDepthRange(0.0, 0.85)
glDepthFunc(GL_LESS) # The Type Of Depth Test To Do
glEnable(GL_DEPTH_TEST) # Enables Depth Testing
glShadeModel(GL_SMOOTH) # Enables Smooth Color Shading
glTexEnvf( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE )

This comment has been minimized.

Copy link
@ggayan

ggayan Jul 5, 2010

Author Owner

creo que aquí esta la magia de mezclar la textura con la luz que sale de radiosity.


glMatrixMode(GL_PROJECTION)
glLoadIdentity() # Reset The Projection Matrix
Expand Down Expand Up @@ -99,7 +104,7 @@ def DrawGLScene():
UP_VECTOR_X, UP_VECTOR_Y, UP_VECTOR_Z)

#dibujo los ejes
axis()
#axis()

#dibujo el escenario
escenario()
Expand Down Expand Up @@ -271,15 +276,15 @@ def getFormFactor(i,j):
def RadiosityIteration(iterations):
for x in xrange(0,iterations):
print "iteration ",x
shoot()
# collect()
#shoot()
collect()

def shoot():
for index_x, patch_1 in enumerate(patchesList):
for index_y, patch_2 in enumerate(patchesList):
if( index_x == index_y):
continue
ff = 0.3*getFormFactor(index_x, index_y)
ff = getFormFactor(index_x, index_y)
if(ff==0):
continue
patch_2.incident_red += patch_1.excident_red * ff
Expand All @@ -291,7 +296,6 @@ def shoot():
patch.excident_green = patch.emmision_green + patch.incident_green * patch.reflectance_green
patch.excident_blue = patch.emmision_blue + patch.incident_blue * patch.reflectance_blue


def collect():
for index_x, patch_1 in enumerate(patchesList):
aux_r = 0
Expand All @@ -312,7 +316,10 @@ def collect():
for patch in patchesList:
patch.excident_red = patch.emmision_red + patch.incident_red * patch.reflectance_red
patch.excident_green = patch.emmision_green + patch.incident_green * patch.reflectance_green
patch.excident_blue = patch.emmision_blue + patch.incident_blue * patch.reflectance_blue
patch.excident_blue = patch.emmision_blue + patch.incident_blue * patch.reflectance_blue

def calc_incident_light(patch):
total_light = 0.0

def dibujarListaParches():
for patch in patchesList:
Expand Down Expand Up @@ -403,10 +410,33 @@ def keyPressed(*args): #Presionar una tecla
LOOK_AT_Z = LOOK_AT_Z - speed
# print "LOOK_AT_Z =", LOOK_AT_Z
if key == '\053':
shoot()
# collect()
print "SHOOT!"

#shoot()
collect()
#print "SHOOT!"
print "COLLECT!"

def LoadTextures():
#global texture
image = Image.open("texture.jpg")

ix = image.size[0]
iy = image.size[1]
image = image.tostring("raw", "RGBX", 0, -1)

# Create Texture
# There does not seem to be support for this call or the version of PyOGL I have is broken.
#glGenTextures(1, texture)
#glBindTexture(GL_TEXTURE_2D, texture) # 2d texture (x and y size)

glPixelStorei(GL_UNPACK_ALIGNMENT,1)
glTexImage2D(GL_TEXTURE_2D, 0, 3, ix, iy, 0, GL_RGBA, GL_UNSIGNED_BYTE, image)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST)
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST)
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL)

def main(): #Nuestra funcion principal
global windowId
Expand Down
Binary file added texture.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
# 1 = calcular
VSB = 0
FFT = 0
shoots = 1
shoots = 2

# intensidad de fuentes luminosas
INITINTEN = 500.0
Expand Down

0 comments on commit 79dc4c6

Please sign in to comment.