def init(self): GLZPR.init(self) if self.render_textures: glEnable(GL_TEXTURE_2D) glEnable(GL_ALPHA_TEST) glAlphaFunc(GL_GREATER,.4) glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA) glFrontFace(GL_CCW) glEnable(GL_NORMALIZE) glEnable(GL_BLEND) glLightfv(GL_LIGHT0,GL_AMBIENT,(.3,.3,.3,1)) glLightfv(GL_LIGHT0,GL_DIFFUSE,(1,1,1,1)) glLightfv(GL_LIGHT0,GL_SPECULAR,(.1,.1,.1,1)) glColorMaterial(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE) glEnable(GL_COLOR_MATERIAL) self.load_textures_gl() gobject.timeout_add(1,self._animate) if self.shaders: try: from OpenGL.GL import shaders vertex_shader = shaders.compileShader(""" uniform float lerp; varying vec2 texture_coordinate; void main() { gl_Position = gl_ModelViewProjectionMatrix * mix(gl_Vertex,gl_Color,lerp); texture_coordinate = vec2(gl_MultiTexCoord0); // pass to frag } """,GL_VERTEX_SHADER) fragment_shader = shaders.compileShader(""" // tedious, try and be like the FFP varying vec2 texture_coordinate; uniform sampler2D tex; void main() { gl_FragColor = texture2D(tex,texture_coordinate); } """,GL_FRAGMENT_SHADER) self.shader = shaders.compileProgram(vertex_shader,fragment_shader) self.uniform_lerp = glGetUniformLocation(self.shader,"lerp") self.uniform_tex = glGetUniformLocation(self.shader,"tex") except Exception as e: traceback.print_exc() self.shaders = False for model in self.models.values(): model.init_gl() if self.vbos: glEnableClientState(GL_VERTEX_ARRAY) glEnableClientState(GL_NORMAL_ARRAY) glEnableClientState(GL_COLOR_ARRAY)
def zpr_init(): GLZPR.init(zpr) terrain.init_gl()
from OpenGL.GL import * from OpenGL.GLU import * from OpenGL.GLUT import * print "Creating terrain..." from terrain import Terrain terrain = Terrain() terrain.create_ico(2) print "ok" from zpr import GLZPR glutInit(()) gtk.gdk.threads_init() window = gtk.Window(gtk.WINDOW_TOPLEVEL) window.set_title("IcoPlay") window.set_size_request(640,480) window.connect("destroy",lambda event: gtk.main_quit()) vbox = gtk.VBox(False, 0) window.add(vbox) zpr = GLZPR() zpr.draw = terrain.draw_gl_ffp zpr._pick = lambda x,y,dx,dy,event: terrain.pick(x,y) zpr.pick = lambda *args: False def zpr_init(): GLZPR.init(zpr) terrain.init_gl() zpr.init = zpr_init vbox.pack_start(zpr,True,True) window.show_all() gtk.main()