diff --git a/lightsim/openglsim.py b/lightsim/openglsim.py --- a/lightsim/openglsim.py +++ b/lightsim/openglsim.py @@ -1,38 +1,56 @@ # see http://www.sgi.com/software/opengl/advanced97/notes/node57.html for accum notes -import sys -from Image import * +import sys, time +import numpy as num from OpenGL.GL import * from OpenGL.Tk import * +import Image + +def drawWithAlpha(imgString, w, h, alpha): + """without opengl extensions""" + t = time.time() + ar = num.reshape(num.fromstring(imgString, dtype='uint8'), + (w * h, 4)) + print " tonum", time.time() - t + ar[:,3] *= alpha + + print " scl", time.time() - t + glDrawPixels(w, h, + GL_RGBA, GL_UNSIGNED_BYTE, ar.tostring()) + print " draw", time.time() - t + class Surface: def Display(self, event=None): - + assert 'GL_ARB_imaging' in glGetString(GL_EXTENSIONS).split() + glClearColor(0.0, 0.0, 0.0, 0) glClear( GL_COLOR_BUFFER_BIT |GL_ACCUM_BUFFER_BIT) - + glEnable(GL_BLEND) + #glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) + glBlendFunc(GL_SRC_ALPHA, GL_DST_ALPHA) l=glGenLists(1) glNewList(l,GL_COMPILE) glEndList() # glDrawBuffer(GL_BACK) - for x in range(1,2): - + for x, img in enumerate(self.image): mag = self.scales[x].get() print "pic %i at %f" % (x,mag) - glClear(GL_COLOR_BUFFER_BIT) - glDrawPixels(self.imageWidth, self.imageHeight, GL_RGB, GL_UNSIGNED_BYTE, self.image[x]) +# glClear(GL_COLOR_BUFFER_BIT) + #glBlendColor(1, 1, 1, mag) # needs ARB_imaging + drawWithAlpha(img, self.imageWidth, self.imageHeight, mag) + - if x==0: - glAccum(GL_LOAD,mag) - else: - glAccum(GL_ACCUM,mag) +## if x==0: +## glAccum(GL_LOAD,mag) +## else: +## glAccum(GL_ACCUM,mag) # glAccum(GL_ADD,self.x) self.x=(self.x+.1)%2.0 - print "return" - glAccum(GL_RETURN,1) +## glAccum(GL_RETURN,1) def SetupWindow(self): self.OglFrame = Frame() @@ -43,7 +61,7 @@ class Surface: def SetupOpenGL(self): - self.ogl = Opengl(master=self.OglFrame, width = 270, height = 270, double = 1, depth = 0) + self.ogl = Opengl(master=self.OglFrame, width = 512, height = 270, double = 1, depth = 0) self.ogl.pack(side = 'top', expand = 1, fill = 'both') self.ogl.set_centerpoint(0, 0, 0) self.ogl.redraw = self.Display @@ -60,11 +78,12 @@ class Surface: self.SetupWindow() self.image=[] - for filename in ('pic1.ppm','pic2.ppm'): - im = open(filename) + for filename in ('skyline/bg.png', 'skyline/cyc-lo-red.png'): + im = Image.open(filename) + im.thumbnail((200, 200)) self.imageWidth = im.size[0] self.imageHeight = im.size[1] - self.image.append(im.tostring("raw", "RGB", 0, -1)) + self.image.append(im.convert("RGBA").tostring())#"raw", "RGB", 0, -1)) print self.imageWidth, self.imageHeight, self.imageWidth * self.imageHeight*4, len(self.image) self.SetupOpenGL()