| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import Image |
|---|
| 27 |
from OpenGL import GL, GLU |
|---|
| 28 |
|
|---|
| 29 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 30 |
#~ Definitions |
|---|
| 31 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 32 |
|
|---|
| 33 |
def _DecodeImageData(strdata, size): |
|---|
| 34 |
rawdata = strdata.decode('base64').decode('zlib') |
|---|
| 35 |
return rawdata, size |
|---|
| 36 |
def _EncodeImageData(filename): |
|---|
| 37 |
image = Image.open(filename) |
|---|
| 38 |
rawdata = image.tostring('raw', 'RGBX', 0, -1) |
|---|
| 39 |
strdata = rawdata.encode('zlib').encode('base64') |
|---|
| 40 |
return strdata, image.size |
|---|
| 41 |
|
|---|
| 42 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 43 |
|
|---|
| 44 |
Rawdata = _DecodeImageData(""" |
|---|
| 45 |
eJzt3c9qE1EYxuFb76KLUqpBoa0RaRQk1sXERdxIsvEi+tfWaimiV3HMK8zYrW4C8z0HzgX8zsOZ |
|---|
| 46 |
SWbztWZVX+tfH9vyx6J1D+/b6f28zb+/HeVOWxrTmuah//NDW366b93yWzv9cNfm3ddR7rSlMa1p |
|---|
| 47 |
7lfOI2czu3vdprev2vHNy1HutKUxrWke+jfnkbOZvbtt0zdf2vFsnDttaUxrmvuVO5FzObqZtsn1 |
|---|
| 48 |
YTu4ej7KnbY0pjXNQ//mTuRcjk6u2+TFVTs4vBzlTlsa05rmfuU+5G7kfPYuJ233/Mkod9rSmNY0 |
|---|
| 49 |
D/2b+5C7kfPZe3bRdp+ej3KnLY1pTXO/8m7M8zF3JOe0c7Y/yp22NKY1zUP/5t2Y52PuSM5pZ/9s |
|---|
| 50 |
lDttaUxrmvnz58+fP3/+/Pnz589/2078+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/ |
|---|
| 51 |
f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/7bduLPnz9//vz58+fPnz9//vz5 |
|---|
| 52 |
8+fPnz9//vz58+fPnz////U3/632/DfzH2vPf6w5/7X72198/mu9+c9dW/1cDv2r4vOfLcuqu9YF |
|---|
| 53 |
n3+rR8+/vAvyTqjz/lv8eef3q/rvn9jX+/27GPqr//+p/v+3+veP6t+/qn//9P2bP3/+/Pnz579t |
|---|
| 54 |
J/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78+fPnz58/f/78 |
|---|
| 55 |
+fPnz58/f/78+fPnz58//2078efPnz9//vz58+fPnz9//vz58+fPnz9//vz58+fPnz9//vz58/83 |
|---|
| 56 |
f/Pfas9/M/+x9vxH818Xpee/Vpz/vH40/zmzkHMeVec/W3XXb80sVlc= |
|---|
| 57 |
|
|---|
| 58 |
""", (128,128)) |
|---|
| 59 |
|
|---|
| 60 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 61 |
|
|---|
| 62 |
class TextureGrid(object): |
|---|
| 63 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 64 |
#~ Constants / Variables / Etc. |
|---|
| 65 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 66 |
|
|---|
| 67 |
GridExtent = 1 |
|---|
| 68 |
TextureExtent = 10 |
|---|
| 69 |
TextureID = None |
|---|
| 70 |
ReloadTexture = 0 |
|---|
| 71 |
imagedata, imagesize = Rawdata |
|---|
| 72 |
|
|---|
| 73 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 74 |
#~ Public Methods |
|---|
| 75 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 76 |
|
|---|
| 77 |
def __init__(self, **kw): |
|---|
| 78 |
for name, value in kw.iteritems(): |
|---|
| 79 |
setattr(self, name, value) |
|---|
| 80 |
|
|---|
| 81 |
def LoadGridTexture(self, filename): |
|---|
| 82 |
image = Image.open(filename) |
|---|
| 83 |
self.imagedata = image.tostring('raw', 'RGBX', 0, -1) |
|---|
| 84 |
self.imagesize = image.size |
|---|
| 85 |
self.ReloadTexture = 1 |
|---|
| 86 |
|
|---|
| 87 |
def _LoadTexture(self): |
|---|
| 88 |
w, h = self.imagesize |
|---|
| 89 |
|
|---|
| 90 |
if self.TextureID is None: |
|---|
| 91 |
self.TextureID = GL.glGenTextures(1) |
|---|
| 92 |
GL.glBindTexture(GL.GL_TEXTURE_2D, self.TextureID) |
|---|
| 93 |
GL.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, 1) |
|---|
| 94 |
GL.glTexImage2D(GL.GL_TEXTURE_2D, 0, 3, w, h, 0, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata) |
|---|
| 95 |
#GLU.gluBuild2DMipmaps(GL.GL_TEXTURE_2D, 3, w, h, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, self.imagedata) |
|---|
| 96 |
|
|---|
| 97 |
GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_REPEAT) |
|---|
| 98 |
GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_REPEAT) |
|---|
| 99 |
GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR) |
|---|
| 100 |
GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR) |
|---|
| 101 |
#GL.glTexParameterf(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR_MIPMAP_NEAREST) |
|---|
| 102 |
|
|---|
| 103 |
def GLExecute(self, context): |
|---|
| 104 |
if self.ReloadTexture or self.TextureID is None: |
|---|
| 105 |
self._LoadTexture() |
|---|
| 106 |
self.ReloadTexture = 0 |
|---|
| 107 |
|
|---|
| 108 |
GL.glEnable(GL.GL_TEXTURE_2D) |
|---|
| 109 |
GL.glBindTexture(GL.GL_TEXTURE_2D, self.TextureID) |
|---|
| 110 |
GL.glTexEnvf(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE) |
|---|
| 111 |
|
|---|
| 112 |
GridExtent = self.GridExtent |
|---|
| 113 |
TextureExtent = self.TextureExtent |
|---|
| 114 |
|
|---|
| 115 |
GL.glColor3f(1, 1., 1.) |
|---|
| 116 |
GL.glNormal3f(0, 1., 0.) |
|---|
| 117 |
|
|---|
| 118 |
GL.glBegin(GL.GL_QUADS) |
|---|
| 119 |
GL.glTexCoord2f(0, 0) |
|---|
| 120 |
GL.glVertex3f(-GridExtent, 0., -GridExtent) |
|---|
| 121 |
GL.glTexCoord2f(0, TextureExtent) |
|---|
| 122 |
GL.glVertex3f(-GridExtent, 0., GridExtent) |
|---|
| 123 |
GL.glTexCoord2f(TextureExtent, TextureExtent) |
|---|
| 124 |
GL.glVertex3f(GridExtent, 0., GridExtent) |
|---|
| 125 |
GL.glTexCoord2f(TextureExtent, 0) |
|---|
| 126 |
GL.glVertex3f(GridExtent, 0., -GridExtent) |
|---|
| 127 |
GL.glEnd() |
|---|
| 128 |
|
|---|
| 129 |
GL.glDisable(GL.GL_TEXTURE_2D) |
|---|