diff --git a/kivy/c_ext/graphics.pyx b/kivy/c_ext/graphics.pyx index 1cdc9a956..17f80c8a8 100644 --- a/kivy/c_ext/graphics.pyx +++ b/kivy/c_ext/graphics.pyx @@ -204,6 +204,10 @@ cdef class Shader: else: Logger.debug('Shader compiled sucessfully') +def Context_instance(): + global _default_context + print 'get', _default_context + return _default_context cdef class GraphicContext: '''Handle the saving/restore of the context @@ -224,6 +228,8 @@ cdef class GraphicContext: self._default_shader = Shader(_default_vertex_shader, _default_fragment_shader) return self._default_shader + instance = staticmethod(Context_instance) + def __cinit__(self): self.state = {} self.stack = [] @@ -393,6 +399,7 @@ cdef class Canvas: cdef list batch_slices def __cinit__(self): + global _default_context if _default_context == None: _default_context = GraphicContext() self._context = _default_context diff --git a/kivy/core/window/__init__.py b/kivy/core/window/__init__.py index ce0d3996f..f0a7a6a69 100644 --- a/kivy/core/window/__init__.py +++ b/kivy/core/window/__init__.py @@ -304,6 +304,10 @@ class WindowBase(EventDispatcher): def update_viewport(self): # XXX FIXME from kivy.core.gl import * + from kivy.graphics import GraphicContext + from kivy.lib.transformations import clip_matrix + context = GraphicContext.instance() + context.set('projection_mat', clip_matrix(0, self.width, 0, self.height, -1, 1)) width, height = self.system_size w2 = width / 2. @@ -312,13 +316,9 @@ class WindowBase(EventDispatcher): # prepare the viewport glViewport(0, 0, width, height) - # set the projection - glMatrixMode(GL_PROJECTION) - glLoadIdentity() - glFrustum(-w2, w2, -h2, h2, .1, 1000) - glScalef(5000, 5000, 1) - # use the rotated size. + # XXX FIXME fix rotation + ''' width, height = self.size w2 = width / 2. h2 = height / 2. @@ -330,6 +330,7 @@ class WindowBase(EventDispatcher): glTranslatef(w2, h2, 0) glRotatef(self._rotation, 0, 0, 1) glTranslatef(-w2, -h2, 0) + ''' # update window size for w in self.children: diff --git a/kivy/uix/widget.py b/kivy/uix/widget.py index ecefc7055..3a19194c2 100644 --- a/kivy/uix/widget.py +++ b/kivy/uix/widget.py @@ -12,9 +12,8 @@ __all__ = ('Widget', ) from kivy.weakmethod import WeakMethod from kivy.c_ext.event import EventDispatcher from kivy.c_ext.properties import * -from kivy.base import EventLoop -EventLoop.ensure_window() from kivy.graphics import Canvas +from kivy.base import EventLoop class Widget(EventDispatcher): ''' @@ -64,6 +63,7 @@ class Widget(EventDispatcher): self.register_event_type('on_touch_up') self.register_event_type('on_draw') + EventLoop.ensure_window() self.canvas = Canvas()