Skip to content

Commit 2971288

Browse files
committed
fixed for chromebook
1 parent 740b845 commit 2971288

File tree

3 files changed

+25
-20
lines changed

3 files changed

+25
-20
lines changed

demo.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ def redraw(self):
4141
app = AppOgl(root, width=320, height=200)
4242
app.pack(fill=BOTH, expand=YES)
4343
app.animate=10
44+
app.after(100, app.printContext)
4445
app.mainloop()

pyopengltk.py

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,7 @@ def tkSwapBuffers( self ):
172172
if sys.platform.startswith( 'linux' ):
173173

174174
from ctypes import c_int, c_char_p, c_void_p, cdll, POINTER
175-
from OpenGL.GLX import GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, \
176-
GLX_BLUE_SIZE, GLX_GREEN_SIZE, GLX_DEPTH_SIZE, glXChooseVisual, \
177-
glXMakeCurrent, glXCreateContext, glXSwapBuffers
175+
from OpenGL import GLX
178176
from OpenGL.raw._GLX import Display
179177

180178
_x11lib = cdll.LoadLibrary('libX11.so' )
@@ -184,34 +182,39 @@ def tkSwapBuffers( self ):
184182

185183
Colormap = c_void_p
186184

187-
att = [ GLX_RGBA, GLX_DOUBLEBUFFER,
188-
GLX_RED_SIZE, 4,
189-
GLX_GREEN_SIZE, 4,
190-
GLX_BLUE_SIZE, 4,
191-
GLX_DEPTH_SIZE, 16,
192-
GL.GLint(0),
185+
att = [ GLX.GLX_RGBA, GLX.GLX_DOUBLEBUFFER,
186+
GLX.GLX_RED_SIZE, 4,
187+
GLX.GLX_GREEN_SIZE, 4,
188+
GLX.GLX_BLUE_SIZE, 4,
189+
GLX.GLX_DEPTH_SIZE, 16,
190+
0,
193191
]
194192

195193
# Inherits the base and fills in the 3 platform dependent functions
196194
class OpenGLFrame( baseOpenGLFrame ):
197195

198196
def tkCreateContext( self ):
199197
self.__window = XOpenDisplay( os.environ.get("DISPLAY") )
200-
visual = glXChooseVisual( self.__window, 0,
198+
major = c_int(0)
199+
minor = c_int(0)
200+
GLX.glXQueryVersion( self.__window, major, minor )
201+
print("GLX version:",major,minor)
202+
visual = GLX.glXChooseVisual( self.__window, 0,
201203
(GL.GLint * len(att))(* att) )
202204
if not visual:
203205
_log.error("glXChooseVisual call failed" )
204-
self.__context = glXCreateContext(self.__window, visual, None,
205-
GL.GL_FALSE)
206-
glXMakeCurrent(self.__window, self._wid, self.__context)
206+
self.__context = GLX.glXCreateContext(self.__window, visual,
207+
None,
208+
GL.GL_TRUE)
209+
GLX.glXMakeCurrent(self.__window, self._wid, self.__context)
207210

208211
def tkMakeCurrent( self ):
209212
if self.winfo_ismapped():
210-
glXMakeCurrent(self.__window, self._wid, self.__context)
213+
GLX.glXMakeCurrent(self.__window, self._wid, self.__context)
211214

212215
def tkSwapBuffers( self ):
213216
if self.winfo_ismapped():
214-
glXSwapBuffers( self.__window, self._wid)
217+
GLX.glXSwapBuffers( self.__window, self._wid)
215218

216219
# Linux/X11 specific code ends
217220
###############################################################################

shader_example.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,20 @@
1515
import Tkinter as tk
1616

1717
vertex_shader = """
18-
#version 330
18+
#version 130
1919
in vec3 position;
2020
varying vec3 vertex_color;
2121
uniform mat3 proj;
2222
void main()
2323
{
24-
gl_Position = vec4( proj*position, 1.0f);
25-
gl_PointSize = 4.f/(0.5f + length( position ));
24+
gl_Position = vec4( proj*position, 1.0);
25+
gl_PointSize = 4./(0.5 + length( position ));
2626
vertex_color = vec3( position.x/2+.5, position.y/2+.5, position.z/2+.5);
2727
}
2828
"""
2929

3030
fragment_shader = """
31-
#version 330
31+
#version 130
3232
varying vec3 vertex_color;
3333
void main()
3434
{
@@ -82,7 +82,8 @@ 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.glGetString(GL.GL_VERSION))
85+
print("GL_VERSION:",GL.glGetString(GL.GL_VERSION))
86+
print("GLSL_VERSION",GL.glGetString(GL.GL_SHADING_LANGUAGE_VERSION))
8687
if not hasattr(self, "shader"):
8788
self.shader = OpenGL.GL.shaders.compileProgram(
8889
OpenGL.GL.shaders.compileShader(vertex_shader, GL.GL_VERTEX_SHADER),

0 commit comments

Comments
 (0)