gfx/gui (win32): Fixed warning with latest MinGW-w64 headers
[sdk] / ecere / src / gfx / drivers / OpenGLDisplayDriver.ec
index 00acaef..edc6447 100644 (file)
@@ -69,7 +69,7 @@ namespace gfx::drivers;
 #if defined(__WIN32__)
 #define WIN32_LEAN_AND_MEAN
 #undef _WIN32_WINNT
-#define _WIN32_WINNT 0x0500
+#define _WIN32_WINNT 0x0502
 #define String Sting_
 #include <windows.h>
 #undef String
@@ -149,160 +149,160 @@ static double nearPlane = 1;
 #define WGL_SAMPLE_BUFFERS_ARB              0x2041
 #define WGL_SAMPLES_ARB                     0x2042
 
-#define  WGL_WGLEXT_VERSION   1 
-#define  WGL_FRONT_COLOR_BUFFER_BIT_ARB   0x00000001 
-#define  WGL_BACK_COLOR_BUFFER_BIT_ARB   0x00000002 
-#define  WGL_DEPTH_BUFFER_BIT_ARB   0x00000004 
-#define  WGL_STENCIL_BUFFER_BIT_ARB   0x00000008 
-#define  WGL_NUMBER_PIXEL_FORMATS_ARB   0x2000 
-#define  WGL_DRAW_TO_WINDOW_ARB   0x2001 
-#define  WGL_DRAW_TO_BITMAP_ARB   0x2002 
-#define  WGL_ACCELERATION_ARB   0x2003 
-#define  WGL_NEED_PALETTE_ARB   0x2004 
-#define  WGL_NEED_SYSTEM_PALETTE_ARB   0x2005 
-#define  WGL_SWAP_LAYER_BUFFERS_ARB   0x2006 
-#define  WGL_SWAP_METHOD_ARB   0x2007 
-#define  WGL_NUMBER_OVERLAYS_ARB   0x2008 
-#define  WGL_NUMBER_UNDERLAYS_ARB   0x2009 
-#define  WGL_TRANSPARENT_ARB   0x200A 
-#define  WGL_TRANSPARENT_RED_VALUE_ARB   0x2037 
-#define  WGL_TRANSPARENT_GREEN_VALUE_ARB   0x2038 
-#define  WGL_TRANSPARENT_BLUE_VALUE_ARB   0x2039 
-#define  WGL_TRANSPARENT_ALPHA_VALUE_ARB   0x203A 
-#define  WGL_TRANSPARENT_INDEX_VALUE_ARB   0x203B 
-#define  WGL_SHARE_DEPTH_ARB   0x200C 
-#define  WGL_SHARE_STENCIL_ARB   0x200D 
-#define  WGL_SHARE_ACCUM_ARB   0x200E 
-#define  WGL_SUPPORT_GDI_ARB   0x200F 
-#define  WGL_SUPPORT_OPENGL_ARB   0x2010 
-#define  WGL_DOUBLE_BUFFER_ARB   0x2011 
-#define  WGL_STEREO_ARB   0x2012 
-#define  WGL_PIXEL_TYPE_ARB   0x2013 
-#define  WGL_COLOR_BITS_ARB   0x2014 
-#define  WGL_RED_BITS_ARB   0x2015 
-#define  WGL_RED_SHIFT_ARB   0x2016 
-#define  WGL_GREEN_BITS_ARB   0x2017 
-#define  WGL_GREEN_SHIFT_ARB   0x2018 
-#define  WGL_BLUE_BITS_ARB   0x2019 
-#define  WGL_BLUE_SHIFT_ARB   0x201A 
-#define  WGL_ALPHA_BITS_ARB   0x201B 
-#define  WGL_ALPHA_SHIFT_ARB   0x201C 
-#define  WGL_ACCUM_BITS_ARB   0x201D 
-#define  WGL_ACCUM_RED_BITS_ARB   0x201E 
-#define  WGL_ACCUM_GREEN_BITS_ARB   0x201F 
-#define  WGL_ACCUM_BLUE_BITS_ARB   0x2020 
-#define  WGL_ACCUM_ALPHA_BITS_ARB   0x2021 
-#define  WGL_DEPTH_BITS_ARB   0x2022 
-#define  WGL_STENCIL_BITS_ARB   0x2023 
-#define  WGL_AUX_BUFFERS_ARB   0x2024 
-#define  WGL_NO_ACCELERATION_ARB   0x2025 
-#define  WGL_GENERIC_ACCELERATION_ARB   0x2026 
-#define  WGL_FULL_ACCELERATION_ARB   0x2027 
-#define  WGL_SWAP_EXCHANGE_ARB   0x2028 
-#define  WGL_SWAP_COPY_ARB   0x2029 
-#define  WGL_SWAP_UNDEFINED_ARB   0x202A 
-#define  WGL_TYPE_RGBA_ARB   0x202B 
-#define  WGL_TYPE_COLORINDEX_ARB   0x202C 
-#define  ERROR_INVALID_PIXEL_TYPE_ARB   0x2043 
-#define  ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB   0x2054 
-#define  WGL_DRAW_TO_PBUFFER_ARB   0x202D 
-#define  WGL_MAX_PBUFFER_PIXELS_ARB   0x202E 
-#define  WGL_MAX_PBUFFER_WIDTH_ARB   0x202F 
-#define  WGL_MAX_PBUFFER_HEIGHT_ARB   0x2030 
-#define  WGL_PBUFFER_LARGEST_ARB   0x2033 
-#define  WGL_PBUFFER_WIDTH_ARB   0x2034 
-#define  WGL_PBUFFER_HEIGHT_ARB   0x2035 
-#define  WGL_PBUFFER_LOST_ARB   0x2036 
-#define  ERROR_INVALID_PIXEL_TYPE_EXT   0x2043 
-#define  WGL_NUMBER_PIXEL_FORMATS_EXT   0x2000 
-#define  WGL_DRAW_TO_WINDOW_EXT   0x2001 
-#define  WGL_DRAW_TO_BITMAP_EXT   0x2002 
-#define  WGL_ACCELERATION_EXT   0x2003 
-#define  WGL_NEED_PALETTE_EXT   0x2004 
-#define  WGL_NEED_SYSTEM_PALETTE_EXT   0x2005 
-#define  WGL_SWAP_LAYER_BUFFERS_EXT   0x2006 
-#define  WGL_SWAP_METHOD_EXT   0x2007 
-#define  WGL_NUMBER_OVERLAYS_EXT   0x2008 
-#define  WGL_NUMBER_UNDERLAYS_EXT   0x2009 
-#define  WGL_TRANSPARENT_EXT   0x200A 
-#define  WGL_TRANSPARENT_VALUE_EXT   0x200B 
-#define  WGL_SHARE_DEPTH_EXT   0x200C 
-#define  WGL_SHARE_STENCIL_EXT   0x200D 
-#define  WGL_SHARE_ACCUM_EXT   0x200E 
-#define  WGL_SUPPORT_GDI_EXT   0x200F 
-#define  WGL_SUPPORT_OPENGL_EXT   0x2010 
-#define  WGL_DOUBLE_BUFFER_EXT   0x2011 
-#define  WGL_STEREO_EXT   0x2012 
-#define  WGL_PIXEL_TYPE_EXT   0x2013 
-#define  WGL_COLOR_BITS_EXT   0x2014 
-#define  WGL_RED_BITS_EXT   0x2015 
-#define  WGL_RED_SHIFT_EXT   0x2016 
-#define  WGL_GREEN_BITS_EXT   0x2017 
-#define  WGL_GREEN_SHIFT_EXT   0x2018 
-#define  WGL_BLUE_BITS_EXT   0x2019 
-#define  WGL_BLUE_SHIFT_EXT   0x201A 
-#define  WGL_ALPHA_BITS_EXT   0x201B 
-#define  WGL_ALPHA_SHIFT_EXT   0x201C 
-#define  WGL_ACCUM_BITS_EXT   0x201D 
-#define  WGL_ACCUM_RED_BITS_EXT   0x201E 
-#define  WGL_ACCUM_GREEN_BITS_EXT   0x201F 
-#define  WGL_ACCUM_BLUE_BITS_EXT   0x2020 
-#define  WGL_ACCUM_ALPHA_BITS_EXT   0x2021 
-#define  WGL_DEPTH_BITS_EXT   0x2022 
-#define  WGL_STENCIL_BITS_EXT   0x2023 
-#define  WGL_AUX_BUFFERS_EXT   0x2024 
-#define  WGL_NO_ACCELERATION_EXT   0x2025 
-#define  WGL_GENERIC_ACCELERATION_EXT   0x2026 
-#define  WGL_FULL_ACCELERATION_EXT   0x2027 
-#define  WGL_SWAP_EXCHANGE_EXT   0x2028 
-#define  WGL_SWAP_COPY_EXT   0x2029 
-#define  WGL_SWAP_UNDEFINED_EXT   0x202A 
-#define  WGL_TYPE_RGBA_EXT   0x202B 
-#define  WGL_TYPE_COLORINDEX_EXT   0x202C 
-#define  WGL_DRAW_TO_PBUFFER_EXT   0x202D 
-#define  WGL_MAX_PBUFFER_PIXELS_EXT   0x202E 
-#define  WGL_MAX_PBUFFER_WIDTH_EXT   0x202F 
-#define  WGL_MAX_PBUFFER_HEIGHT_EXT   0x2030 
-#define  WGL_OPTIMAL_PBUFFER_WIDTH_EXT   0x2031 
-#define  WGL_OPTIMAL_PBUFFER_HEIGHT_EXT   0x2032 
-#define  WGL_PBUFFER_LARGEST_EXT   0x2033 
-#define  WGL_PBUFFER_WIDTH_EXT   0x2034 
-#define  WGL_PBUFFER_HEIGHT_EXT   0x2035 
-#define  WGL_DEPTH_FLOAT_EXT   0x2040 
-#define  WGL_SAMPLE_BUFFERS_3DFX   0x2060 
-#define  WGL_SAMPLES_3DFX   0x2061 
-#define  WGL_SAMPLE_BUFFERS_EXT   0x2041 
-#define  WGL_SAMPLES_EXT   0x2042 
-#define  WGL_GENLOCK_SOURCE_MULTIVIEW_I3D   0x2044 
-#define  WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D   0x2045 
-#define  WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D   0x2046 
-#define  WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D   0x2047 
-#define  WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D   0x2048 
-#define  WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D   0x2049 
-#define  WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D   0x204A 
-#define  WGL_GENLOCK_SOURCE_EDGE_RISING_I3D   0x204B 
-#define  WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D   0x204C 
-#define  WGL_GAMMA_TABLE_SIZE_I3D   0x204E 
-#define  WGL_GAMMA_EXCLUDE_DESKTOP_I3D   0x204F 
-#define  WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D   0x2050 
-#define  WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D   0x2051 
-#define  WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D   0x2052 
-#define  WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D   0x2053 
-#define  WGL_ARB_buffer_region   1 
-#define  WGL_ARB_extensions_string   1 
-#define  WGL_ARB_pixel_format   1 
-#define  WGL_ARB_make_current_read   1 
-#define  WGL_ARB_pbuffer   1 
-#define  WGL_EXT_display_color_table   1 
-#define  WGL_EXT_extensions_string   1 
-#define  WGL_EXT_make_current_read   1 
-#define  WGL_EXT_pbuffer   1 
-#define  WGL_EXT_pixel_format   1 
-#define  WGL_EXT_swap_control   1 
-#define  WGL_WGL_EXT_depth_float   1 
-#define  WGL_WGL_3DFX_multisample   1 
-#define  WGL_WGL_EXT_multisample   1 
-#define  WGL_NV_allocate_memory   1 
+#define  WGL_WGLEXT_VERSION   1
+#define  WGL_FRONT_COLOR_BUFFER_BIT_ARB   0x00000001
+#define  WGL_BACK_COLOR_BUFFER_BIT_ARB   0x00000002
+#define  WGL_DEPTH_BUFFER_BIT_ARB   0x00000004
+#define  WGL_STENCIL_BUFFER_BIT_ARB   0x00000008
+#define  WGL_NUMBER_PIXEL_FORMATS_ARB   0x2000
+#define  WGL_DRAW_TO_WINDOW_ARB   0x2001
+#define  WGL_DRAW_TO_BITMAP_ARB   0x2002
+#define  WGL_ACCELERATION_ARB   0x2003
+#define  WGL_NEED_PALETTE_ARB   0x2004
+#define  WGL_NEED_SYSTEM_PALETTE_ARB   0x2005
+#define  WGL_SWAP_LAYER_BUFFERS_ARB   0x2006
+#define  WGL_SWAP_METHOD_ARB   0x2007
+#define  WGL_NUMBER_OVERLAYS_ARB   0x2008
+#define  WGL_NUMBER_UNDERLAYS_ARB   0x2009
+#define  WGL_TRANSPARENT_ARB   0x200A
+#define  WGL_TRANSPARENT_RED_VALUE_ARB   0x2037
+#define  WGL_TRANSPARENT_GREEN_VALUE_ARB   0x2038
+#define  WGL_TRANSPARENT_BLUE_VALUE_ARB   0x2039
+#define  WGL_TRANSPARENT_ALPHA_VALUE_ARB   0x203A
+#define  WGL_TRANSPARENT_INDEX_VALUE_ARB   0x203B
+#define  WGL_SHARE_DEPTH_ARB   0x200C
+#define  WGL_SHARE_STENCIL_ARB   0x200D
+#define  WGL_SHARE_ACCUM_ARB   0x200E
+#define  WGL_SUPPORT_GDI_ARB   0x200F
+#define  WGL_SUPPORT_OPENGL_ARB   0x2010
+#define  WGL_DOUBLE_BUFFER_ARB   0x2011
+#define  WGL_STEREO_ARB   0x2012
+#define  WGL_PIXEL_TYPE_ARB   0x2013
+#define  WGL_COLOR_BITS_ARB   0x2014
+#define  WGL_RED_BITS_ARB   0x2015
+#define  WGL_RED_SHIFT_ARB   0x2016
+#define  WGL_GREEN_BITS_ARB   0x2017
+#define  WGL_GREEN_SHIFT_ARB   0x2018
+#define  WGL_BLUE_BITS_ARB   0x2019
+#define  WGL_BLUE_SHIFT_ARB   0x201A
+#define  WGL_ALPHA_BITS_ARB   0x201B
+#define  WGL_ALPHA_SHIFT_ARB   0x201C
+#define  WGL_ACCUM_BITS_ARB   0x201D
+#define  WGL_ACCUM_RED_BITS_ARB   0x201E
+#define  WGL_ACCUM_GREEN_BITS_ARB   0x201F
+#define  WGL_ACCUM_BLUE_BITS_ARB   0x2020
+#define  WGL_ACCUM_ALPHA_BITS_ARB   0x2021
+#define  WGL_DEPTH_BITS_ARB   0x2022
+#define  WGL_STENCIL_BITS_ARB   0x2023
+#define  WGL_AUX_BUFFERS_ARB   0x2024
+#define  WGL_NO_ACCELERATION_ARB   0x2025
+#define  WGL_GENERIC_ACCELERATION_ARB   0x2026
+#define  WGL_FULL_ACCELERATION_ARB   0x2027
+#define  WGL_SWAP_EXCHANGE_ARB   0x2028
+#define  WGL_SWAP_COPY_ARB   0x2029
+#define  WGL_SWAP_UNDEFINED_ARB   0x202A
+#define  WGL_TYPE_RGBA_ARB   0x202B
+#define  WGL_TYPE_COLORINDEX_ARB   0x202C
+#define  ERROR_INVALID_PIXEL_TYPE_ARB   0x2043
+#define  ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB   0x2054
+#define  WGL_DRAW_TO_PBUFFER_ARB   0x202D
+#define  WGL_MAX_PBUFFER_PIXELS_ARB   0x202E
+#define  WGL_MAX_PBUFFER_WIDTH_ARB   0x202F
+#define  WGL_MAX_PBUFFER_HEIGHT_ARB   0x2030
+#define  WGL_PBUFFER_LARGEST_ARB   0x2033
+#define  WGL_PBUFFER_WIDTH_ARB   0x2034
+#define  WGL_PBUFFER_HEIGHT_ARB   0x2035
+#define  WGL_PBUFFER_LOST_ARB   0x2036
+#define  ERROR_INVALID_PIXEL_TYPE_EXT   0x2043
+#define  WGL_NUMBER_PIXEL_FORMATS_EXT   0x2000
+#define  WGL_DRAW_TO_WINDOW_EXT   0x2001
+#define  WGL_DRAW_TO_BITMAP_EXT   0x2002
+#define  WGL_ACCELERATION_EXT   0x2003
+#define  WGL_NEED_PALETTE_EXT   0x2004
+#define  WGL_NEED_SYSTEM_PALETTE_EXT   0x2005
+#define  WGL_SWAP_LAYER_BUFFERS_EXT   0x2006
+#define  WGL_SWAP_METHOD_EXT   0x2007
+#define  WGL_NUMBER_OVERLAYS_EXT   0x2008
+#define  WGL_NUMBER_UNDERLAYS_EXT   0x2009
+#define  WGL_TRANSPARENT_EXT   0x200A
+#define  WGL_TRANSPARENT_VALUE_EXT   0x200B
+#define  WGL_SHARE_DEPTH_EXT   0x200C
+#define  WGL_SHARE_STENCIL_EXT   0x200D
+#define  WGL_SHARE_ACCUM_EXT   0x200E
+#define  WGL_SUPPORT_GDI_EXT   0x200F
+#define  WGL_SUPPORT_OPENGL_EXT   0x2010
+#define  WGL_DOUBLE_BUFFER_EXT   0x2011
+#define  WGL_STEREO_EXT   0x2012
+#define  WGL_PIXEL_TYPE_EXT   0x2013
+#define  WGL_COLOR_BITS_EXT   0x2014
+#define  WGL_RED_BITS_EXT   0x2015
+#define  WGL_RED_SHIFT_EXT   0x2016
+#define  WGL_GREEN_BITS_EXT   0x2017
+#define  WGL_GREEN_SHIFT_EXT   0x2018
+#define  WGL_BLUE_BITS_EXT   0x2019
+#define  WGL_BLUE_SHIFT_EXT   0x201A
+#define  WGL_ALPHA_BITS_EXT   0x201B
+#define  WGL_ALPHA_SHIFT_EXT   0x201C
+#define  WGL_ACCUM_BITS_EXT   0x201D
+#define  WGL_ACCUM_RED_BITS_EXT   0x201E
+#define  WGL_ACCUM_GREEN_BITS_EXT   0x201F
+#define  WGL_ACCUM_BLUE_BITS_EXT   0x2020
+#define  WGL_ACCUM_ALPHA_BITS_EXT   0x2021
+#define  WGL_DEPTH_BITS_EXT   0x2022
+#define  WGL_STENCIL_BITS_EXT   0x2023
+#define  WGL_AUX_BUFFERS_EXT   0x2024
+#define  WGL_NO_ACCELERATION_EXT   0x2025
+#define  WGL_GENERIC_ACCELERATION_EXT   0x2026
+#define  WGL_FULL_ACCELERATION_EXT   0x2027
+#define  WGL_SWAP_EXCHANGE_EXT   0x2028
+#define  WGL_SWAP_COPY_EXT   0x2029
+#define  WGL_SWAP_UNDEFINED_EXT   0x202A
+#define  WGL_TYPE_RGBA_EXT   0x202B
+#define  WGL_TYPE_COLORINDEX_EXT   0x202C
+#define  WGL_DRAW_TO_PBUFFER_EXT   0x202D
+#define  WGL_MAX_PBUFFER_PIXELS_EXT   0x202E
+#define  WGL_MAX_PBUFFER_WIDTH_EXT   0x202F
+#define  WGL_MAX_PBUFFER_HEIGHT_EXT   0x2030
+#define  WGL_OPTIMAL_PBUFFER_WIDTH_EXT   0x2031
+#define  WGL_OPTIMAL_PBUFFER_HEIGHT_EXT   0x2032
+#define  WGL_PBUFFER_LARGEST_EXT   0x2033
+#define  WGL_PBUFFER_WIDTH_EXT   0x2034
+#define  WGL_PBUFFER_HEIGHT_EXT   0x2035
+#define  WGL_DEPTH_FLOAT_EXT   0x2040
+#define  WGL_SAMPLE_BUFFERS_3DFX   0x2060
+#define  WGL_SAMPLES_3DFX   0x2061
+#define  WGL_SAMPLE_BUFFERS_EXT   0x2041
+#define  WGL_SAMPLES_EXT   0x2042
+#define  WGL_GENLOCK_SOURCE_MULTIVIEW_I3D   0x2044
+#define  WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D   0x2045
+#define  WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D   0x2046
+#define  WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D   0x2047
+#define  WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D   0x2048
+#define  WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D   0x2049
+#define  WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D   0x204A
+#define  WGL_GENLOCK_SOURCE_EDGE_RISING_I3D   0x204B
+#define  WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D   0x204C
+#define  WGL_GAMMA_TABLE_SIZE_I3D   0x204E
+#define  WGL_GAMMA_EXCLUDE_DESKTOP_I3D   0x204F
+#define  WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D   0x2050
+#define  WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D   0x2051
+#define  WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D   0x2052
+#define  WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D   0x2053
+#define  WGL_ARB_buffer_region   1
+#define  WGL_ARB_extensions_string   1
+#define  WGL_ARB_pixel_format   1
+#define  WGL_ARB_make_current_read   1
+#define  WGL_ARB_pbuffer   1
+#define  WGL_EXT_display_color_table   1
+#define  WGL_EXT_extensions_string   1
+#define  WGL_EXT_make_current_read   1
+#define  WGL_EXT_pbuffer   1
+#define  WGL_EXT_pixel_format   1
+#define  WGL_EXT_swap_control   1
+#define  WGL_WGL_EXT_depth_float   1
+#define  WGL_WGL_3DFX_multisample   1
+#define  WGL_WGL_EXT_multisample   1
+#define  WGL_NV_allocate_memory   1
 
 /*
 typedef void (APIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum target);
@@ -324,6 +324,9 @@ typedef HDC (APIENTRY * PFNWGLGETPBUFFERDCARBPROC) (void * hPbuffer);
 typedef int (APIENTRY * PFNWGLRELEASEPBUFFERDCARBPROC) (void * hPbuffer, HDC hDC);
 typedef BOOL (APIENTRY * PFNWGLDESTROYPBUFFERARBPROC) (void * hPbuffer);
 typedef BOOL (APIENTRY * PFNWGLQUERYPBUFFERARBPROC) (void * hPbuffer, int iAttribute, int *piValue);
+typedef const char * (APIENTRY * PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
+typedef BOOL (APIENTRY * PFNWGLBINDTEXIMAGEARBPROC) (void * hPbuffer, int iBuffer);
+typedef BOOL (APIENTRY * PFNWGLRELEASETEXIMAGEARBPROC) (void * hPbuffer, int iBuffer);
 
 static PFNGLMAPBUFFERARBPROC glMapBufferARB = null;
 static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = null;
@@ -462,7 +465,7 @@ static bool egl_init_display(ANativeWindow* window)
       EGL_SAMPLES, 0, //2,*/
       EGL_NONE
    };
-   EGLint w, h, dummy, format;
+   EGLint w, h, format;
    EGLint numConfigs;
    EGLConfig config;
    EGLSurface surface;
@@ -525,13 +528,13 @@ static bool egl_init_display(ANativeWindow* window)
 
    currentVertexBuffer = 0;
    return true;
-}  
+}
 
 static void egl_term_display()
 {
    if(stippleTexture)
    {
-      glDeleteTextures(1, (int *)&stippleTexture);
+      glDeleteTextures(1, &stippleTexture);
       stippleTexture = 0;
    }
    if(eglDisplay != EGL_NO_DISPLAY)
@@ -604,7 +607,7 @@ void glesTexCoord2f(float x, float y)
       vertexPointer[count*(2+numVertexCoords)+1] = vertexPointer[(count-3)*(2+numVertexCoords)+1];
       count++;
    }
-} 
+}
 void glesTexCoord2i(int x, int y)       { glesTexCoord2f((float)x, (float)y); }
 void glesTexCoord2d(double x, double y) { glesTexCoord2f((float)x, (float)y); }
 void glesTexCoord2fv(float * a)         { glesTexCoord2f(a[0], a[1]); }
@@ -808,13 +811,14 @@ void glesLoadMatrixd(double * i)
 
 void glesOrtho( double l, double r, double b, double t, double n, double f )
 {
-   Matrix m =
+   Matrix m
    { {
       (2 / (r - l)), 0, 0, 0,
       0, (2 / (t - b)), 0, 0,
       0, 0, (-2 / (f - n)), 0,
       (-(r + l) / (r - l)), (-(t + b) / (t - b)), (-(f + n) / (f - n)), 1
-   } }, res;
+   } };
+   Matrix res;
    res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
    matrixStack[curStack][matrixIndex[curStack]] = res;
    LoadCurMatrix();
@@ -834,13 +838,14 @@ void glesFrustum( double l, double r, double b, double t, double n, double f )
       double B = ((t + b) / (t - b));
       double C = (-(f + n) / (f - n));
       double D = (-2*f*n/(f-n));
-      Matrix m =
+      Matrix m
       { {
          (2.0*n / (r - l)), 0, 0, 0,
          0, (2.0*n / (t - b)), 0, 0,
          A, B,             C,-1,
          0, 0,             D, 0
-      } }, res;
+      } };
+      Matrix res;
       res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
       matrixStack[curStack][matrixIndex[curStack]] = res;
       LoadCurMatrix();
@@ -914,7 +919,7 @@ void glesOrtho( double l, double r, double b, double t, double n, double f )
 {
    float matrix[4][4] =
    {
-      { (float)(2 / (r - l)), 0, 0, 0 }, 
+      { (float)(2 / (r - l)), 0, 0, 0 },
       { 0, (float)(2 / (t - b)), 0, 0 },
       { 0, 0, (float)(-2 / (f - n)), 0 },
       { (float)(-(r + l) / (r - l)), (float)(-(t + b) / (t - b)), (float)(-(f + n) / (f - n)), 1 }
@@ -1036,13 +1041,12 @@ void glesTerminate()
    shortBDSize = 0;
 }
 
-static int stippleTexture;
+static GLuint stippleTexture;
 static bool stippleEnabled;
 
 void glesLineStipple( int i, unsigned short j )
 {
    uint texture[1*16];
-   int c;
    int x;
    for(x = 0; x < 16; x++)
    {
@@ -1139,17 +1143,21 @@ void GLGenBuffers(int count, uint * buffer)
 #ifdef __ANDROID__
    glGenBuffers(count, buffer);
 #else
+#if defined(__WIN32__)
    if(glGenBuffersARB)
+#endif
       glGenBuffersARB(count, buffer);
 #endif
 }
 
-void GLDeleteBuffers(int count, uint * buffer)
+void GLDeleteBuffers(int count, GLuint * buffer)
 {
 #ifdef __ANDROID__
    glDeleteBuffers(count, buffer);
 #else
+#if defined(__WIN32__)
    if(glDeleteBuffersARB)
+#endif
       glDeleteBuffersARB(count, buffer);
 #endif
 }
@@ -1159,7 +1167,9 @@ void GLBindBuffer(int target, uint buffer)
 #ifdef __ANDROID__
    glBindBuffer(target, buffer);
 #else
+#if defined(__WIN32__)
    if(glBindBufferARB)
+#endif
       glBindBufferARB(target, buffer);
 #endif
 }
@@ -1168,13 +1178,16 @@ void GLBufferData(int type, GLenum target, int size, const GLvoid *data, GLenum
 {
 #ifdef __ANDROID__
    if(type == GL_DOUBLE)
-      glesBufferDatad(target, size, data, usage);
+      glesBufferDatad(target, size, (void *)data, usage);
    else if(type == GL_UNSIGNED_INT)
-      glesBufferDatai(target, size, data, usage);
+      glesBufferDatai(target, size, (void *)data, usage);
    else
       glBufferData(target, size, data, usage);
 #else
+
+#if defined(__WIN32__)
    if(glBufferDataARB)
+#endif
       glBufferDataARB(target, size, data, usage);
 
 #endif
@@ -1202,7 +1215,7 @@ class OGLDisplay : struct
    int imageBuffers[2];
    byte * pboMemory1, * pboMemory2;
    */
-#else
+#elif !defined(__ANDROID__)
    GLXContext glContext;
 
    Pixmap pixmap;
@@ -1227,18 +1240,20 @@ class OGLDisplay : struct
 
 class OGLSystem : struct
 {
+   int maxTextureSize;
+   bool loadingFont;
+   bool pow2textures;
 #if defined(__WIN32__)
    PIXELFORMATDESCRIPTOR pfd;
    int format;
    HDC hdc;
    HGLRC glrc;
    HWND hwnd;
-#else
+#elif !defined(__ANDROID__)
    XVisualInfo * visualInfo;
    GLXContext glContext;
    GLXDrawable glxDrawable;
 #endif
-   bool loadingFont;
 };
 
 class OGLSurface : struct
@@ -1253,18 +1268,18 @@ class OGLSurface : struct
 
 class OGLMesh : struct
 {
-   int vertices;
-   int normals;
-   int texCoords;
-   int texCoords2;
-   int colors;
+   uint vertices;
+   uint normals;
+   uint texCoords;
+   uint texCoords2;
+   uint colors;
 };
 
 class OGLIndices : struct
 {
    uint16 * indices;
-   int buffer;
-   int nIndices;
+   uint buffer;
+   uint nIndices;
 };
 
 #if !defined(ECERE_NO3D) && !defined(ECERE_VANILLA)
@@ -1283,6 +1298,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
    bool LockSystem(DisplaySystem displaySystem)
    {
+#if !defined(__ANDROID__)
       OGLSystem oglSystem = displaySystem.driverData;
       if(useSingleGLContext) return true;
    #if defined(__WIN32__)
@@ -1290,11 +1306,10 @@ class OpenGLDisplayDriver : DisplayDriver
    #elif defined(__unix__) || defined(__APPLE__)
       //if(previous) return true;
       // printf("Making SYSTEM current\n");
-#if !defined(__ANDROID__)
       glXMakeCurrent(xGlobalDisplay, (GLXDrawable)oglSystem.glxDrawable, oglSystem.glContext);
-#endif
       //previous = oglSystem.glContext;
    #endif
+#endif
       return true;
    }
 
@@ -1315,20 +1330,17 @@ class OpenGLDisplayDriver : DisplayDriver
 
    bool Lock(Display display)
    {
+#if !defined(__ANDROID__)
       OGLDisplay oglDisplay = display.driverData;
-      OGLSystem oglSystem = display.displaySystem.driverData;
-
       if(useSingleGLContext) return true;
    #if defined(__WIN32__)
       wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc);
    #elif defined(__unix__) || defined(__APPLE__)
       // if(previous) glXMakeCurrent(xGlobalDisplay, None, null);
       // printf("   Making DISPLAY current\n");
-      #if defined(__ANDROID__)
-      #else
-      glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
-      #endif
+      glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
    #endif
+#endif
       return true;
    }
 
@@ -1350,20 +1362,20 @@ class OpenGLDisplayDriver : DisplayDriver
    #if defined(__WIN32__)
          wglMakeCurrent( null, null );
 
-         if(oglDisplay.glrc) 
+         if(oglDisplay.glrc)
             wglDeleteContext(oglDisplay.glrc);
-      
+
          if(oglDisplay.hdc && oglDisplay.pBuffer)
             wglReleasePbufferDCARB(oglDisplay.pBuffer, oglDisplay.hdc);
 
          if(oglDisplay.pBuffer)
             wglDestroyPbufferARB(oglDisplay.pBuffer);
 
-         if(oglDisplay.hdc) 
+         if(oglDisplay.hdc)
             ReleaseDC(display.window, oglDisplay.hdc);
 
          if(oglDisplay.memDC) DeleteDC(oglDisplay.memDC);
-         if(oglDisplay.memBitmap) DeleteObject(oglDisplay.memBitmap); 
+         if(oglDisplay.memBitmap) DeleteObject(oglDisplay.memBitmap);
 
    #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__)
@@ -1390,14 +1402,14 @@ class OpenGLDisplayDriver : DisplayDriver
                if(oglDisplay.shminfoShape.shmaddr != (void *)-1)
                   shmdt(oglDisplay.shminfoShape.shmaddr);
                shmctl(oglDisplay.shminfoShape.shmid, IPC_RMID, 0);
-            }                  
+            }
             XDestroyImage(oglDisplay.shapeImage);
             oglDisplay.shapeImage = None;
          }
 
          glXMakeCurrent(xGlobalDisplay, None, null);
-      
-         if(oglDisplay.glContext) 
+
+         if(oglDisplay.glContext)
             glXDestroyContext(xGlobalDisplay, oglDisplay.glContext);
       #endif
    #endif
@@ -1407,6 +1419,14 @@ class OpenGLDisplayDriver : DisplayDriver
       }
    }
 
+   void ::CheckExtensions(OGLSystem oglSystem)
+   {
+      const char * extensions = (const char *)glGetString(GL_EXTENSIONS);
+      if(extensions)
+         oglSystem.pow2textures = strstr(extensions, "GL_ARB_texture_non_power_of_two") ? false : true;
+      glGetIntegerv(GL_MAX_TEXTURE_SIZE, &oglSystem.maxTextureSize);
+   }
+
    bool CreateDisplaySystem(DisplaySystem displaySystem)
    {
       bool result = false;
@@ -1418,7 +1438,7 @@ class OpenGLDisplayDriver : DisplayDriver
       oglSystem.hdc = GetDC(oglSystem.hwnd);
       if(oglSystem.hdc)
       {
-          
+
          oglSystem.pfd.nSize = (short)sizeof(oglSystem.pfd);
          oglSystem.pfd.nVersion = 1;
          oglSystem.pfd.dwFlags = PFD_DRAW_TO_WINDOW /*PFD_DRAW_TO_BITMAP*/ | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
@@ -1476,7 +1496,7 @@ class OpenGLDisplayDriver : DisplayDriver
                    int numFormats;
                    float fAttributes[] = {0,0};
                    int iAttributes[] =
-                  { 
+                  {
                      WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
                            WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
                            WGL_ACCELERATION_ARB,WGL_FULL_ACCELERATION_ARB,
@@ -1526,6 +1546,8 @@ class OpenGLDisplayDriver : DisplayDriver
 
                result = true;
 
+               CheckExtensions(oglSystem);
+
                wglMakeCurrent(null, null);
 
                //eSystem_DumpErrors(true);
@@ -1536,6 +1558,7 @@ class OpenGLDisplayDriver : DisplayDriver
       vboAvailable = true;
       #if defined(__ANDROID__)
          egl_init_display(guiApp.desktop.windowHandle);
+         CheckExtensions(oglSystem);
          result = true;
       #else
       {
@@ -1570,6 +1593,7 @@ class OpenGLDisplayDriver : DisplayDriver
          {
             glXMakeCurrent(xGlobalDisplay, oglSystem.glxDrawable, oglSystem.glContext);
             // Setup Extensions
+            CheckExtensions(oglSystem);
             glXMakeCurrent(xGlobalDisplay, None, null);
             result = true;
          }
@@ -1590,10 +1614,10 @@ class OpenGLDisplayDriver : DisplayDriver
    #if defined(__WIN32__)
       wglMakeCurrent( null, null );
 
-      if(oglSystem.glrc) 
+      if(oglSystem.glrc)
          wglDeleteContext(oglSystem.glrc);
-      
-      if(oglSystem.hdc) 
+
+      if(oglSystem.hdc)
          ReleaseDC(oglSystem.hwnd, oglSystem.hdc);
       DestroyWindow(oglSystem.hwnd);
 
@@ -1624,7 +1648,9 @@ class OpenGLDisplayDriver : DisplayDriver
    {
       bool result = false;
       OGLDisplay oglDisplay = display.driverData;
+#if !defined(__ANDROID__)
       OGLSystem oglSystem = display.displaySystem.driverData;
+#endif
       if(!oglDisplay)
          oglDisplay = display.driverData = OGLDisplay { };
       //printf("Inside CreateDisplay\n");
@@ -1677,7 +1703,7 @@ class OpenGLDisplayDriver : DisplayDriver
          if(oglDisplay.glContext)
          {
             //printf("CreateDisplay Got a Context\n");
-            glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+            glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
             result = true;
          }
       #endif
@@ -1689,12 +1715,18 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
       if(result)
       {
-#if !defined(__OLDX__)
+#if defined(__WIN32__)
          if(glBlendFuncSeparate)
             glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
          else
-#endif
             glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#else
+#if !defined(__OLDX__)
+          glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+#else
+         glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+#endif
+#endif
          glEnable(GL_BLEND);
 
          glMatrixMode(GL_MODELVIEW);
@@ -1736,12 +1768,12 @@ class OpenGLDisplayDriver : DisplayDriver
    bool DisplaySize(Display display, int width, int height)
    {
       OGLDisplay oglDisplay = display.driverData;
-      OGLSystem oglSystem = display.displaySystem.driverData;
 
       bool result = false;
 
       //printf("Inside DisplaySize\n");
 #if defined(__WIN32__) || defined(USEPBUFFER)
+      OGLSystem oglSystem = display.displaySystem.driverData;
       if(display.alphaBlend)
       {
 #if defined(__WIN32__)
@@ -1749,7 +1781,7 @@ class OpenGLDisplayDriver : DisplayDriver
          {
             /*WGL_TEXTURE_FORMAT_ARB, WGL_TEXTURE_RGBA_ARB,
             WGL_TEXTURE_TARGET_ARB, WGL_TEXTURE_2D_ARB, */0
-         }; 
+         };
          int pixelFormat = 0;
          if(wglChoosePixelFormatARB)
          {
@@ -1757,7 +1789,7 @@ class OpenGLDisplayDriver : DisplayDriver
             int numFormats;
             float fAttributes[] = {0,0};
             int iAttributes[] =
-            { 
+            {
                //WGL_DRAW_TO_BITMAP_ARB, GL_TRUE,
                WGL_DRAW_TO_PBUFFER_ARB,GL_TRUE,
                    WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
@@ -1771,7 +1803,7 @@ class OpenGLDisplayDriver : DisplayDriver
                    WGL_SAMPLES_ARB, 4,                                         // Check For 4x Multisampling
                    0,0
             };
-            
+
             //Log("Found wglChoosePixelFormatARB\n");
 
             valid = wglChoosePixelFormatARB(oglSystem.hdc,iAttributes,fAttributes,1,&pixelFormat,&numFormats);
@@ -1806,7 +1838,7 @@ class OpenGLDisplayDriver : DisplayDriver
             {
                wglMakeCurrent(null, null);
             }
-         }  
+         }
 
          wglMakeCurrent( null, null );
          wglMakeCurrent( oglDisplay.hdc, oglDisplay.glrc );
@@ -1817,8 +1849,8 @@ class OpenGLDisplayDriver : DisplayDriver
 
          if(!useSingleGLContext)
             wglMakeCurrent( null, null );
-           
-         if(oglDisplay.glrc) 
+
+         if(oglDisplay.glrc)
             wglDeleteContext(oglDisplay.glrc);
 
          oglDisplay.pBuffer = wglCreatePbufferARB(oglSystem.hdc, pixelFormat, width, height, attributes);
@@ -1832,8 +1864,8 @@ class OpenGLDisplayDriver : DisplayDriver
             wglMakeCurrent(oglDisplay.hdc, oglDisplay.glrc);
 
             //wglQueryPbufferARB(pBuffer, WGL_PBUFFER_WIDTH_ARB, &width);
-            //wglQueryPbufferARB(pBuffer, WGL_PBUFFER_HEIGHT_ARB, &height); 
-            
+            //wglQueryPbufferARB(pBuffer, WGL_PBUFFER_HEIGHT_ARB, &height);
+
             // glDeleteBuffersARB(2, oglDisplay.imageBuffers);
 
             if((info = (BITMAPINFO *)new0 byte[sizeof(BITMAPINFOHEADER)+sizeof(RGBQUAD)*256]))
@@ -1963,7 +1995,7 @@ class OpenGLDisplayDriver : DisplayDriver
                   if(oglDisplay.shminfoShape.shmaddr != (void *)-1)
                      shmdt(oglDisplay.shminfoShape.shmaddr);
                   shmctl(oglDisplay.shminfoShape.shmid, IPC_RMID, 0);
-               }                  
+               }
                XDestroyImage(oglDisplay.shapeImage);
                oglDisplay.shapeImage = None;
             }
@@ -1988,14 +2020,14 @@ class OpenGLDisplayDriver : DisplayDriver
                if(oglDisplay.glContext)
                {
                   glXMakeCurrent(xGlobalDisplay, None, null);
-                  glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+                  glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
 
                   // Initialize Shared Memory Pixmap
-                  oglDisplay.image = XShmCreateImage(xGlobalDisplay, DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 32, 
+                  oglDisplay.image = XShmCreateImage(xGlobalDisplay, DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 32,
                      ZPixmap, null, &oglDisplay.shminfo, width, height);
                   if(oglDisplay.image)
                   {
-                     oglDisplay.shminfo.shmid = shmget(IPC_PRIVATE, 
+                     oglDisplay.shminfo.shmid = shmget(IPC_PRIVATE,
                         oglDisplay.image->bytes_per_line * oglDisplay.image->height, IPC_CREAT|0777);
                      if(oglDisplay.shminfo.shmid != -1)
                      {
@@ -2005,15 +2037,15 @@ class OpenGLDisplayDriver : DisplayDriver
                            oglDisplay.shminfo.readOnly = False;
                            if(XShmAttach(xGlobalDisplay, &oglDisplay.shminfo))
                            {
-                              oglDisplay.pixmap = XShmCreatePixmap(xGlobalDisplay, (X11Window)display.window, oglDisplay.shminfo.shmaddr, 
+                              oglDisplay.pixmap = XShmCreatePixmap(xGlobalDisplay, (X11Window)display.window, oglDisplay.shminfo.shmaddr,
                                  &oglDisplay.shminfo, width, height, 32);
 
                               // Initialize Shared Memory Shape Pixmap
-                              oglDisplay.shapeImage = XShmCreateImage(xGlobalDisplay, DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 1, 
+                              oglDisplay.shapeImage = XShmCreateImage(xGlobalDisplay, DefaultVisual(xGlobalDisplay, DefaultScreen(xGlobalDisplay)), 1,
                                  ZPixmap, null, &oglDisplay.shminfoShape, width, height);
                               if(oglDisplay.shapeImage)
                               {
-                                 oglDisplay.shminfoShape.shmid = shmget(IPC_PRIVATE, 
+                                 oglDisplay.shminfoShape.shmid = shmget(IPC_PRIVATE,
                                     oglDisplay.shapeImage->bytes_per_line * oglDisplay.shapeImage->height, IPC_CREAT|0777);
                                  if(oglDisplay.shminfoShape.shmid != -1)
                                  {
@@ -2023,7 +2055,7 @@ class OpenGLDisplayDriver : DisplayDriver
                                        oglDisplay.shminfoShape.readOnly = False;
                                        if(XShmAttach(xGlobalDisplay, &oglDisplay.shminfoShape))
                                        {
-                                          oglDisplay.shapePixmap = XShmCreatePixmap(xGlobalDisplay, (X11Window)display.window, oglDisplay.shminfoShape.shmaddr, 
+                                          oglDisplay.shapePixmap = XShmCreatePixmap(xGlobalDisplay, (X11Window)display.window, oglDisplay.shminfoShape.shmaddr,
                                              &oglDisplay.shminfoShape, width, height, 1);
                                           //oglDisplay.shapePixmap = XCreatePixmap(xGlobalDisplay, (X11Window)display.window, width, height, 1);
 
@@ -2037,9 +2069,9 @@ class OpenGLDisplayDriver : DisplayDriver
                                              #endif
                                              oglDisplay.pixmapPicture = XRenderCreatePicture(xGlobalDisplay, oglDisplay.pixmap, format, CPRepeat, &attributes);
                                              oglDisplay.windowPicture = XRenderCreatePicture(xGlobalDisplay, (X11Window)display.window, format, 0, &attributes);
-                                             oglDisplay.shapePicture = XRenderCreatePicture(xGlobalDisplay, oglDisplay.shapePixmap, 
+                                             oglDisplay.shapePicture = XRenderCreatePicture(xGlobalDisplay, oglDisplay.shapePixmap,
                                                 XRenderFindStandardFormat(xGlobalDisplay, PictStandardA1), 0, &attributes);
-                                          }  
+                                          }
 
                                           oglDisplay.picture = oglDisplay.shminfo.shmaddr;
                                           oglDisplay.stride = oglDisplay.image->bytes_per_line / 4;
@@ -2067,7 +2099,7 @@ class OpenGLDisplayDriver : DisplayDriver
          width = eglWidth;
          height = eglHeight;
       #else
-         glXMakeCurrent(xGlobalDisplay, (int)display.window, oglDisplay.glContext);
+         glXMakeCurrent(xGlobalDisplay, (GLXDrawable)display.window, oglDisplay.glContext);
       #endif
 #endif
       }
@@ -2080,7 +2112,7 @@ class OpenGLDisplayDriver : DisplayDriver
       }
       if(!result)
          return false;
-         
+
       result = false;
 
       glViewport(0,0,width,height);
@@ -2097,7 +2129,7 @@ class OpenGLDisplayDriver : DisplayDriver
       }
       if(oglDisplay.flippingBuffer || !width || !height)
          result = true;
-         
+
       return result;
    }
 
@@ -2131,7 +2163,9 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void Update(Display display, Box updateBox)
    {
+#if defined(__WIN32__) || defined(USEPBUFFER)
       OGLDisplay oglDisplay = display.driverData;
+#endif
       //Logf("DisplayScreen\n");
 
       glFlush();
@@ -2164,15 +2198,15 @@ class OpenGLDisplayDriver : DisplayDriver
             // outstanding DMA transfers into the buffer to finish.
             glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, oglDisplay.imageBuffers[0]);
             oglDisplay.pboMemory1 = (byte *)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB, GL_READ_ONLY);
-           
+
             // glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, oglDisplay.imageBuffers[1]);
             // oglDisplay.pboMemory2 = (byte *)glMapBufferARB(GL_PIXEL_PACK_BUFFER_ARB,GL_READ_ONLY);
 
-           
+
             memcpy(oglDisplay.picture, oglDisplay.pboMemory1, display.width * display.height * 4);
             //memcpy(oglDisplay.picture + display.width * display.height * 4 / 2, oglDisplay.pboMemory2, display.width * display.height * 4/ 2);
             */
-            
+
             UpdateLayeredWindow(display.window, hdc, &point, &size, oglDisplay.memDC, &srcPoint, 0, &blend, ULW_ALPHA);
             /*
 
@@ -2182,7 +2216,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
             // glBindBufferARB(GL_PIXEL_PACK_BUFFER_ARB, oglDisplay.imageBuffers[1]);
             // glUnmapBufferARB(GL_PIXEL_PACK_BUFFER_ARB);
-           
+
             // Bind two different buffer objects and start the glReadPixels
             // asynchronously. Each call will return directly after
             // starting the DMA transfer.
@@ -2197,7 +2231,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__)
       #else
-            XTransform transform = 
+            XTransform transform =
             {
                {
                   { (int)(1.0f * (1<<16)), (int)(0.0f * (1<<16)),  (int)(0 * (1 << 16)) },
@@ -2217,18 +2251,18 @@ class OpenGLDisplayDriver : DisplayDriver
      #endif
 #endif
          }
-      } 
+      }
       else
 #endif
       {
 #if defined(__WIN32__)
-         //wglSwapLayerBuffers(oglDisplay.hdc,WGL_SWAP_MAIN_PLANE); 
+         //wglSwapLayerBuffers(oglDisplay.hdc,WGL_SWAP_MAIN_PLANE);
          SwapBuffers(oglDisplay.hdc);
 #elif defined(__unix__) || defined(__APPLE__)
       #if defined(__ANDROID__)
          eglSwapBuffers(eglDisplay, eglSurface);
       #else
-         glXSwapBuffers(xGlobalDisplay, (int)display.window);
+         glXSwapBuffers(xGlobalDisplay, (GLXDrawable)display.window);
       #endif
 #endif
       }
@@ -2237,21 +2271,30 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void FreeBitmap(DisplaySystem displaySystem, Bitmap bitmap)
    {
-      glDeleteTextures(1, (int *)&bitmap.driverData);
-      bitmap.driverData = 0;
-
+      if(bitmap.driverData)
+      {
+         GLuint tex = (GLuint)(uintptr)bitmap.driverData;
+         glDeleteTextures(1, &tex);
+         bitmap.driverData = 0;
+      }
       bitmap.driver = ((subclass(DisplayDriver))class(LFBDisplayDriver));
    }
 
    bool AllocateBitmap(DisplaySystem displaySystem, Bitmap bitmap, int width, int height, int stride, PixelFormat format, bool allocatePalette)
    {
+      OGLSystem oglSystem = displaySystem.driverData;
       bool result = false;
       Bitmap mipMap { };
-      int glBitmap = -1;
-      
-      uint w = pow2i(Min(width, 1024)), h = pow2i(Min(height, 1024));
-      //uint w = pow2i(Min(width, 2048)), h = pow2i(Min(height, 2048));
-      //uint w = pow2i(Min(width, 512)), h = pow2i(Min(height, 512));
+      GLuint glBitmap = 0;
+
+      uint w = width, h = height;
+      if(oglSystem.pow2textures)
+      {
+         w = pow2i(w);
+         h = pow2i(h);
+      }
+      w = Min(w, oglSystem.maxTextureSize);
+      h = Min(h, oglSystem.maxTextureSize);
 
       glGenTextures(1, &glBitmap);
       glBindTexture(GL_TEXTURE_2D, glBitmap);
@@ -2273,7 +2316,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
       delete mipMap;
 
-      bitmap.driverData = (void *)glBitmap;
+      bitmap.driverData = (void *)(uintptr)glBitmap;
       bitmap.driver = displaySystem.driver;
       bitmap.width = w;
       bitmap.height = h;
@@ -2291,9 +2334,21 @@ class OpenGLDisplayDriver : DisplayDriver
       if(/*bitmap.pixelFormat == pixelFormatRGBA || */bitmap.Convert(null, pixelFormat888, null))
       {
          int c, level;
-         uint w = pow2i(Min(bitmap.width, 1024)), h = pow2i(Min(bitmap.height, 1024));
-         //uint w = pow2i(Min(bitmap.width, 512)), h = pow2i(Min(bitmap.height, 512));
-         int glBitmap = -1;
+         uint w = bitmap.width, h = bitmap.height;
+         GLuint glBitmap = 0;
+         if(oglSystem.pow2textures)
+         {
+            w = pow2i(w);
+            h = pow2i(h);
+         }
+         w = Min(w, oglSystem.maxTextureSize);
+         h = Min(h, oglSystem.maxTextureSize);
+
+         if(mipMaps)
+         {
+            while(w * 2 < h) w *= 2;
+            while(h * 2 < w) h *= 2;
+         }
 
          // Switch ARGB to RGBA
          //if(bitmap.format != pixelFormatRGBA)
@@ -2301,7 +2356,7 @@ class OpenGLDisplayDriver : DisplayDriver
             for(c=0; c<bitmap.size; c++)
             {
                // ((ColorRGBA *)bitmap.picture)[c] = ((ColorAlpha *)bitmap.picture)[c];
-               // TODO: 
+               // TODO:
                ColorAlpha color = ((ColorAlpha *)bitmap.picture)[c];
                ((ColorRGBA *)bitmap.picture)[c] = ColorRGBA { color.color.r, color.color.g, color.color.b, color.a };
             }
@@ -2310,11 +2365,10 @@ class OpenGLDisplayDriver : DisplayDriver
 
          glGetError();
          glGenTextures(1, &glBitmap);
-         if(glBitmap == -1)
+         if(glBitmap == 0)
          {
-            int error = glGetError();
+            //int error = glGetError();
             return false;
-            //Print("");
          }
 
          glBindTexture(GL_TEXTURE_2D, glBitmap);
@@ -2352,7 +2406,7 @@ class OpenGLDisplayDriver : DisplayDriver
                   delete mipMap;
                }
             }
-            else 
+            else
                mipMap = bitmap;
 
             if(result)
@@ -2372,14 +2426,14 @@ class OpenGLDisplayDriver : DisplayDriver
                   result = false;
                }
             }
-            if(mipMap != bitmap) 
+            if(mipMap != bitmap)
                delete mipMap;
             if(!mipMaps) break;
          }
 
          if(!bitmap.keepData)
             bitmap.driver.FreeBitmap(bitmap.displaySystem, bitmap);
-         bitmap.driverData = (void *)glBitmap;
+         bitmap.driverData = (void *)(uintptr)glBitmap;
          bitmap.driver = displaySystem.driver;
 
          if(!result)
@@ -2473,7 +2527,7 @@ class OpenGLDisplayDriver : DisplayDriver
       bool result = false;
       OGLDisplay oglDisplay = display.driverData;
       ColorAlpha * flippingBuffer = oglDisplay.flippingBuffer;
-      
+
       if(oglDisplay.flippingBuffer)
       {
          if(bitmap.pixelFormat != pixelFormat888 || bitmap.width < w || bitmap.height < h)
@@ -2553,15 +2607,28 @@ class OpenGLDisplayDriver : DisplayDriver
       glBegin(GL_POINTS);
       // glVertex2i(x+surface.offset.x, y+surface.offset.y);
       glVertex2f(x+surface.offset.x + 0.5f, y+surface.offset.y + 0.5f);
-       
+
       glEnd();
    }
 
-   void DrawLine(Display display, Surface surface, int x1, int y1, int x2, int y2)
+   void DrawLine(Display display, Surface surface, int _x1, int _y1, int _x2, int _y2)
    {
       OGLSurface oglSurface = surface.driverData;
-      if(x1 == x2) { y2++; y1--; }
-      else if(y1 == y2) { x2++; x1--; }
+      float x1 = _x1, x2 = _x2, y1 = _y1, y2 = _y2;
+      if(_x1 == _x2)
+      {
+         if(_y2 >= _y1)
+            y2 += 1;
+         else
+            y1 += 1;
+      }
+      else if(_y1 == _y2)
+      {
+         if(_x2 >= _x1)
+            x2 += 1;
+         else
+            x1 += 1;
+      }
       x1 += surface.offset.x;
       y1 += surface.offset.y;
       x2 += surface.offset.x;
@@ -2589,7 +2656,7 @@ class OpenGLDisplayDriver : DisplayDriver
          glVertex2f(x1 + 0.5f, y1 + 0.5f);
          glVertex2f(x2 + 0.5f, y2 + 0.5f);
       }
-      
+
       glEnd();
    }
 
@@ -2655,7 +2722,7 @@ class OpenGLDisplayDriver : DisplayDriver
       glColor4fv(oglSurface.background);
       glRecti(x1+surface.offset.x, y1+surface.offset.y,
               x2+surface.offset.x + 1, y2+surface.offset.y + 1);
-              
+
       /*
       glRectf(x1+surface.offset.x, y1+surface.offset.y,
               x2+surface.offset.x + 1, y2+surface.offset.y + 1);
@@ -2705,8 +2772,8 @@ class OpenGLDisplayDriver : DisplayDriver
       }
       else if(oglSurface.xOffset)
          glTranslated(oglSurface.xOffset / 64.0/*-0.375*/, 0.0, 0.0);
-         
-      glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+
+      glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
       glBegin(GL_QUADS);
 
       if(h < 0)
@@ -2773,7 +2840,7 @@ class OpenGLDisplayDriver : DisplayDriver
 #endif
 
       glEnable(GL_TEXTURE_2D);
-      glBindTexture(GL_TEXTURE_2D, (uint)bitmap.driverData);
+      glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)bitmap.driverData);
 
       glColor4fv(oglSurface.bitmapMult);
 
@@ -2783,13 +2850,13 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
          glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
          glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
          glVertex2i(dx+w+surface.offset.x, dy-h+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
          glVertex2i(dx+surface.offset.x, dy-h+surface.offset.y);
       }
@@ -2797,13 +2864,13 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          glTexCoord2f((float)(sx) / bitmap.width, (float)(sy)/ bitmap.height);
          glVertex2i(dx+surface.offset.x, dy+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx+sw)/ bitmap.width, (float)(sy)/ bitmap.height);
          glVertex2i(dx+w+surface.offset.x, dy+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx+sw) / bitmap.width, (float)(sy+sh)/ bitmap.height);
          glVertex2i(dx+w+surface.offset.x, dy+h+surface.offset.y);
-      
+
          glTexCoord2f((float)(sx)/ bitmap.width, (float)(sy+sh)/ bitmap.height);
          glVertex2i(dx+surface.offset.x, dy+h+surface.offset.y);
       }
@@ -2828,7 +2895,7 @@ class OpenGLDisplayDriver : DisplayDriver
    void StretchDI(Display display, Surface surface, Bitmap bitmap, int dx, int dy, int sx, int sy, int w, int h, int sw, int sh)
    {
       float s2dw,s2dh,d2sw,d2sh;
-      bool flipX = false, flipY = false;
+      //bool flipX = false, flipY = false;
 
       //Logf("StretchDI\n");
 
@@ -2836,13 +2903,13 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          w = Abs(w);
          sw = Abs(sw);
-         flipX = true; 
+         //flipX = true;
       }
       if(Sgn(h) != Sgn(sh))
       {
          h = Abs(h);
          sh = Abs(sh);
-         flipY = true; 
+         //flipY = true;
       }
 
       s2dw=(float)w / sw;
@@ -2879,7 +2946,7 @@ class OpenGLDisplayDriver : DisplayDriver
       //Clip against the edges of the surfaceination
       if(dx<surface.box.left)
       {
-         //if(!flip) 
+         //if(!flip)
          sx+=(int)((surface.box.left-dx)*d2sw);
          sw-=(int)((surface.box.left-dx)*d2sw);
          w-=surface.box.left-dx;
@@ -2949,7 +3016,7 @@ class OpenGLDisplayDriver : DisplayDriver
       //Clip against the edges of the surfaceination
       if(dx<surface.box.left)
       {
-         //if(!flip) 
+         //if(!flip)
          sx+=surface.box.left-dx;
          w-=surface.box.left-dx;
          dx=surface.box.left;
@@ -2999,7 +3066,7 @@ class OpenGLDisplayDriver : DisplayDriver
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).UnloadFont(displaySystem, font);
    }
 
-   Font LoadFont(DisplaySystem displaySystem, char * faceName, float size, FontFlags flags)
+   Font LoadFont(DisplaySystem displaySystem, const char * faceName, float size, FontFlags flags)
    {
       Font font;
       OGLSystem oglSystem = displaySystem.driverData;
@@ -3008,12 +3075,12 @@ class OpenGLDisplayDriver : DisplayDriver
       return font;
    }
 
-   void FontExtent(DisplaySystem displaySystem, Font font, char * text, int len, int * width, int * height)
+   void FontExtent(DisplaySystem displaySystem, Font font, const char * text, int len, int * width, int * height)
    {
       ((subclass(DisplayDriver))class(LFBDisplayDriver)).FontExtent(displaySystem, font, text, len, width, height);
    }
 
-   void WriteText(Display display, Surface surface, int x, int y, char * text, int len)
+   void WriteText(Display display, Surface surface, int x, int y, const char * text, int len)
    {
       OGLSurface oglSurface = surface.driverData;
       OGLSystem oglSystem = display.displaySystem.driverData;
@@ -3055,7 +3122,7 @@ class OpenGLDisplayDriver : DisplayDriver
       oglSurface.opaqueText = opaque;
    }
 
-   void TextExtent(Display display, Surface surface, char * text, int len, int * width, int * height)
+   void TextExtent(Display display, Surface surface, const char * text, int len, int * width, int * height)
    {
       OGLSurface oglSurface = surface.driverData;
       OGLSystem oglSystem = display.displaySystem.driverData;
@@ -3118,7 +3185,7 @@ class OpenGLDisplayDriver : DisplayDriver
             break;
          case depthWrite:
             if(value) glDepthMask((byte)bool::true); else glDepthMask((byte)bool::false);
-            oglDisplay.depthWrite = value;
+            oglDisplay.depthWrite = (bool)value;
             break;
          case fogColor:
          {
@@ -3127,8 +3194,7 @@ class OpenGLDisplayDriver : DisplayDriver
             break;
          }
          case fogDensity:
-            value *= nearPlane;
-            glFogf(GL_FOG_DENSITY, *(float *)(void *)&value);
+            glFogf(GL_FOG_DENSITY, (float)(RenderStateFloat { value }.f * nearPlane));
             break;
          case blend:
             if(value) glEnable(GL_BLEND); else glDisable(GL_BLEND);
@@ -3177,7 +3243,7 @@ class OpenGLDisplayDriver : DisplayDriver
          color[1] = light.diffuse.g * light.multiplier;
          color[2] = light.diffuse.b * light.multiplier;
          glLightfv(GL_LIGHT0 + id, GL_DIFFUSE, color);
-         
+
          color[0] = light.ambient.r * light.multiplier;
          color[1] = light.ambient.g * light.multiplier;
          color[2] = light.ambient.b * light.multiplier;
@@ -3186,7 +3252,7 @@ class OpenGLDisplayDriver : DisplayDriver
          color[1] = light.specular.g * light.multiplier;
          color[2] = light.specular.b * light.multiplier;
          glLightfv(GL_LIGHT0 + id, GL_SPECULAR,color);
-         
+
          if(lightObject)
          {
             Vector3D positionVector;
@@ -3224,7 +3290,7 @@ class OpenGLDisplayDriver : DisplayDriver
             position[0] = (float)positionVector.x;
             position[1] = (float)positionVector.y;
             position[2] = (float)positionVector.z;
-            
+
             glLightfv(GL_LIGHT0 + id, GL_POSITION, position);
 
             /*
@@ -3238,7 +3304,7 @@ class OpenGLDisplayDriver : DisplayDriver
             glEnd();
             glEnable(GL_DEPTH_TEST);
             glEnable(GL_LIGHTING);
-                     
+
 
             // Display Target
             if(lightObject.flags.root || !lightObject.parent)
@@ -3248,7 +3314,7 @@ class OpenGLDisplayDriver : DisplayDriver
             }
             else
             {
-               positionVector.MultMatrix(light.target.transform.position, 
+               positionVector.MultMatrix(light.target.transform.position,
                   lightObject.light.target.parent.matrix);
                positionVector.Subtract(positionVector, display.camera.cPosition);
             }
@@ -3290,7 +3356,7 @@ class OpenGLDisplayDriver : DisplayDriver
          }
          else
          {
-            
+
             Vector3Df vector { 0,0,-1 };
             Vector3Df direction;
             Matrix mat;
@@ -3339,7 +3405,7 @@ class OpenGLDisplayDriver : DisplayDriver
          {
             float pickX = display.display3D.pickX + surface.offset.x;
             float pickY = display.height - (display.display3D.pickY + surface.offset.y) - 1;
-            Matrix pickMatrix = 
+            Matrix pickMatrix
             {
                {
                   w / display.display3D.pickWidth, 0, 0, 0,
@@ -3437,7 +3503,13 @@ class OpenGLDisplayDriver : DisplayDriver
       {
          Bitmap map = material.baseMap;
          glEnable(GL_TEXTURE_2D);
-         glBindTexture(GL_TEXTURE_2D, (uint)map.driverData);
+         glBindTexture(GL_TEXTURE_2D, (GLuint)(uintptr)map.driverData);
+
+         glMatrixMode(GL_TEXTURE);
+         glLoadIdentity();
+         if(material.uScale && material.vScale)
+            glScalef(material.uScale, material.vScale, 1);
+         glMatrixMode(GL_MODELVIEW);
 
          if(material.flags.tile)
          {
@@ -3470,7 +3542,7 @@ class OpenGLDisplayDriver : DisplayDriver
             glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color);
          }
       }
-      {   
+      {
          float color[4] = { material.specular.r, material.specular.g, material.specular.b, 0 };
          glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, color);
       }
@@ -3478,7 +3550,7 @@ class OpenGLDisplayDriver : DisplayDriver
          float color[4] = { material.emissive.r, material.emissive.g, material.emissive.b, 0 };
          glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, color);
       }
-      
+
       glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, &material.power);
    }
 
@@ -3580,7 +3652,7 @@ class OpenGLDisplayDriver : DisplayDriver
    {
       OGLMesh oglMesh = mesh.data;
       if(!flags) flags = mesh.flags;
-      
+
       if(vboAvailable)
       {
          if(!(flags.vertices) || oglMesh.vertices)
@@ -3622,7 +3694,7 @@ class OpenGLDisplayDriver : DisplayDriver
    {
       if(oglIndices)
       {
-         if(oglIndices.buffer) 
+         if(oglIndices.buffer)
             GLDeleteBuffers(1, &oglIndices.buffer);
          delete oglIndices.indices;
          delete oglIndices;
@@ -3646,7 +3718,7 @@ class OpenGLDisplayDriver : DisplayDriver
       if(vboAvailable)
       {
          GLBindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB, oglIndices.buffer);
-         GLBufferData( indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)), 
+         GLBufferData( indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, GL_ELEMENT_ARRAY_BUFFER_ARB, nIndices * (indices32bit ? sizeof(uint32) : sizeof(uint16)),
             oglIndices.indices, GL_STATIC_DRAW_ARB);
          GLBindBuffer( GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
       }
@@ -3654,7 +3726,7 @@ class OpenGLDisplayDriver : DisplayDriver
 
    uint16 * LockIndices(DisplaySystem displaySystem, OGLIndices oglIndices)
    {
-      
+
       return oglIndices.indices;
    }
 
@@ -3663,12 +3735,14 @@ class OpenGLDisplayDriver : DisplayDriver
       //Logf("SelectMesh\n");
 
 #if !defined( __ANDROID__) && !defined(__APPLE__)
-      if(display.display3D.mesh && glUnlockArraysEXT)   
-         glUnlockArraysEXT();
+#if defined(__WIN32__)
+      if(glUnlockArraysEXT)
+#endif
+         if(display.display3D.mesh)
+            glUnlockArraysEXT();
 #endif
       if(mesh)
       {
-         OGLDisplay oglDisplay = display.driverData;
          OGLMesh oglMesh = mesh.data;
 
          // *** Vertex Stream ***
@@ -3737,7 +3811,11 @@ class OpenGLDisplayDriver : DisplayDriver
          }
 
 #if !defined(__ANDROID__) && !defined(__APPLE__)
-         if(glLockArraysEXT) glLockArraysEXT(0, mesh.nVertices);
+
+#if defined(__WIN32__)
+         if(glLockArraysEXT)
+#endif
+            glLockArraysEXT(0, mesh.nVertices);
 #endif
       }
       else
@@ -3746,14 +3824,13 @@ class OpenGLDisplayDriver : DisplayDriver
 
    void DrawPrimitives(Display display, PrimitiveSingle * primitive, Mesh mesh)
    {
-      OGLDisplay oglDisplay = display.driverData;
       //Logf("DrawPrimitives\n");
 
       if(primitive->type.vertexRange)
          glDrawArrays(primitiveTypes[primitive->type.primitiveType], primitive->first, primitive->nVertices);
       else
       {
-         //    *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) *** 
+         //    *** Hoping the data won't be uploaded at all (Won't really work if another group of the mesh is using the mesh ) ***
          // HACK TO SPEED THINGS UP...
 #ifndef __ANDROID__
          GLBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
@@ -3767,7 +3844,7 @@ class OpenGLDisplayDriver : DisplayDriver
                MeshFeatures flags = mesh.flags;
                for(c = 0; c<primitive->nIndices; c++)
                {
-                  short index = ((short *) oglIndices.indices)[c];
+                  uint16 index = ((uint16 *) oglIndices.indices)[c];
                   if(flags.normals) glNormal3fv((float *)&mesh.normals[index]);
                   if(flags.texCoords1) glTexCoord2fv((float *)&mesh.texCoords[index]);
                   if(flags.colors) glColor4fv((float *)&mesh.colors[index]);
@@ -3784,12 +3861,12 @@ class OpenGLDisplayDriver : DisplayDriver
             if(!display.display3D.collectingHits && vboAvailable && oglIndices)
             {
                GLBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, oglIndices.buffer);
-               glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices, 
+               glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
                   primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, 0);
                GLBindBuffer(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
             }
             else
-               glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices, 
+               glDrawElements(primitiveTypes[primitive->type.primitiveType], primitive->nIndices,
                   primitive->type.indices32bit ? GL_UNSIGNED_INT : GL_UNSIGNED_SHORT, oglIndices ? oglIndices.indices : primitive->indices);
          }
       }
@@ -3842,4 +3919,25 @@ public void UseSingleGLContext(bool useSingle)
    useSingleGLContext = useSingle;
 }
 
+default dllexport void *
+#if defined(__WIN32__)
+__attribute__((stdcall))
+#endif
+IS_GLGetContext(DisplaySystem displaySystem)
+{
+   if(displaySystem)
+   {
+#if defined(__WIN32__)
+      OGLSystem system = displaySystem.driverData;
+      return system.glrc;
+#elif !defined(__ANDROID__)
+      OGLSystem system = displaySystem.driverData;
+      return system.glContext;
+#else
+      return eglContext;
+#endif
+   }
+   return null;
+}
+
 #endif