Skip to content

Commit 85afe77

Browse files
committed
some more context info printed
1 parent ce81d23 commit 85afe77

File tree

3 files changed

+28
-9
lines changed

3 files changed

+28
-9
lines changed

demo.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def initgl(self):
2323
GL.glMatrixMode(GL.GL_PROJECTION)
2424
GL.glLoadIdentity()
2525
GLU.gluOrtho2D(-5,5,-5,5)
26+
self.start = time.time()
27+
self.nframes = 0
2628

2729

2830
def redraw(self):
@@ -35,11 +37,14 @@ def redraw(self):
3537
GL.glVertex2f( x, y )
3638
GL.glEnd()
3739
GL.glFlush()
40+
self.nframes+=1
41+
tm = time.time() - self.start
42+
print("fps",self.nframes / tm, end="\r" )
3843

3944
if __name__ == '__main__':
4045
root = Tk()
4146
app = AppOgl(root, width=320, height=200)
4247
app.pack(fill=BOTH, expand=YES)
43-
app.animate=10
48+
app.animate=1
4449
app.after(100, app.printContext)
4550
app.mainloop()

pyopengltk.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,25 @@ def tkMap( self, evt ):
6363

6464
def printContext(self):
6565
""" For debugging """
66-
print( GL.glGetString(GL.GL_VENDOR),
67-
GL.glGetString(GL.GL_RENDERER),
68-
GL.glGetString(GL.GL_VERSION) )
66+
print("Extension list:")
6967
exts = GL.glGetString(GL.GL_EXTENSIONS)
70-
print( exts )
68+
for e in sorted(exts.split()):
69+
print( "\t", e )
70+
print( "GL_VENDOR :",GL.glGetString(GL.GL_VENDOR))
71+
print( "GL_RENDERER:",GL.glGetString(GL.GL_RENDERER))
72+
print( "GL_VERSION :",GL.glGetString(GL.GL_VERSION))
73+
try:
74+
print(" GL_MAJOR_VERSION:", GL.glGetIntegerv( GL.GL_MAJOR_VERSION ))
75+
print(" GL_MINOR_VERSION:", GL.glGetIntegerv( GL.GL_MINOR_VERSION ))
76+
print(" GL_SHADING_LANGUAGE_VERSION :",
77+
GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION))
78+
msk = GL.glGetIntegerv(GL.GL_CONTEXT_PROFILE_MASK)
79+
print(" GL_CONTEXT_CORE_PROFILE_BIT :",
80+
bool( msk & GL.GL_CONTEXT_CORE_PROFILE_BIT) )
81+
print(" GL_CONTEXT_COMPATIBILITY_PROFILE_BIT :",
82+
bool( msk & GL.GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) )
83+
except:
84+
raise
7185

7286
def tkCreateContext( self ):
7387
# Platform dependent part

shader_example.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,6 @@ def initgl(self):
8282
GL.glClearColor(0.15, 0.15, 0.15, 1.0)
8383
GL.glEnable(GL.GL_DEPTH_TEST)
8484
GL.glEnable(GL.GL_PROGRAM_POINT_SIZE)
85-
print("GL_VERSION:",GL.glGetString(GL.GL_VERSION))
86-
print("GLSL_VERSION",GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION))
8785
if not hasattr(self, "shader"):
8886
self.shader = OpenGL.GL.shaders.compileProgram(
8987
OpenGL.GL.shaders.compileShader(vertex_shader, GL.GL_VERTEX_SHADER),
@@ -92,6 +90,7 @@ def initgl(self):
9290
self.vertex_array_object = create_object(self.shader)
9391
self.proj = GL.glGetUniformLocation( self.shader, 'proj')
9492
self.nframes = 0
93+
self.start = time.time()
9594

9695
def redraw(self):
9796
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT)
@@ -105,7 +104,7 @@ def redraw(self):
105104
GL.glBindVertexArray( 0 )
106105
GL.glUseProgram( 0 )
107106
GL.glRasterPos2f(-0.99,-0.99);
108-
if self.nframes > 0:
107+
if self.nframes > 1:
109108
t = time.time()-self.start
110109
fps = "fps: %5.2f frames: %d"%(self.nframes / t, self.nframes)
111110
for c in fps:
@@ -116,9 +115,10 @@ def redraw(self):
116115
def main():
117116
root = tk.Tk()
118117
app = ShaderFrame(root, width=512,height=512)
119-
app.start = time.time()
120118
app.pack(fill=tk.BOTH, expand=tk.YES)
119+
app.after(100, app.printContext)
121120
app.animate=1000//60
121+
app.animate=1
122122
app.mainloop()
123123
if __name__ == '__main__':
124124
main()

0 commit comments

Comments
 (0)