#!/usr/bin/env python


import pyglet
from pyglet.gl import *

window = pyglet.window.Window()

        
@window.event
def on_resize(width, height):
    glViewport(0, 0, width, height)
    glMatrixMode(GL_PROJECTION)
    glLoadIdentity()
    gluPerspective(60., width / float(height), .1, 8192.)
    glMatrixMode(GL_MODELVIEW)
    return pyglet.event.EVENT_HANDLED
    
@window.event
def on_draw():
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
    glLoadIdentity()
    glTranslatef(0.0,0.0,-5.0)

    glBegin(GL_QUADS)
    
    glMultiTexCoord3f(GL_TEXTURE0, texture0.tex_coords[0], texture0.tex_coords[1], texture0.tex_coords[2])
    glMultiTexCoord3f(GL_TEXTURE1, texture1.tex_coords[0], texture1.tex_coords[1], texture1.tex_coords[2])
    glVertex3f(-1.0, -1.0,  1.0)
    glMultiTexCoord3f(GL_TEXTURE0, texture0.tex_coords[3], texture0.tex_coords[4], texture0.tex_coords[5])
    glMultiTexCoord3f(GL_TEXTURE1, texture1.tex_coords[3], texture1.tex_coords[4], texture1.tex_coords[5])
    glVertex3f( 1.0, -1.0,  1.0)	
    glMultiTexCoord3f(GL_TEXTURE0, texture0.tex_coords[6], texture0.tex_coords[7], texture0.tex_coords[8])
    glMultiTexCoord3f(GL_TEXTURE1, texture1.tex_coords[6], texture1.tex_coords[7], texture1.tex_coords[8])
    glVertex3f( 1.0,  1.0,  1.0)	
    glMultiTexCoord3f(GL_TEXTURE0, texture0.tex_coords[9], texture0.tex_coords[10], texture0.tex_coords[11])
    glMultiTexCoord3f(GL_TEXTURE1, texture1.tex_coords[9], texture1.tex_coords[10], texture1.tex_coords[11])
    glVertex3f(-1.0,  1.0,  1.0)	
    glEnd()
        

texture0 = pyglet.resource.image('texture1.png')
texture1 = pyglet.resource.image('texture2.png')
texNames = [texture0.id, texture1.id]
glGenTextures(2, (GLuint * len(texNames))(*texNames))
glActiveTexture(GL_TEXTURE0)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, texNames[0])
glActiveTexture(GL_TEXTURE1)
glEnable(GL_TEXTURE_2D)
glBindTexture(GL_TEXTURE_2D, texNames[1])
pyglet.app.run()