Index: GLCtrl/GLCtrl.cpp
===================================================================
--- GLCtrl/GLCtrl.cpp	(wersja 8215)
+++ GLCtrl/GLCtrl.cpp	(kopia robocza)
@@ -25,8 +25,6 @@
 	glLoadIdentity();
 }
 
-#ifndef GUI_GTK
-
 Image GLCtrl::GLPane::MouseEvent(int event, Point p, int zdelta, dword keyflags)
 {
 	p = p - GetScreenView().TopLeft() + ctrl->GetScreenView().TopLeft();
@@ -33,6 +31,8 @@
 	return ctrl->MouseEvent(event, p, zdelta, keyflags);
 }
 
+#ifndef GUI_GTK
+
 Vector<int> GLCtrl::Pick(int x, int y)
 {
 	pane.ActivateContext();
Index: GLCtrl/GLCtrl.h
===================================================================
--- GLCtrl/GLCtrl.h	(wersja 8215)
+++ GLCtrl/GLCtrl.h	(kopia robocza)
@@ -25,25 +25,15 @@
 #undef  Display
 #endif
 
-NAMESPACE_UPP
-
 #ifdef GUI_GTK
 
-class GLCtrl : public Ctrl {
-public:
-	virtual void Paint(Draw& w);
+#include <gtk/gtkgl.h>
+#include <gdk/gdkgl.h>
 
-public:
-	Callback WhenGLPaint;
+#endif
 
-	virtual void GLPaint();
-	virtual void GLResize(int w, int h);
+NAMESPACE_UPP
 
-	void StdView();
-};
-
-#else
-
 class GLCtrl : public Ctrl {
 	typedef GLCtrl CLASSNAME;
 	
@@ -64,7 +54,7 @@
 		GLPicking() : _isPicking(false) {}
 	};
 	
-#ifdef GUI_X11
+#if defined(GUI_X11)
 	class GLPane : public DHCtrl {
 		friend class GLCtrl;
 		
@@ -96,14 +86,42 @@
 		
 		void ActivateContext();
 	};
-#else
-	struct GLPane : DHCtrl {
+#elif defined(GUI_GTK)
+	class GLPane : Ctrl {
 		friend class GLCtrl;
 		
-		HDC    hDC;
-		HGLRC  hRC;
+	public:
+		GLPane();
+		~GLPane();
+		
+		virtual void Layout();
+		virtual void Paint(Draw &);
+		
+		virtual Image MouseEvent(int event, Point p, int zdelta, dword keyflags);
+		
+	private:
+		void InitGdkGLConfig();
+	
+		void InitGTKVariables();
+		void ReleaseGTKVariables();
+		
+	private:
 		GLCtrl *ctrl;
 		
+		GtkWindow *gtk;
+		GdkWindow *win;
+		
+		GdkGLConfig *sGlconfig;
+		
+		GdkPixmap *pixmap;
+		GdkGLDrawable *gldrawable;
+		GdkGLContext *glcontext;
+	};
+	
+#elif defined(GUI_WIN)
+	class GLPane : DHCtrl {
+		friend class GLCtrl;
+		
 	public:
 		GLPane() : hDC(NULL), hRC(NULL) { NoWantFocus(); }
 		~GLPane() { Destroy(); }
@@ -116,6 +134,11 @@
 		void Destroy();
 		
 		void ActivateContext();
+	
+	private:
+		HDC    hDC;
+		HGLRC  hRC;
+		GLCtrl *ctrl;
 	};
 #endif
 	
@@ -166,8 +189,6 @@
 	Vector<int> Pick(int x, int y);
 };
 
-#endif
-
 END_UPP_NAMESPACE
 
 #endif
Index: GLCtrl/GtkGLCtrl.cpp
===================================================================
--- GLCtrl/GtkGLCtrl.cpp	(wersja 8215)
+++ GLCtrl/GtkGLCtrl.cpp	(kopia robocza)
@@ -2,66 +2,105 @@
 
 #ifdef GUI_GTK
 
-#include <gtk/gtkgl.h>
-#include <gdk/gdkgl.h>
 #include <gdk/gdkglconfig.h>
 
 NAMESPACE_UPP
 
-GdkGLConfig *sGlconfig;
+GLCtrl::GLPane::GLPane()
+{
+	ctrl = NULL;
+	
+	sGlconfig = NULL;
+	
+	pixmap = NULL;
+	gldrawable = NULL;
+	glcontext = NULL;
+	
+	gtk = NULL;
+	win = NULL;
+}
 
-EXITBLOCK {
+GLCtrl::GLPane::~GLPane()
+{
 	if(sGlconfig)
-	    g_object_unref(G_OBJECT(sGlconfig));
+		g_object_unref(G_OBJECT(sGlconfig));
+	
+	ReleaseGTKVariables();
 }
 
-void GLCtrl::GLPaint()
+void GLCtrl::GLPane::Layout()
 {
-	WhenGLPaint();
+	InitGdkGLConfig();
+	
+	ReleaseGTKVariables();
+	InitGTKVariables();
 }
 
-void GLCtrl::Paint(Draw& w)
-{
+void GLCtrl::GLPane::Paint(Draw& w)
+{	
 	Size sz = GetSize();
 	
-	Ctrl *top = GetTopCtrl();
-	if(!top)
-		return;
+	if(glcontext) {
+		if(gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
+			glViewport(0, 0, sz.cx, sz.cy);
+			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+			ctrl->GLPaint();
+			if(gdk_gl_config_is_double_buffered(sGlconfig))
+				gdk_gl_drawable_swap_buffers(gldrawable);
+			else
+				glFlush ();
+			gdk_gl_drawable_gl_end(gldrawable);
 
-	GtkWindow *gtk = top->gtk();
-	GdkWindow *win = top->gdk();
+			Rect r = GetScreenView() - GetTopCtrl()->GetScreenView().TopLeft();
+			GtkWidget *widget = GTK_WIDGET(gtk);
+			gdk_draw_drawable(win, widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
+					          pixmap, 0, 0, r.left, r.top, r.GetWidth(), r.GetHeight());
+		}
+	}
+}
 
-	if(sz.cx <= 0 || sz.cy <= 0 || !win || !gtk)
+void GLCtrl::GLPane::InitGdkGLConfig()
+{
+	if(sGlconfig)
 		return;
+	
+	int glConfig = GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_SINGLE;
+	if(ctrl) {
+		
+	}
+	sGlconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)glConfig);
+}
 
-	ONCELOCK {
-		sGlconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode)(GDK_GL_MODE_RGB|GDK_GL_MODE_DEPTH|GDK_GL_MODE_SINGLE));
+void GLCtrl::GLPane::InitGTKVariables()
+{
+	if(win == NULL && gtk == NULL) {
+		Ctrl *top = GetTopCtrl();
+		if (!top)
+			return;	
+		gtk = top->gtk();
+		win = top->gdk();
 	}
+	
+	Size sz = GetSize();
+	pixmap = gdk_pixmap_new(win, sz.cx, sz.cy, -1);
+	if (pixmap == NULL)
+		return;
+	
+	gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, sGlconfig, NULL));
+	if (gldrawable == NULL)
+		return;
+	
+	glcontext = gdk_gl_context_new(gldrawable, NULL, FALSE, GDK_GL_RGBA_TYPE);
+}
 
-	GdkPixmap *pixmap = gdk_pixmap_new(win, sz.cx, sz.cy, -1);
-	if(pixmap) {
-		GdkGLDrawable *gldrawable = GDK_GL_DRAWABLE(gdk_pixmap_set_gl_capability(pixmap, sGlconfig, NULL));
-		if(gldrawable) {
-			GdkGLContext *glcontext = gdk_gl_context_new(gldrawable, NULL, FALSE, GDK_GL_RGBA_TYPE);
-			if(glcontext) {
-				if(gdk_gl_drawable_gl_begin(gldrawable, glcontext)) {
-					glViewport(0, 0, sz.cx, sz.cy);
-					glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-					GLPaint();
-					glFlush ();
-					gdk_gl_drawable_gl_end(gldrawable);
-
-					Rect r = GetScreenView() - GetTopCtrl()->GetScreenView().TopLeft();
-					GtkWidget *widget = GTK_WIDGET(gtk);
-					gdk_draw_drawable(win, widget->style->fg_gc[GTK_WIDGET_STATE (widget)],
-					                  pixmap, 0, 0, r.left, r.top, r.GetWidth(), r.GetHeight());
-				}
-				g_object_unref(G_OBJECT(glcontext));
-			}
-			g_object_unref(G_OBJECT(gldrawable));
-		}
+void GLCtrl::GLPane::ReleaseGTKVariables()
+{
+	if(glcontext)
+		gdk_gl_context_destroy(glcontext);
+	if(gldrawable)
+		g_object_unref(G_OBJECT(gldrawable));
+	if(pixmap)
 		g_object_unref(G_OBJECT(pixmap));
-	}
 }
 
 END_UPP_NAMESPACE
