0
|
1 # see http://www.sgi.com/software/opengl/advanced97/notes/node57.html for accum notes
|
|
2
|
|
3 import sys
|
|
4 from Image import *
|
|
5 from OpenGL.GL import *
|
|
6 from OpenGL.Tk import *
|
|
7
|
|
8 class Surface:
|
|
9 def Display(self, event=None):
|
|
10
|
|
11 glClearColor(0.0, 0.0, 0.0, 0)
|
|
12 glClear( GL_COLOR_BUFFER_BIT |GL_ACCUM_BUFFER_BIT)
|
|
13
|
|
14 l=glGenLists(1)
|
|
15 glNewList(l,GL_COMPILE)
|
|
16 glEndList()
|
|
17
|
|
18 # glDrawBuffer(GL_BACK)
|
|
19
|
|
20 for x in range(1,2):
|
|
21
|
|
22 mag = self.scales[x].get()
|
|
23 print "pic %i at %f" % (x,mag)
|
|
24 glClear(GL_COLOR_BUFFER_BIT)
|
|
25 glDrawPixels(self.imageWidth, self.imageHeight, GL_RGB, GL_UNSIGNED_BYTE, self.image[x])
|
|
26
|
|
27 if x==0:
|
|
28 glAccum(GL_LOAD,mag)
|
|
29 else:
|
|
30 glAccum(GL_ACCUM,mag)
|
|
31
|
|
32 # glAccum(GL_ADD,self.x)
|
|
33 self.x=(self.x+.1)%2.0
|
|
34 print "return"
|
|
35 glAccum(GL_RETURN,1)
|
|
36
|
|
37 def SetupWindow(self):
|
|
38 self.OglFrame = Frame()
|
|
39 self.OglFrame.pack(side = 'top',fill='both',expand=1)
|
|
40 self.QuitButton = Button(self.OglFrame, {'text':'Quit'})
|
|
41 self.QuitButton.bind('<ButtonRelease-1>', sys.exit)
|
|
42 self.QuitButton.pack({'side':'top'})
|
|
43
|
|
44
|
|
45 def SetupOpenGL(self):
|
|
46 self.ogl = Opengl(master=self.OglFrame, width = 270, height = 270, double = 1, depth = 0)
|
|
47 self.ogl.pack(side = 'top', expand = 1, fill = 'both')
|
|
48 self.ogl.set_centerpoint(0, 0, 0)
|
|
49 self.ogl.redraw = self.Display
|
|
50
|
|
51 for x in range(0,2):
|
|
52 self.scales[x] = Scale(self.OglFrame,label="s%i"%x,from_=0,to=1,res=.05,orient='horiz',command=self.ogl.tkRedraw)
|
|
53 self.scales[x].pack()
|
|
54
|
|
55
|
|
56 def __init__(self):
|
|
57 self.x=0
|
|
58 self.scales=[None,None]
|
|
59
|
|
60 self.SetupWindow()
|
|
61
|
|
62 self.image=[]
|
|
63 for filename in ('pic1.ppm','pic2.ppm'):
|
|
64 im = open(filename)
|
|
65 self.imageWidth = im.size[0]
|
|
66 self.imageHeight = im.size[1]
|
|
67 self.image.append(im.tostring("raw", "RGB", 0, -1))
|
|
68 print self.imageWidth, self.imageHeight, self.imageWidth * self.imageHeight*4, len(self.image)
|
|
69
|
|
70 self.SetupOpenGL()
|
|
71
|
|
72 glDisable(GL_CULL_FACE)
|
|
73 # glEnable(GL_DEPTH_TEST)
|
|
74 # glEnable(GL_NORMALIZE)
|
|
75 glShadeModel(GL_FLAT)
|
|
76
|
|
77 self.ogl.tkRedraw()
|
|
78 self.ogl.mainloop()
|
|
79
|
|
80 if __name__ == '__main__':
|
|
81 Surface()
|
|
82
|
|
83 demo = Surface
|