// Jeank - rewrited from sample of Alex V. Boreskoff <steps3d@gmail.com>, <steps3d@narod.ru>

#include "quakedef.h"

//#include	"gl_GLExt.h"
//#include    <GL/gl.h>
//#include    "libs/glext/glext.h"
//#include    <stdio.h>
//#include    <string.h>
//#include    <ctype.h>
//#include    <stdlib.h>
//#include    <malloc.h>

/*
=======================
Vars, defines
=======================
*/
BINDTEXFUNCPTR bindTexFunc;
#define TEXTURE_EXT_STRING			"GL_EXT_texture_object"
#define FX_DISPLAY_MODE_EXT_STRING	"gl3DfxDisplayModeEXT"
#define FX_SET_PALETTE_EXT_STRING	"3DFX_set_global_palette"
#define VR_SET_PALETTE_EXT_STRING	"POWERVR_set_global_palette"

FX_DISPLAY_MODE_EXT		fxDisplayModeExtension;
FX_SET_PALETTE_EXT		fxSetPaletteExtension;

//ArrayExtensions
PROC glArrayElementEXT;
PROC glColorPointerEXT;
PROC glTexCoordPointerEXT;
PROC glVertexPointerEXT;

// multitexturing
GLenum GL_MTexture0;
GLenum GL_MTexture1;
GLenum GL_MTexture2;
int    gl_max_texture_units;

qboolean is_3dfx = false;
qboolean is_PowerVR = false;

const char *gl_vendor;
const char *gl_renderer;
const char *gl_version;
const char *gl_extensions;

static  boolean	extinitialized = false; // whether initExtensions has already been called
/*
=======================
Extentions
=======================
*/
#ifdef  _WIN32

PFNWGLGETEXTENSIONSSTRINGARBPROC        wglGetExtensionsStringARB = NULL;
// multitexture functions
// under Linux all multitexture is supported by OpenGL itself
PFNGLACTIVETEXTUREARBPROC        glActiveTextureARB        = NULL;
PFNGLCLIENTACTIVETEXTUREARBPROC  glClientActiveTextureARB  = NULL;
PFNGLMULTITEXCOORD1FARBPROC      glMultiTexCoord1f         = NULL;
PFNGLMULTITEXCOORD1FVARBPROC     glMultiTexCoord1fv        = NULL;
PFNGLMULTITEXCOORD2FARBPROC      glMultiTexCoord2f         = NULL;
PFNGLMULTITEXCOORD2FVARBPROC     glMultiTexCoord2fv        = NULL;
PFNGLMULTITEXCOORD3FARBPROC      glMultiTexCoord3f         = NULL;
PFNGLMULTITEXCOORD3FVARBPROC     glMultiTexCoord3fv        = NULL;
PFNGLMULTITEXCOORD4FARBPROC      glMultiTexCoord4f         = NULL;
PFNGLMULTITEXCOORD4FVARBPROC     glMultiTexCoord4fv        = NULL;
// p-buffer functions
PFNWGLCREATEPBUFFERARBPROC              wglCreatePbufferARB     = NULL;
PFNWGLGETPBUFFERDCARBPROC               wglGetPbufferDCARB      = NULL;
PFNWGLRELEASEPBUFFERDCARBPROC           wglReleasePbufferDCARB  = NULL;
PFNWGLDESTROYPBUFFERARBPROC             wglDestroyPbufferARB    = NULL;
PFNWGLQUERYPBUFFERARBPROC               wglQueryPbufferARB      = NULL;
// WGL_ARB_pixel_format
PFNWGLCHOOSEPIXELFORMATARBPROC          wglChoosePixelFormatARB = NULL;
// WGL_ARB_render_texture
PFNWGLBINDTEXIMAGEARBPROC               wglBindTexImageARB      = NULL;
PFNWGLRELEASETEXIMAGEARBPROC            wglReleaseTexImageARB   = NULL;
PFNWGLSETPBUFFERATTRIBARBPROC           wglSetPbufferAttribARB  = NULL;
// WGL_EXT_swap_control
PFNWGLSWAPINTERVALEXTPROC               wglSwapIntervalEXT      = NULL;
PFNWGLGETSWAPINTERVALEXTPROC            wglGetSwapIntervalEXT   = NULL;
//fresh Linux already has 2.0 stencel ops from OpenGL 2.0
PFNGLSTENCILFUNCSEPARATEPROC					glStencilFuncSeparate  = NULL;
PFNGLSTENCILOPSEPARATEPROC						glStencilOpSeparate    = NULL;
PFNGLSTENCILMASKSEPARATEPROC					glStencilMaskSeparate  = NULL;
// blend ops from OPenGL 2.0
PFNGLBLENDEQUATIONPROC							glBlendEquation         = NULL;
PFNGLBLENDEQUATIONSEPARATEPROC		 			glBlendEquationSeparate = NULL;
PFNGLBLENDFUNCSEPARATEPROC						glBlendFuncSeparate     = NULL;
PFNGLBLENDCOLORPROC								glBlendColor            = NULL;
#else

// GLX_SGIX_pbuffer
PFNGLXCREATEGLXPBUFFERSGIXPROC          glXCreateGLXPbufferSGIX  = NULL;
PFNGLXDESTROYGLXPBUFFERSGIXPROC         glXDestroyGLXPbufferSGIX = NULL;
PFNGLXQUERYGLXPBUFFERSGIXPROC           glXQueryGLXPbufferSGIX   = NULL;
// GLX_SGIX_fbconfig
PFNGLXCHOOSEFBCONFIGSGIXPROC            glXChooseFBConfigSGIX          = NULL;
PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC   glXCreateContextWithConfigSGIX = NULL;

#endif

// fog coord function
PFNGLFOGCOORDFEXTPROC            glFogCoordf               = NULL;
// secondary color functions
PFNGLSECONDARYCOLOR3FPROC        glSecondaryColor3f        = NULL;
PFNGLSECONDARYCOLOR3FVPROC       glSecondaryColor3fv       = NULL;
PFNGLSECONDARYCOLORPOINTERPROC   glSecondaryColorPointer   = NULL;
// register combiners functions
PFNGLCOMBINERPARAMETERFVNVPROC   glCombinerParameterfvNV   = NULL;
PFNGLCOMBINERPARAMETERIVNVPROC   glCombinerParameterivNV   = NULL;
PFNGLCOMBINERPARAMETERFNVPROC    glCombinerParameterfNV    = NULL;
PFNGLCOMBINERPARAMETERINVPROC    glCombinerParameteriNV    = NULL;
PFNGLCOMBINERINPUTNVPROC         glCombinerInputNV         = NULL;
PFNGLCOMBINEROUTPUTNVPROC        glCombinerOutputNV        = NULL;
PFNGLFINALCOMBINERINPUTNVPROC    glFinalCombinerInputNV    = NULL;
// VBO functions
PFNGLBINDBUFFERARBPROC           glBindBufferARB           = NULL;
PFNGLDELETEBUFFERSARBPROC        glDeleteBuffersARB        = NULL;
PFNGLGENBUFFERSARBPROC           glGenBuffersARB           = NULL;
PFNGLISBUFFERARBPROC             glIsBufferARB             = NULL;
PFNGLBUFFERDATAARBPROC           glBufferDataARB           = NULL;
PFNGLBUFFERSUBDATAARBPROC        glBufferSubDataARB        = NULL;
PFNGLGETBUFFERSUBDATAARBPROC     glGetBufferSubDataARB     = NULL;
PFNGLMAPBUFFERARBPROC            glMapBufferARB            = NULL;
PFNGLUNMAPBUFFERARBPROC          glUnmapBufferARB          = NULL;
PFNGLGETBUFFERPARAMETERIVARBPROC glGetBufferParameterivARB = NULL;
PFNGLGETBUFFERPOINTERVARBPROC    glGetBufferPointervARB    = NULL;
// NV-occlusion query extension
PFNGLGENOCCLUSIONQUERIESNVPROC          glGenOcclusionQueriesNV = NULL;
PFNGLBEGINOCCLUSIONQUERYNVPROC          glBeginOcclusionQueryNV = NULL;
PFNGLENDOCCLUSIONQUERYNVPROC            glEndOcclusionQueryNV   = NULL;
PFNGLGETOCCLUSIONQUERYIVNVPROC          glGetOcclusionQueryivNV = NULL;
// ARB_vertex_program extension
PFNGLGENPROGRAMSARBPROC                 glGenProgramsARB        = NULL;
PFNGLDELETEPROGRAMSARBPROC              glDeleteProgramsARB     = NULL;
PFNGLBINDPROGRAMARBPROC                 glBindProgramARB        = NULL;
PFNGLISPROGRAMARBPROC                   glIsProgramARB          = NULL;

PFNGLPROGRAMSTRINGARBPROC               glProgramStringARB      = NULL;
PFNGLGETPROGRAMIVARBPROC                glGetProgramivARB       = NULL;

PFNGLVERTEXATTRIB4FARBPROC              glVertexAttrib4fARB     = NULL;
PFNGLVERTEXATTRIB4FVARBPROC             glVertexAttrib4fvARB    = NULL;
PFNGLVERTEXATTRIB3FARBPROC              glVertexAttrib3fARB     = NULL;
PFNGLVERTEXATTRIB3FVARBPROC             glVertexAttrib3fvARB    = NULL;

PFNGLVERTEXATTRIBPOINTERARBPROC         glVertexAttribPointerARB        = NULL;
PFNGLENABLEVERTEXATTRIBARRAYARBPROC     glEnableVertexAttribArrayARB    = NULL;
PFNGLDISABLEVERTEXATTRIBARRAYARBPROC    glDisableVertexAttribArrayARB   = NULL;

PFNGLPROGRAMLOCALPARAMETER4FARBPROC     glProgramLocalParameter4fARB    = NULL;
PFNGLPROGRAMLOCALPARAMETER4FVARBPROC    glProgramLocalParameter4fvARB   = NULL;

PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC  glGetProgramLocalParameterfvARB = NULL;

PFNGLPROGRAMENVPARAMETER4FARBPROC       glProgramEnvParameter4fARB      = NULL;
PFNGLPROGRAMENVPARAMETER4FVARBPROC      glProgramEnvParameter4fvARB     = NULL;

PFNGLGETPROGRAMENVPARAMETERFVARBPROC    glGetProgramEnvParameterfvARB   = NULL;
// GL_EXT_texture3D
PFNGLTEXIMAGE3DEXTPROC                  glTexImage3DEXT                  = NULL;
// ARB_texture_compression
PFNGLCOMPRESSEDTEXIMAGE3DARBPROC        glCompressedTexImage3DARB        = NULL;
PFNGLCOMPRESSEDTEXIMAGE2DARBPROC        glCompressedTexImage2DARB        = NULL;
PFNGLCOMPRESSEDTEXIMAGE1DARBPROC        glCompressedTexImage1DARB        = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC     glCompressedTexSubImage3DARB     = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC     glCompressedTexSubImage2DARB     = NULL;
PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC     glCompressedTexSubImage1DARB     = NULL;
PFNGLGETCOMPRESSEDTEXIMAGEARBPROC       glGetCompressedTexImageARB       = NULL;
// ARB_point_parameters
PFNGLPOINTPARAMETERFARBPROC             glPointParameterfARB             = NULL;
PFNGLPOINTPARAMETERFVARBPROC            glPointParameterfvARB            = NULL;
// ARB_occlusion_query
PFNGLGENQUERIESARBPROC                  glGenQueriesARB        = NULL;
PFNGLDELETEQUERIESARBPROC               glDeleteQueriesARB     = NULL;
PFNGLISQUERYARBPROC                     glIsQueryARB           = NULL;
PFNGLBEGINQUERYARBPROC                  glBeginQueryARB        = NULL;
PFNGLENDQUERYARBPROC                    glEndQueryARB          = NULL;
PFNGLGETQUERYIVARBPROC                  glGetQueryivARB        = NULL;
PFNGLGETQUERYOBJECTIVARBPROC            glGetQueryObjectivARB  = NULL;
PFNGLGETQUERYOBJECTUIVARBPROC           glGetQueryObjectuivARB = NULL;
// GLSL-specific extensions
// GL_ARB_shader_object
PFNGLDELETEOBJECTARBPROC                glDeleteObjectARB         = NULL;
PFNGLGETHANDLEARBPROC                   glGetHandleARB            = NULL;
PFNGLDETACHOBJECTARBPROC                glDetachObjectARB         = NULL;
PFNGLCREATESHADEROBJECTARBPROC          glCreateShaderObjectARB   = NULL;
PFNGLSHADERSOURCEARBPROC                glShaderSourceARB         = NULL;
PFNGLCOMPILESHADERARBPROC               glCompileShaderARB        = NULL;
PFNGLCREATEPROGRAMOBJECTARBPROC         glCreateProgramObjectARB  = NULL;
PFNGLATTACHOBJECTARBPROC                glAttachObjectARB         = NULL;
PFNGLLINKPROGRAMARBPROC                 glLinkProgramARB          = NULL;
PFNGLUSEPROGRAMOBJECTARBPROC            glUseProgramObjectARB     = NULL;
PFNGLVALIDATEPROGRAMARBPROC             glValidateProgramARB      = NULL;
PFNGLUNIFORM1FARBPROC                   glUniform1fARB            = NULL;
PFNGLUNIFORM2FARBPROC                   glUniform2fARB            = NULL;
PFNGLUNIFORM3FARBPROC                   glUniform3fARB            = NULL;
PFNGLUNIFORM4FARBPROC                   glUniform4fARB            = NULL;
PFNGLUNIFORM1IARBPROC                   glUniform1iARB            = NULL;
PFNGLUNIFORM2IARBPROC                   glUniform2iARB            = NULL;
PFNGLUNIFORM3IARBPROC                   glUniform3iARB            = NULL;
PFNGLUNIFORM4IARBPROC                   glUniform4iARB            = NULL;
PFNGLUNIFORM1FVARBPROC                  glUniform1fvARB           = NULL;
PFNGLUNIFORM2FVARBPROC                  glUniform2fvARB           = NULL;
PFNGLUNIFORM3FVARBPROC                  glUniform3fvARB           = NULL;
PFNGLUNIFORM4FVARBPROC                  glUniform4fvARB           = NULL;
PFNGLUNIFORM1IVARBPROC                  glUniform1ivARB           = NULL;
PFNGLUNIFORM2IVARBPROC                  glUniform2ivARB           = NULL;
PFNGLUNIFORM3IVARBPROC                  glUniform3ivARB           = NULL;
PFNGLUNIFORM4IVARBPROC                  glUniform4ivARB           = NULL;
PFNGLUNIFORMMATRIX2FVARBPROC            glUniformMatrix2fvARB     = NULL;
PFNGLUNIFORMMATRIX3FVARBPROC            glUniformMatrix3fvARB     = NULL;
PFNGLUNIFORMMATRIX4FVARBPROC            glUniformMatrix4fvARB     = NULL;
PFNGLGETOBJECTPARAMETERFVARBPROC        glGetObjectParameterfvARB = NULL;
PFNGLGETOBJECTPARAMETERIVARBPROC        glGetObjectParameterivARB = NULL;
PFNGLGETINFOLOGARBPROC                  glGetInfoLogARB           = NULL;
PFNGLGETATTACHEDOBJECTSARBPROC          glGetAttachedObjectsARB   = NULL;
PFNGLGETUNIFORMLOCATIONARBPROC          glGetUniformLocationARB   = NULL;
PFNGLGETACTIVEUNIFORMARBPROC            glGetActiveUniformARB     = NULL;
PFNGLGETUNIFORMFVARBPROC                glGetUniformfvARB         = NULL;
PFNGLGETUNIFORMIVARBPROC                glGetUniformivARB         = NULL;
PFNGLGETSHADERSOURCEARBPROC             glGetShaderSourceARB      = NULL;
// GL_ARB_vertex_shader
PFNGLBINDATTRIBLOCATIONARBPROC          glBindAttribLocationARB   = NULL;
PFNGLGETACTIVEATTRIBARBPROC             glGetActiveAttribARB      = NULL;
PFNGLGETATTRIBLOCATIONARBPROC           glGetAttribLocationARB    = NULL;
PFNGLGETVERTEXATTRIBFVARBPROC           glGetVertexAttribfvARB    = NULL;
// EXT_stencil_two_side
PFNGLACTIVESTENCILFACEEXTPROC           glActiveStencilFaceEXT    = NULL;
// EXT_depth_bounds_test
PFNGLDEPTHBOUNDSEXTPROC			glDepthBoundsEXT                  = NULL;
// EXT_framebuffer_object
PFNGLISRENDERBUFFEREXTPROC						glIsRenderbufferEXT                      = NULL;
PFNGLBINDRENDERBUFFEREXTPROC					glBindRenderbufferEXT                    = NULL;
PFNGLDELETERENDERBUFFERSEXTPROC					glDeleteRenderbuffersEXT                 = NULL;
PFNGLGENRENDERBUFFERSEXTPROC					glGenRenderbuffersEXT                    = NULL;
PFNGLRENDERBUFFERSTORAGEEXTPROC					glRenderbufferStorageEXT                 = NULL;
PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC			glGetRenderbufferParameterivEXT          = NULL;
PFNGLISFRAMEBUFFEREXTPROC						glIsFramebufferEXT                       = NULL;
PFNGLBINDFRAMEBUFFEREXTPROC						glBindFramebufferEXT                     = NULL;
PFNGLDELETEFRAMEBUFFERSEXTPROC					glDeleteFramebuffersEXT                  = NULL;
PFNGLGENFRAMEBUFFERSEXTPROC						glGenFramebuffersEXT                     = NULL;
PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC				glCheckFramebufferStatusEXT              = NULL;
PFNGLFRAMEBUFFERTEXTURE1DEXTPROC				glFramebufferTexture1DEXT                = NULL;
PFNGLFRAMEBUFFERTEXTURE2DEXTPROC				glFramebufferTexture2DEXT                = NULL;
PFNGLFRAMEBUFFERTEXTURE3DEXTPROC				glFramebufferTexture3DEXT                = NULL;
PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC				glFramebufferRenderbufferEXT             = NULL;
PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC	glGetFramebufferAttachmentParameterivEXT = NULL;
PFNGLGENERATEMIPMAPEXTPROC						glGenerateMipmapEXT                      = NULL;

#ifndef	GL_VERSION_1_3			// ARB_transpose matrix
PFNGLLOADTRANSPOSEMATRIXFPROC					glLoadTransposeMatrixfARB                = NULL;
PFNGLLOADTRANSPOSEMATRIXDPROC					glLoadTransposeMatrixdARB                = NULL;
PFNGLMULTTRANSPOSEMATRIXFPROC					glMultTransposeMatrixfARB                = NULL;
PFNGLMULTTRANSPOSEMATRIXDPROC					glMultTransposeMatrixdARB                = NULL;
#endif

// ARB_color_buffer_float
PFNGLCLAMPCOLORARBPROC							glClampColorARB        = NULL;
// draw buffers from OpenGL 2.0
PFNGLDRAWBUFFERSPROC							glDrawBuffers           = NULL;
// ATI_draw_buffers
PFNGLDRAWBUFFERSATIPROC							glDrawBuffersATI        = NULL;
// EXT_texture_integer
PFNGLTEXPARAMETERIIVEXTPROC				glTexParameterIivEXT      = NULL;
PFNGLTEXPARAMETERIUIVEXTPROC			glTexParameterIuivEXT     = NULL;
PFNGLGETTEXPARAMETERIIVEXTPROC			glGetTexParameterIivEXT   = NULL;
PFNGLGETTEXPARAMETERIUIVEXTPROC			glGetTexParameterIuivEXT  = NULL;
PFNGLCLEARCOLORIIEXTPROC				glClearColorIiEXT         = NULL;
PFNGLCLEARCOLORIUIEXTPROC				glClearColorIuiEXT        = NULL;
// EXT_draw_instanced
PFNGLDRAWARRAYSINSTANCEDEXTPROC			glDrawArraysInstancedEXT  = NULL;
PFNGLDRAWELEMENTSINSTANCEDEXTPROC		glDrawElementsInstancedEXT  = NULL;
// EXT_texture_buffer_object
PFNGLTEXBUFFEREXTPROC 					glTexBufferEXT  = NULL;
// EXT_gpu_shader4
PFNGLGETUNIFORMUIVEXTPROC				glGetUniformuivEXT        = NULL;
PFNGLBINDFRAGDATALOCATIONEXTPROC		glBindFragDataLocationEXT = NULL;
PFNGLGETFRAGDATALOCATIONEXTPROC			glGetFragDataLocationEXT  = NULL;
PFNGLUNIFORM1UIEXTPROC					glUniform1uiEXT           = NULL;
PFNGLUNIFORM2UIEXTPROC					glUniform2uiEXT           = NULL;
PFNGLUNIFORM3UIEXTPROC					glUniform3uiEXT           = NULL;
PFNGLUNIFORM4UIEXTPROC					glUniform4uiEXT           = NULL;
PFNGLUNIFORM1UIVEXTPROC					glUniform1uivEXT          = NULL;
PFNGLUNIFORM2UIVEXTPROC					glUniform2uivEXT          = NULL;
PFNGLUNIFORM3UIVEXTPROC					glUniform3uivEXT          = NULL;
PFNGLUNIFORM4UIVEXTPROC					glUniform4uivEXT          = NULL;
PFNGLVERTEXATTRIBI1IEXTPROC				glVertexAttribI1iEXT      = NULL;
PFNGLVERTEXATTRIBI2IEXTPROC				glVertexAttribI2iEXT      = NULL;
PFNGLVERTEXATTRIBI3IEXTPROC				glVertexAttribI3iEXT      = NULL;
PFNGLVERTEXATTRIBI4IEXTPROC				glVertexAttribI4iEXT      = NULL;
PFNGLVERTEXATTRIBI1UIEXTPROC			glVertexAttribI1uiEXT     = NULL;
PFNGLVERTEXATTRIBI2UIEXTPROC			glVertexAttribI2uiEXT     = NULL;
PFNGLVERTEXATTRIBI3UIEXTPROC			glVertexAttribI3uiEXT     = NULL;
PFNGLVERTEXATTRIBI4UIEXTPROC			glVertexAttribI4uiEXT     = NULL;
PFNGLVERTEXATTRIBI1IVEXTPROC			glVertexAttribI1ivEXT     = NULL;
PFNGLVERTEXATTRIBI2IVEXTPROC			glVertexAttribI2ivEXT     = NULL;
PFNGLVERTEXATTRIBI3IVEXTPROC			glVertexAttribI3ivEXT     = NULL;
PFNGLVERTEXATTRIBI4IVEXTPROC			glVertexAttribI4ivEXT     = NULL;
PFNGLVERTEXATTRIBI1UIVEXTPROC			glVertexAttribI1uivEXT    = NULL;
PFNGLVERTEXATTRIBI2UIVEXTPROC			glVertexAttribI2uivEXT    = NULL;
PFNGLVERTEXATTRIBI3UIVEXTPROC			glVertexAttribI3uivEXT    = NULL;
PFNGLVERTEXATTRIBI4UIVEXTPROC			glVertexAttribI4uivEXT    = NULL;
PFNGLVERTEXATTRIBI4BVEXTPROC			glVertexAttribI4bvEXT     = NULL;
PFNGLVERTEXATTRIBI4SVEXTPROC			glVertexAttribI4svEXT     = NULL;
PFNGLVERTEXATTRIBI4UBVEXTPROC			glVertexAttribI4ubvEXT    = NULL;
PFNGLVERTEXATTRIBI4USVEXTPROC			glVertexAttribI4usvEXT    = NULL;
PFNGLVERTEXATTRIBIPOINTEREXTPROC		glVertexAttribIPointerEXT = NULL;
PFNGLGETVERTEXATTRIBIIVEXTPROC			glGetVertexAttribIivEXT   = NULL;
PFNGLGETVERTEXATTRIBIUIVEXTPROC			glGetVertexAttribIuivEXT  = NULL;
// EXT_geometry_shader4
PFNGLPROGRAMPARAMETERIEXTPROC			glProgramParameteriEXT       = NULL;
PFNGLFRAMEBUFFERTEXTUREEXTPROC			glFramebufferTextureEXT      = NULL;
PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC		glFramebufferTextureLayerEXT = NULL;
PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC		glFramebufferTextureFaceEXT  = NULL;
// EXT_bindable_uniform
PFNGLUNIFORMBUFFEREXTPROC				glUniformBufferEXT           = NULL;
PFNGLGETUNIFORMBUFFERSIZEEXTPROC		glGetUniformBufferSizeEXT    = NULL;
PFNGLGETUNIFORMOFFSETEXTPROC			glGetUniformOffsetEXT        = NULL;
// OpenGL 2.0 shader support
PFNGLCOMPILESHADERPROC					glCompileShader       = NULL;
PFNGLCREATEPROGRAMPROC					glCreateProgram       = NULL;
PFNGLCREATESHADERPROC					glCreateShader        = NULL;
PFNGLDELETEPROGRAMPROC					glDeleteProgram       = NULL;
PFNGLDELETESHADERPROC					glDeleteShader        = NULL;
PFNGLDETACHSHADERPROC					glDetachShader        = NULL;
PFNGLGETPROGRAMINFOLOGPROC				glGetProgramInfoLog   = NULL;
PFNGLGETSHADERINFOLOGPROC				glGetShaderInfoLog    = NULL;
PFNGLGETSHADERSOURCEPROC				glGetShaderSource     = NULL;
PFNGLLINKPROGRAMPROC					glLinkProgram         = NULL;
PFNGLSHADERSOURCEPROC					glShaderSource        = NULL;
PFNGLUSEPROGRAMPROC						glUseProgram          = NULL;
PFNGLVALIDATEPROGRAMPROC				glValidateProgram     = NULL;
PFNGLGETPROGRAMIVPROC					glGetProgramiv        = NULL;
PFNGLGETSHADERIVPROC					glGetShaderiv         = NULL;
PFNGLATTACHSHADERPROC					glAttachShader        = NULL;
PFNGLGETUNIFORMLOCATIONPROC				glGetUniformLocation  = NULL;
PFNGLGETATTRIBLOCATIONPROC				glGetAttribLocation   = NULL;
PFNGLUNIFORM4FVPROC						glUniform4fv          = NULL;
PFNGLUNIFORM3FVPROC						glUniform3fv          = NULL;
PFNGLUNIFORM2FVPROC						glUniform2fv          = NULL;
PFNGLUNIFORM1FPROC						glUniform1f           = NULL;
PFNGLUNIFORM1IPROC						glUniform1i           = NULL;
PFNGLUNIFORMMATRIX2FVPROC				glUniformMatrix2fv    = NULL;
PFNGLUNIFORMMATRIX3FVPROC				glUniformMatrix3fv    = NULL;
PFNGLUNIFORMMATRIX4FVPROC				glUniformMatrix4fv    = NULL;
PFNGLGETUNIFORMFVPROC					glGetUniformfv        = NULL;
PFNGLVERTEXATTRIB4FVPROC				glVertexAttrib4fv     = NULL;
PFNGLGETVERTEXATTRIBFVPROC				glGetVertexAttribfv   = NULL;
// OpenGL 2 query support
PFNGLGENQUERIESPROC                     glGenQueries        = NULL;
PFNGLDELETEQUERIESPROC                  glDeleteQueries     = NULL;
PFNGLISQUERYPROC                        glIsQuery           = NULL;
PFNGLBEGINQUERYPROC                     glBeginQuery        = NULL;
PFNGLENDQUERYPROC                       glEndQuery          = NULL;
PFNGLGETQUERYIVPROC                     glGetQueryiv        = NULL;
PFNGLGETQUERYOBJECTIVPROC               glGetQueryObjectiv  = NULL;
PFNGLGETQUERYOBJECTUIVPROC              glGetQueryObjectuiv = NULL;
// NV_transform_feedback
PFNGLBEGINTRANSFORMFEEDBACKNVPROC		glBeginTransformFeedbackNV      = NULL;
PFNGLENDTRANSFORMFEEDBACKNVPROC			glEndTransformFeedbackNV        = NULL;
PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC		glTransformFeedbackAttribsNV    = NULL;
PFNGLBINDBUFFERRANGENVPROC				glBindBufferRangeNV             = NULL;
PFNGLBINDBUFFEROFFSETNVPROC				glBindBufferOffsetNV            = NULL;
PFNGLBINDBUFFERBASENVPROC				glBindBufferBaseNV              = NULL;
PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC	glTransformFeedbackVaryingsNV   = NULL;
PFNGLACTIVEVARYINGNVPROC				glActiveVaryingNV               = NULL;
PFNGLGETVARYINGLOCATIONNVPROC			glGetVaryingLocationNV          = NULL;
PFNGLGETACTIVEVARYINGNVPROC				glGetActiveVaryingNV            = NULL;
PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC	glGetTransformFeedbackVaryingNV = NULL;
// NV_fence
PFNGLDELETEFENCESNVPROC					glDeleteFencesNV = NULL;
PFNGLGENFENCESNVPROC					glGenFencesNV    = NULL;
PFNGLISFENCENVPROC						glIsFenceNV      = NULL;
PFNGLTESTFENCENVPROC					glTestFenceNV    = NULL;
PFNGLGETFENCEIVNVPROC					glGetFenceivNV   = NULL;
PFNGLFINISHFENCENVPROC					glFinishFenceNV  = NULL;
PFNGLSETFENCENVPROC						glSetFenceNV     = NULL;
// NV__conditional_render
PFNGLBEGINCONDITIONALRENDERNVPROC		glBeginConditionalRenderNV = NULL;
PFNGLENDCONDITIONALRENDERNVPROC			glEndConditionalRenderNV   = NULL;
// ARB_sampler_objects
PFNGLGENSAMPLERSPROC			glGenSamplers            = NULL;
PFNGLDELETESAMPLERSPROC			glDeleteSamplers         = NULL;
PFNGLISSAMPLERPROC				glIsSampler              = NULL;
PFNGLBINDSAMPLERPROC			glBindSampler            = NULL;
PFNGLSAMPLERPARAMETERIPROC		glSamplerParameteri      = NULL;
PFNGLSAMPLERPARAMETERIVPROC		glSamplerParameteriv     = NULL;
PFNGLSAMPLERPARAMETERFPROC		glSamplerParameterf      = NULL;
PFNGLSAMPLERPARAMETERFVPROC		glSamplerParameterfv     = NULL;
PFNGLSAMPLERPARAMETERIIVPROC	glSamplerParameterIiv    = NULL;
PFNGLSAMPLERPARAMETERIUIVPROC	glSamplerParameterIuiv   = NULL;
PFNGLGETSAMPLERPARAMETERIVPROC	glGetSamplerParameteriv  = NULL;
PFNGLGETSAMPLERPARAMETERIIVPROC	glGetSamplerParameterIiv = NULL;
PFNGLGETSAMPLERPARAMETERFVPROC	glGetSamplerParameterfv  = NULL;
PFNGLGETSAMPLERPARAMETERIFVPROC	glGetSamplerParameterIfv = NULL;
// ARB_get_program_binary
PFNGLGETPROGRAMBINARYPROC  glGetProgramBinary  = NULL;
PFNGLPROGRAMBINARYPROC     glProgramBinary     = NULL;
PFNGLPROGRAMPARAMETERIPROC glProgramParameteri = NULL;
// ARB_vertex_array_object
PFNGLBINDVERTEXARRAYPROC		glBindVertexArray    = NULL;
PFNGLDELETEVERTEXARRAYSPROC		glDeleteVertexArrays = NULL;
PFNGLGENVERTEXARRAYSPROC		glGenVertexArrays    = NULL;
PFNGLISVERTEXARRAYPROC			glIsVertexArray      = NULL;
// ARB_instanced_arrays
//PFNGLVERTEXATTRIBDIVISORARBPROC	glVertexAttribDivisor = NULL;


////////////////////////// functions ////////////////////////////

/*
==========================
	EXTENTIONS INIT
==========================
*/

//WIN32 OR LINUX
#ifdef  _WIN32
boolean    initWin32Extensions ()
{
	const char * exts;

    wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC) wglGetProcAddress ( "wglGetExtensionsStringARB" );

    if ( wglGetExtensionsStringARB == NULL )
        return false;

    exts = wglGetExtensionsStringARB ( wglGetCurrentDC () );

    if ( exts == NULL )
        return false;

    if ( strstr ( exts, "WGL_ARB_pbuffer" ) != NULL )
    {
        wglCreatePbufferARB    = (PFNWGLCREATEPBUFFERARBPROC)     wglGetProcAddress ( "wglCreatePbufferARB"    );
        wglGetPbufferDCARB     = (PFNWGLGETPBUFFERDCARBPROC)      wglGetProcAddress ( "wglGetPbufferDCARB"     );
        wglReleasePbufferDCARB = (PFNWGLRELEASEPBUFFERDCARBPROC)  wglGetProcAddress ( "wglReleasePbufferDCARB" );
        wglDestroyPbufferARB   = (PFNWGLDESTROYPBUFFERARBPROC)    wglGetProcAddress ( "wglDestroyPbufferARB"   );
        wglQueryPbufferARB     = (PFNWGLQUERYPBUFFERARBPROC)      wglGetProcAddress ( "wglQueryPbufferARB"     );
    }

    if ( strstr ( exts, "WGL_ARB_pixel_format" ) != NULL )
        wglChoosePixelFormatARB = (PFNWGLCHOOSEPIXELFORMATARBPROC)wglGetProcAddress ( "wglChoosePixelFormatARB" );

    if ( strstr ( exts, "WGL_ARB_render_texture" ) != NULL )
    {
        wglBindTexImageARB      = (PFNWGLBINDTEXIMAGEARBPROC)     wglGetProcAddress ( "wglBindTexImageARB"     );
        wglReleaseTexImageARB   = (PFNWGLRELEASETEXIMAGEARBPROC)  wglGetProcAddress ( "wglReleaseTexImageARB"  );
        wglSetPbufferAttribARB  = (PFNWGLSETPBUFFERATTRIBARBPROC) wglGetProcAddress ( "wglSetPbufferAttribARB" );
    }

    if ( strstr ( exts, "WGL_EXT_swap_control" ) != NULL )
    {
        wglSwapIntervalEXT      = (PFNWGLSWAPINTERVALEXTPROC)       wglGetProcAddress ( "wglSwapIntervalEXT"    );
        wglGetSwapIntervalEXT   = (PFNWGLGETSWAPINTERVALEXTPROC)    wglGetProcAddress ( "wglGetSwapIntervalEXT" );
    }

    return true;
}
#else
void    initLinuxExtensions ()
{
                                    // GLX_SGIX_pbuffer
    glXCreateGLXPbufferSGIX  = (PFNGLXCREATEGLXPBUFFERSGIXPROC)  wglGetProcAddress ( "glXCreateGLXPbufferSGIX" );
    glXDestroyGLXPbufferSGIX = (PFNGLXDESTROYGLXPBUFFERSGIXPROC) wglGetProcAddress ( "glXDestroyGLXPbufferSGIX" );
    glXQueryGLXPbufferSGIX   = (PFNGLXQUERYGLXPBUFFERSGIXPROC)   wglGetProcAddress ( "glXQueryGLXPbufferSGIX" );

                                    // GLX_SGIX_fbconfig
    glXChooseFBConfigSGIX          = (PFNGLXCHOOSEFBCONFIGSGIXPROC)          wglGetProcAddress ( "glXChooseFBConfigSGIX" );
    glXCreateContextWithConfigSGIX = (PFNGLXCREATECONTEXTWITHCONFIGSGIXPROC) wglGetProcAddress ( "glXCreateContextWithConfigSGIX" );
}
#endif

/*
==========================
	ALL EXTENTIONS INIT
==========================
*/

void	GL_Init_All_Extensions (void)
{
    if ( extinitialized )
	      return;

#ifdef  _WIN32
    glActiveTextureARB       = (PFNGLACTIVETEXTUREARBPROC)         wglGetProcAddress ( "glActiveTextureARB"       );
    glClientActiveTextureARB = (PFNGLCLIENTACTIVETEXTUREARBPROC)   wglGetProcAddress ( "glClientActiveTextureARB" );
    glMultiTexCoord1f        = (PFNGLMULTITEXCOORD1FARBPROC)       wglGetProcAddress ( "glMultiTexCoord1fARB"     );
    glMultiTexCoord1fv       = (PFNGLMULTITEXCOORD1FVARBPROC)      wglGetProcAddress ( "glMultiTexCoord1fvARB"    );
    glMultiTexCoord2f        = (PFNGLMULTITEXCOORD2FARBPROC)       wglGetProcAddress ( "glMultiTexCoord2fARB"     );
    glMultiTexCoord2fv       = (PFNGLMULTITEXCOORD2FVARBPROC)      wglGetProcAddress ( "glMultiTexCoord2fvARB"    );
    glMultiTexCoord3f        = (PFNGLMULTITEXCOORD3FARBPROC)       wglGetProcAddress ( "glMultiTexCoord3fARB"     );
    glMultiTexCoord3fv       = (PFNGLMULTITEXCOORD3FVARBPROC)      wglGetProcAddress ( "glMultiTexCoord3fvARB"    );
    glMultiTexCoord4f        = (PFNGLMULTITEXCOORD4FARBPROC)       wglGetProcAddress ( "glMultiTexCoord4fARB"     );
    glMultiTexCoord4fv       = (PFNGLMULTITEXCOORD4FVARBPROC)      wglGetProcAddress ( "glMultiTexCoord4fvARB"    );
#endif

    glFogCoordf              = (PFNGLFOGCOORDFEXTPROC)             wglGetProcAddress ( "glFogCoordfEXT"         );
    glSecondaryColor3f       = (PFNGLSECONDARYCOLOR3FPROC)         wglGetProcAddress ( "glSecondaryColor3fEXT"      );
    glSecondaryColor3fv      = (PFNGLSECONDARYCOLOR3FVPROC)        wglGetProcAddress ( "glSecondaryColor3fvEXT"     );
    glSecondaryColorPointer  = (PFNGLSECONDARYCOLORPOINTERPROC)    wglGetProcAddress ( "glSecondaryColorPointerEXT" );
    glCombinerParameterfvNV  = (PFNGLCOMBINERPARAMETERFVNVPROC)    wglGetProcAddress ( "glCombinerParameterfvNV"  );
    glCombinerParameterivNV  = (PFNGLCOMBINERPARAMETERIVNVPROC)    wglGetProcAddress ( "glCombinerParameterivNV"  );
    glCombinerParameterfNV   = (PFNGLCOMBINERPARAMETERFNVPROC)     wglGetProcAddress ( "glCombinerParameterfNV"   );
    glCombinerParameteriNV   = (PFNGLCOMBINERPARAMETERINVPROC)     wglGetProcAddress ( "glCombinerParameteriNV"   );
    glCombinerInputNV        = (PFNGLCOMBINERINPUTNVPROC)          wglGetProcAddress ( "glCombinerInputNV"        );
    glCombinerOutputNV       = (PFNGLCOMBINEROUTPUTNVPROC)         wglGetProcAddress ( "glCombinerOutputNV"       );
    glFinalCombinerInputNV   = (PFNGLFINALCOMBINERINPUTNVPROC)     wglGetProcAddress ( "glFinalCombinerInputNV"   );
    glBindBufferARB           = (PFNGLBINDBUFFERARBPROC)           wglGetProcAddress ( "glBindBufferARB"           );
    glDeleteBuffersARB        = (PFNGLDELETEBUFFERSARBPROC)        wglGetProcAddress ( "glDeleteBuffersARB"        );
    glGenBuffersARB           = (PFNGLGENBUFFERSARBPROC)           wglGetProcAddress ( "glGenBuffersARB"           );
    glIsBufferARB             = (PFNGLISBUFFERARBPROC)             wglGetProcAddress ( "glIsBufferARB"             );
    glBufferDataARB           = (PFNGLBUFFERDATAARBPROC)           wglGetProcAddress ( "glBufferDataARB"           );
    glBufferSubDataARB        = (PFNGLBUFFERSUBDATAARBPROC)        wglGetProcAddress ( "glBufferSubDataARB"        );
    glGetBufferSubDataARB     = (PFNGLGETBUFFERSUBDATAARBPROC)     wglGetProcAddress ( "glGetBufferSubDataARB"     );
    glMapBufferARB            = (PFNGLMAPBUFFERARBPROC)            wglGetProcAddress ( "glMapBufferARB"            );
    glUnmapBufferARB          = (PFNGLUNMAPBUFFERARBPROC)          wglGetProcAddress ( "glUnmapBufferARB"          );
    glGetBufferParameterivARB = (PFNGLGETBUFFERPARAMETERIVARBPROC) wglGetProcAddress ( "glGetBufferParameterivARB" );
    glGetBufferPointervARB    = (PFNGLGETBUFFERPOINTERVARBPROC)    wglGetProcAddress ( "glGetBufferPointervARB"    );
	// NV-occlusion query extension
    glGenOcclusionQueriesNV = (PFNGLGENOCCLUSIONQUERIESNVPROC) wglGetProcAddress ( "glGenOcclusionQueriesNV" );
    glBeginOcclusionQueryNV = (PFNGLBEGINOCCLUSIONQUERYNVPROC) wglGetProcAddress ( "glBeginOcclusionQueryNV" );
    glEndOcclusionQueryNV   = (PFNGLENDOCCLUSIONQUERYNVPROC)   wglGetProcAddress ( "glEndOcclusionQueryNV"   );
    glGetOcclusionQueryivNV = (PFNGLGETOCCLUSIONQUERYIVNVPROC) wglGetProcAddress ( "glGetOcclusionQueryivNV" );
	// ARB_vertex_program extension
    glGenProgramsARB                = (PFNGLGENPROGRAMSARBPROC)               wglGetProcAddress ( "glGenProgramsARB" );
    glDeleteProgramsARB             = (PFNGLDELETEPROGRAMSARBPROC)            wglGetProcAddress ( "glDeleteProgramsARB" );
    glBindProgramARB                = (PFNGLBINDPROGRAMARBPROC)               wglGetProcAddress ( "glBindProgramARB" );
    glIsProgramARB                  = (PFNGLISPROGRAMARBPROC)                 wglGetProcAddress ( "glIsProgramARB" );
    glProgramStringARB              = (PFNGLPROGRAMSTRINGARBPROC)             wglGetProcAddress ( "glProgramStringARB" );
    glGetProgramivARB               = (PFNGLGETPROGRAMIVARBPROC)              wglGetProcAddress ( "glGetProgramivARB" );
    glVertexAttrib4fARB             = (PFNGLVERTEXATTRIB4FARBPROC)            wglGetProcAddress ( "glVertexAttrib4fARB" );
    glVertexAttrib4fvARB            = (PFNGLVERTEXATTRIB4FVARBPROC)           wglGetProcAddress ( "glVertexAttrib4fvARB" );
    glVertexAttrib3fARB             = (PFNGLVERTEXATTRIB3FARBPROC)            wglGetProcAddress ( "glVertexAttrib3fARB" );
    glVertexAttrib3fvARB            = (PFNGLVERTEXATTRIB3FVARBPROC)           wglGetProcAddress ( "glVertexAttrib3fvARB" );
    glVertexAttribPointerARB        = (PFNGLVERTEXATTRIBPOINTERARBPROC)       wglGetProcAddress ( "glVertexAttribPointerARB" );
    glEnableVertexAttribArrayARB    = (PFNGLENABLEVERTEXATTRIBARRAYARBPROC)   wglGetProcAddress ( "glEnableVertexAttribArrayARB" );
    glDisableVertexAttribArrayARB   = (PFNGLDISABLEVERTEXATTRIBARRAYARBPROC)  wglGetProcAddress ( "glDisableVertexAttribArrayARB" );
    glProgramLocalParameter4fARB    = (PFNGLPROGRAMLOCALPARAMETER4FARBPROC)   wglGetProcAddress ( "glProgramLocalParameter4fARB" );
    glProgramLocalParameter4fvARB   = (PFNGLPROGRAMLOCALPARAMETER4FVARBPROC)  wglGetProcAddress ( "glProgramLocalParameter4fvARB" );
    glGetProgramLocalParameterfvARB = (PFNGLGETPROGRAMLOCALPARAMETERFVARBPROC)wglGetProcAddress ( "glGetProgramLocalParameterfvARB" );
    glProgramEnvParameter4fARB      = (PFNGLPROGRAMENVPARAMETER4FARBPROC)     wglGetProcAddress ( "glProgramEnvParameter4fARB" );
    glProgramEnvParameter4fvARB     = (PFNGLPROGRAMENVPARAMETER4FVARBPROC)    wglGetProcAddress ( "glProgramEnvParameter4fvARB" );
    glGetProgramEnvParameterfvARB   = (PFNGLGETPROGRAMENVPARAMETERFVARBPROC)  wglGetProcAddress ( "glGetProgramEnvParameterfvARB" );
	// GL_EXT_texture3D
    glTexImage3DEXT                 =(PFNGLTEXIMAGE3DEXTPROC)                 wglGetProcAddress ( "glTexImage3DEXT" );
	// ARB_texture_compression
    glCompressedTexImage3DARB       = (PFNGLCOMPRESSEDTEXIMAGE3DARBPROC)      wglGetProcAddress ( "glCompressedTexImage3DARB"    );
    glCompressedTexImage2DARB       = (PFNGLCOMPRESSEDTEXIMAGE2DARBPROC)      wglGetProcAddress ( "glCompressedTexImage2DARB"    );
    glCompressedTexImage1DARB       = (PFNGLCOMPRESSEDTEXIMAGE1DARBPROC)      wglGetProcAddress ( "glCompressedTexImage1DARB"    );
    glCompressedTexSubImage3DARB    = (PFNGLCOMPRESSEDTEXSUBIMAGE3DARBPROC)   wglGetProcAddress ( "glCompressedTexSubImage3DARB" );
    glCompressedTexSubImage2DARB    = (PFNGLCOMPRESSEDTEXSUBIMAGE2DARBPROC)   wglGetProcAddress ( "glCompressedTexSubImage2DARB" );
    glCompressedTexSubImage1DARB    = (PFNGLCOMPRESSEDTEXSUBIMAGE1DARBPROC)   wglGetProcAddress ( "glCompressedTexSubImage1DARB" );
    glGetCompressedTexImageARB      = (PFNGLGETCOMPRESSEDTEXIMAGEARBPROC)     wglGetProcAddress ( "glGetCompressedTexImageARB"   );
	// ARB_point_parameters
    glPointParameterfARB             = (PFNGLPOINTPARAMETERFARBPROC)          wglGetProcAddress ( "glPointParameterfARB" );
    glPointParameterfvARB            = (PFNGLPOINTPARAMETERFVARBPROC)         wglGetProcAddress ( "glPointParameterfvARB" );
	// ARB_occlusion_query
    glGenQueriesARB        = (PFNGLGENQUERIESARBPROC)        wglGetProcAddress ( "glGenQueriesARB"        );
    glDeleteQueriesARB     = (PFNGLDELETEQUERIESARBPROC)     wglGetProcAddress ( "glDeleteQueriesARB"     );
    glIsQueryARB           = (PFNGLISQUERYARBPROC)           wglGetProcAddress ( "glIsQueryARB"           );
    glBeginQueryARB        = (PFNGLBEGINQUERYARBPROC)        wglGetProcAddress ( "glBeginQueryARB"        );
    glEndQueryARB          = (PFNGLENDQUERYARBPROC)          wglGetProcAddress ( "glEndQueryARB"          );
    glGetQueryivARB        = (PFNGLGETQUERYIVARBPROC)        wglGetProcAddress ( "glGetQueryivARB"        );
    glGetQueryObjectivARB  = (PFNGLGETQUERYOBJECTIVARBPROC)  wglGetProcAddress ( "glGetQueryObjectivARB"  );
    glGetQueryObjectuivARB = (PFNGLGETQUERYOBJECTUIVARBPROC) wglGetProcAddress ( "glGetQueryObjectuivARB" );
	// GLSL-specific extensions  // GL_ARB_shader_object
    glDeleteObjectARB         = (PFNGLDELETEOBJECTARBPROC)         wglGetProcAddress ( "glDeleteObjectARB" );
    glGetHandleARB            = (PFNGLGETHANDLEARBPROC)            wglGetProcAddress ( "glGetHandleARB" );
    glDetachObjectARB         = (PFNGLDETACHOBJECTARBPROC)         wglGetProcAddress ( "glDetachObjectARB" );
    glCreateShaderObjectARB   = (PFNGLCREATESHADEROBJECTARBPROC)   wglGetProcAddress ( "glCreateShaderObjectARB" );
    glShaderSourceARB         = (PFNGLSHADERSOURCEARBPROC)         wglGetProcAddress ( "glShaderSourceARB" );
    glCompileShaderARB        = (PFNGLCOMPILESHADERARBPROC)        wglGetProcAddress ( "glCompileShaderARB" );
    glCreateProgramObjectARB  = (PFNGLCREATEPROGRAMOBJECTARBPROC)  wglGetProcAddress ( "glCreateProgramObjectARB" );
    glAttachObjectARB         = (PFNGLATTACHOBJECTARBPROC)         wglGetProcAddress ( "glAttachObjectARB" );
    glLinkProgramARB          = (PFNGLLINKPROGRAMARBPROC)          wglGetProcAddress ( "glLinkProgramARB" );
    glUseProgramObjectARB     = (PFNGLUSEPROGRAMOBJECTARBPROC)     wglGetProcAddress ( "glUseProgramObjectARB" );
    glValidateProgramARB      = (PFNGLVALIDATEPROGRAMARBPROC)      wglGetProcAddress ( "glValidateProgramARB" );
    glUniform1fARB            = (PFNGLUNIFORM1FARBPROC)            wglGetProcAddress ( "glUniform1fARB" );
    glUniform2fARB            = (PFNGLUNIFORM2FARBPROC)            wglGetProcAddress ( "glUniform2fARB" );
    glUniform3fARB            = (PFNGLUNIFORM3FARBPROC)            wglGetProcAddress ( "glUniform3fARB" );
    glUniform4fARB            = (PFNGLUNIFORM4FARBPROC)            wglGetProcAddress ( "glUniform4fARB" );
    glUniform1iARB            = (PFNGLUNIFORM1IARBPROC)            wglGetProcAddress ( "glUniform1iARB" );
    glUniform2iARB            = (PFNGLUNIFORM2IARBPROC)            wglGetProcAddress ( "glUniform2iARB" );
    glUniform3iARB            = (PFNGLUNIFORM3IARBPROC)            wglGetProcAddress ( "glUniform3iARB" );
    glUniform4iARB            = (PFNGLUNIFORM4IARBPROC)            wglGetProcAddress ( "glUniform4iARB" );
    glUniform1fvARB           = (PFNGLUNIFORM1FVARBPROC)           wglGetProcAddress ( "glUniform1fvARB" );
    glUniform2fvARB           = (PFNGLUNIFORM2FVARBPROC)           wglGetProcAddress ( "glUniform2fvARB" );
    glUniform3fvARB           = (PFNGLUNIFORM3FVARBPROC)           wglGetProcAddress ( "glUniform3fvARB" );
    glUniform4fvARB           = (PFNGLUNIFORM4FVARBPROC)           wglGetProcAddress ( "glUniform4fvARB" );
    glUniform1ivARB           = (PFNGLUNIFORM1IVARBPROC)           wglGetProcAddress ( "glUniform1ivARB" );
    glUniform2ivARB           = (PFNGLUNIFORM2IVARBPROC)           wglGetProcAddress ( "glUniform2ivARB" );
    glUniform3ivARB           = (PFNGLUNIFORM3IVARBPROC)           wglGetProcAddress ( "glUniform3ivARB" );
    glUniform4ivARB           = (PFNGLUNIFORM4IVARBPROC)           wglGetProcAddress ( "glUniform4ivARB" );
    glUniformMatrix2fvARB     = (PFNGLUNIFORMMATRIX2FVARBPROC)     wglGetProcAddress ( "glUniformMatrix2fvARB" );
    glUniformMatrix3fvARB     = (PFNGLUNIFORMMATRIX3FVARBPROC)     wglGetProcAddress ( "glUniformMatrix3fvARB" );
    glUniformMatrix4fvARB     = (PFNGLUNIFORMMATRIX4FVARBPROC)     wglGetProcAddress ( "glUniformMatrix4fvARB" );
    glGetObjectParameterfvARB = (PFNGLGETOBJECTPARAMETERFVARBPROC) wglGetProcAddress ( "glGetObjectParameterfvARB" );
    glGetObjectParameterivARB = (PFNGLGETOBJECTPARAMETERIVARBPROC) wglGetProcAddress ( "glGetObjectParameterivARB" );
    glGetInfoLogARB           = (PFNGLGETINFOLOGARBPROC)           wglGetProcAddress ( "glGetInfoLogARB" );
    glGetAttachedObjectsARB   = (PFNGLGETATTACHEDOBJECTSARBPROC)   wglGetProcAddress ( "glGetAttachedObjectsARB" );
    glGetUniformLocationARB   = (PFNGLGETUNIFORMLOCATIONARBPROC)   wglGetProcAddress ( "glGetUniformLocationARB" );
    glGetActiveUniformARB     = (PFNGLGETACTIVEUNIFORMARBPROC)     wglGetProcAddress ( "glGetActiveUniformARB" );
    glGetUniformfvARB         = (PFNGLGETUNIFORMFVARBPROC)         wglGetProcAddress ( "glGetUniformfvARB" );
    glGetUniformivARB         = (PFNGLGETUNIFORMIVARBPROC)         wglGetProcAddress ( "glGetUniformivARB" );
    glGetShaderSourceARB      = (PFNGLGETSHADERSOURCEARBPROC)      wglGetProcAddress ( "glGetShaderSourceARB" );
	// GL_ARB_vertex_shader
    glBindAttribLocationARB   = (PFNGLBINDATTRIBLOCATIONARBPROC)   wglGetProcAddress ( "glBindAttribLocationARB" );
    glGetActiveAttribARB      = (PFNGLGETACTIVEATTRIBARBPROC)      wglGetProcAddress ( "glGetActiveAttribARB"    );
    glGetAttribLocationARB    = (PFNGLGETATTRIBLOCATIONARBPROC)    wglGetProcAddress ( "glGetAttribLocationARB"  );
    glGetVertexAttribfvARB    = (PFNGLGETVERTEXATTRIBFVARBPROC)    wglGetProcAddress ( "glGetVertexAttribfvARB"  );
	// EXT_stencil_two_side
    glActiveStencilFaceEXT    = (PFNGLACTIVESTENCILFACEEXTPROC)    wglGetProcAddress ( "glActiveStencilFaceEXT" );
	// EXT_depth_bounds_test
	glDepthBoundsEXT      = (PFNGLDEPTHBOUNDSEXTPROC)          wglGetProcAddress ( "glDepthBoundsEXT" );
	// EXT_framebuffer_object
	glIsRenderbufferEXT                      = (PFNGLISRENDERBUFFEREXTPROC                     ) wglGetProcAddress ( "glIsRenderbufferEXT" );
	glBindRenderbufferEXT                    = (PFNGLBINDRENDERBUFFEREXTPROC                   ) wglGetProcAddress ( "glBindRenderbufferEXT" );
	glDeleteRenderbuffersEXT                 = (PFNGLDELETERENDERBUFFERSEXTPROC                ) wglGetProcAddress ( "glDeleteRenderbuffersEXT" );
	glGenRenderbuffersEXT                    = (PFNGLGENRENDERBUFFERSEXTPROC                   ) wglGetProcAddress ( "glGenRenderbuffersEXT" );
	glRenderbufferStorageEXT                 = (PFNGLRENDERBUFFERSTORAGEEXTPROC                ) wglGetProcAddress ( "glRenderbufferStorageEXT" );
	glGetRenderbufferParameterivEXT          = (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC         ) wglGetProcAddress ( "glGetRenderbufferParameterivEXT" );
	glIsFramebufferEXT                       = (PFNGLISFRAMEBUFFEREXTPROC                      ) wglGetProcAddress ( "glIsFramebufferEXT" );
	glBindFramebufferEXT                     = (PFNGLBINDFRAMEBUFFEREXTPROC                    ) wglGetProcAddress ( "glBindFramebufferEXT" );
	glDeleteFramebuffersEXT                  = (PFNGLDELETEFRAMEBUFFERSEXTPROC                 ) wglGetProcAddress ( "glDeleteFramebuffersEXT" );
	glGenFramebuffersEXT                     = (PFNGLGENFRAMEBUFFERSEXTPROC                    ) wglGetProcAddress ( "glGenFramebuffersEXT" );
	glCheckFramebufferStatusEXT              = (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC             ) wglGetProcAddress ( "glCheckFramebufferStatusEXT" );
	glFramebufferTexture1DEXT                = (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC               ) wglGetProcAddress ( "glFramebufferTexture1DEXT" );
	glFramebufferTexture2DEXT                = (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC               ) wglGetProcAddress ( "glFramebufferTexture2DEXT" );
	glFramebufferTexture3DEXT                = (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC               ) wglGetProcAddress ( "glFramebufferTexture3DEXT" );
	glFramebufferRenderbufferEXT             = (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC			   ) wglGetProcAddress ( "glFramebufferRenderbufferEXT" );
	glGetFramebufferAttachmentParameterivEXT = (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) wglGetProcAddress ( "glGetFramebufferAttachmentParameterivEXT" );
	glGenerateMipmapEXT                      = (PFNGLGENERATEMIPMAPEXTPROC					   ) wglGetProcAddress ( "glGenerateMipmapEXT" );

#ifndef	GL_VERSION_1_3										// ARB_transpose matrix
	glLoadTransposeMatrixfARB	              = (PFNGLLOADTRANSPOSEMATRIXFPROC                 ) wglGetProcAddress ( "glLoadTransposeMatrixfARB" );
	glLoadTransposeMatrixdARB	              = (PFNGLLOADTRANSPOSEMATRIXDPROC                 ) wglGetProcAddress ( "glLoadTransposeMatrixdARB" );
	glMultTransposeMatrixfARB	              = (PFNGLMULTTRANSPOSEMATRIXFPROC                 ) wglGetProcAddress ( "glMultTransposeMatrixfARB" );
	glMultTransposeMatrixdARB	              = (PFNGLMULTTRANSPOSEMATRIXDPROC                 ) wglGetProcAddress ( "glMultTransposeMatrixdARB" );
#endif	
	// ARB_color_buffer_float
	glClampColorARB         = (PFNGLCLAMPCOLORARBPROC)      wglGetProcAddress ( "glClampColorARB" );

#ifdef	_WIN32											
	// fresh Linux already has 2.0 stencil ops from OpenGL 2.0
	glStencilFuncSeparate  = (PFNGLSTENCILFUNCSEPARATEPROC) wglGetProcAddress ( "glStencilFuncSeparate" );
	glStencilOpSeparate    = (PFNGLSTENCILOPSEPARATEPROC)   wglGetProcAddress ( "glStencilOpSeparate" );
	glStencilMaskSeparate  = (PFNGLSTENCILMASKSEPARATEPROC) wglGetProcAddress ( "glStencilMaskSeparate" );
	// blend ops from OPenGL 2.0
	glBlendEquation         = (PFNGLBLENDEQUATIONPROC)         wglGetProcAddress ( "glBlendEquation" );
	glBlendEquationSeparate = (PFNGLBLENDEQUATIONSEPARATEPROC) wglGetProcAddress ( "glBlendEquationSeparate" );
	glBlendFuncSeparate     = (PFNGLBLENDFUNCSEPARATEPROC)     wglGetProcAddress ( "glBlendFuncSeparate" );
	glBlendColor            = (PFNGLBLENDCOLORPROC)            wglGetProcAddress ( "glBlendColor" );
#endif
	// draw buffers from OpenGL 2.0
	glDrawBuffers           = (PFNGLDRAWBUFFERSPROC)           wglGetProcAddress ( "glDrawBuffers" );
	// ATI_draw_buffers
	glDrawBuffersATI        = (PFNGLDRAWBUFFERSATIPROC)        wglGetProcAddress ( "glDrawBuffersATI" );
	// EXT_texture_integer
	glTexParameterIivEXT      = (PFNGLTEXPARAMETERIIVEXTPROC)     wglGetProcAddress ( "glTexParameterIivEXT" );
	glTexParameterIuivEXT     = (PFNGLTEXPARAMETERIUIVEXTPROC)    wglGetProcAddress ( "glTexParameterIuivEXT" );
	glGetTexParameterIivEXT   = (PFNGLGETTEXPARAMETERIIVEXTPROC)  wglGetProcAddress ( "glGetTexParameterIivEXT" );
	glGetTexParameterIuivEXT  = (PFNGLGETTEXPARAMETERIUIVEXTPROC) wglGetProcAddress ( "glGetTexParameterIuivEXT" );
	glClearColorIiEXT         = (PFNGLCLEARCOLORIIEXTPROC)        wglGetProcAddress ( "glClearColorIiEXT" );
	glClearColorIuiEXT        = (PFNGLCLEARCOLORIUIEXTPROC)       wglGetProcAddress ( "glClearColorIuiEXT" );
	// EXT_draw_instanced
	glDrawArraysInstancedEXT    = (PFNGLDRAWARRAYSINSTANCEDEXTPROC)    wglGetProcAddress ( "glDrawArraysInstancedEXT" );
	glDrawElementsInstancedEXT  = (PFNGLDRAWELEMENTSINSTANCEDEXTPROC)  wglGetProcAddress ( "glDrawElementsInstancedEXT" );
	// EXT_texture_buffer_object
	glTexBufferEXT  = (PFNGLTEXBUFFEREXTPROC)  wglGetProcAddress ( "glTexBufferEXT" );
	// EXT_gpu_shader4
	glGetUniformuivEXT         = (PFNGLGETUNIFORMUIVEXTPROC)        wglGetProcAddress ( "" );
	glBindFragDataLocationEXT  = (PFNGLBINDFRAGDATALOCATIONEXTPROC) wglGetProcAddress ( "glBindFragDataLocationEXT" );
	glGetFragDataLocationEXT   = (PFNGLGETFRAGDATALOCATIONEXTPROC)  wglGetProcAddress ( "glGetFragDataLocationEXT" );
	glUniform1uiEXT            = (PFNGLUNIFORM1UIEXTPROC)           wglGetProcAddress ( "glUniform1uiEXT" );
	glUniform2uiEXT            = (PFNGLUNIFORM2UIEXTPROC)           wglGetProcAddress ( "glUniform2uiEXT" );
	glUniform3uiEXT            = (PFNGLUNIFORM3UIEXTPROC)           wglGetProcAddress ( "glUniform3uiEXT" );
	glUniform4uiEXT            = (PFNGLUNIFORM4UIEXTPROC)           wglGetProcAddress ( "glUniform4uiEXT" );
	glUniform1uivEXT           = (PFNGLUNIFORM1UIVEXTPROC)          wglGetProcAddress ( "glUniform1uivEXT" );
	glUniform2uivEXT           = (PFNGLUNIFORM2UIVEXTPROC)          wglGetProcAddress ( "glUniform2uivEXT" );
	glUniform3uivEXT           = (PFNGLUNIFORM2UIVEXTPROC)          wglGetProcAddress ( "glUniform3uivEXT" );
	glUniform4uivEXT           = (PFNGLUNIFORM2UIVEXTPROC)          wglGetProcAddress ( "glUniform4uivEXT" );
	glVertexAttribI1iEXT       = (PFNGLVERTEXATTRIBI1IEXTPROC)      wglGetProcAddress ( "glVertexAttribI1iEXT" );
	glVertexAttribI2iEXT       = (PFNGLVERTEXATTRIBI2IEXTPROC)      wglGetProcAddress ( "glVertexAttribI2iEXT" );
	glVertexAttribI3iEXT       = (PFNGLVERTEXATTRIBI3IEXTPROC)      wglGetProcAddress ( "glVertexAttribI3iEXT" );
	glVertexAttribI4iEXT       = (PFNGLVERTEXATTRIBI4IEXTPROC)      wglGetProcAddress ( "glVertexAttribI4iEXT" );
	glVertexAttribI1uiEXT      = (PFNGLVERTEXATTRIBI1UIEXTPROC)     wglGetProcAddress ( "glVertexAttribI1uiEXT" );
	glVertexAttribI2uiEXT      = (PFNGLVERTEXATTRIBI2UIEXTPROC)     wglGetProcAddress ( "glVertexAttribI2uiEXT" );
	glVertexAttribI3uiEXT      = (PFNGLVERTEXATTRIBI3UIEXTPROC)     wglGetProcAddress ( "glVertexAttribI3uiEXT" );
	glVertexAttribI4uiEXT      = (PFNGLVERTEXATTRIBI4UIEXTPROC)     wglGetProcAddress ( "glVertexAttribI4uiEXT" );
	glVertexAttribI1ivEXT      = (PFNGLVERTEXATTRIBI1IVEXTPROC)     wglGetProcAddress ( "glVertexAttribI1ivEXT" );
	glVertexAttribI2ivEXT      = (PFNGLVERTEXATTRIBI2IVEXTPROC)     wglGetProcAddress ( "glVertexAttribI2ivEXT" );
	glVertexAttribI3ivEXT      = (PFNGLVERTEXATTRIBI3IVEXTPROC)     wglGetProcAddress ( "glVertexAttribI3ivEXT" );
	glVertexAttribI4ivEXT      = (PFNGLVERTEXATTRIBI4IVEXTPROC)     wglGetProcAddress ( "glVertexAttribI4ivEXT" );
	glVertexAttribI1uivEXT     = (PFNGLVERTEXATTRIBI1UIVEXTPROC)    wglGetProcAddress ( "glVertexAttribI1uivEXT" );
	glVertexAttribI2uivEXT     = (PFNGLVERTEXATTRIBI2UIVEXTPROC)    wglGetProcAddress ( "glVertexAttribI2uivEXT" );
	glVertexAttribI3uivEXT     = (PFNGLVERTEXATTRIBI3UIVEXTPROC)    wglGetProcAddress ( "glVertexAttribI3uivEXT" );
	glVertexAttribI4uivEXT     = (PFNGLVERTEXATTRIBI4UIVEXTPROC)    wglGetProcAddress ( "glVertexAttribI4uivEXT" );
	glVertexAttribI4bvEXT      = (PFNGLVERTEXATTRIBI4BVEXTPROC)     wglGetProcAddress ( "glVertexAttribI4bvEXT" );
	glVertexAttribI4svEXT      = (PFNGLVERTEXATTRIBI4SVEXTPROC)     wglGetProcAddress ( "glVertexAttribI4svEXT" );
	glVertexAttribI4ubvEXT     = (PFNGLVERTEXATTRIBI4UBVEXTPROC)    wglGetProcAddress ( "glVertexAttribI4ubvEXT" );
	glVertexAttribI4usvEXT     = (PFNGLVERTEXATTRIBI4USVEXTPROC)    wglGetProcAddress ( "glVertexAttribI4usvEXT" );
	glVertexAttribIPointerEXT  = (PFNGLVERTEXATTRIBIPOINTEREXTPROC) wglGetProcAddress ( "glVertexAttribIPointerEXT" );
	glGetVertexAttribIivEXT    = (PFNGLGETVERTEXATTRIBIIVEXTPROC)   wglGetProcAddress ( "glGetVertexAttribIivEXT" );
	glGetVertexAttribIuivEXT   = (PFNGLGETVERTEXATTRIBIUIVEXTPROC)  wglGetProcAddress ( "glGetVertexAttribIuivEXT" );
	// EXT_geometry_shader4
	glProgramParameteriEXT       = (PFNGLPROGRAMPARAMETERIEXTPROC)       wglGetProcAddress ( "glProgramParameteriEXT" );
	glFramebufferTextureEXT      = (PFNGLFRAMEBUFFERTEXTUREEXTPROC)      wglGetProcAddress ( "glFramebufferTextureEXT" );
	glFramebufferTextureLayerEXT = (PFNGLFRAMEBUFFERTEXTURELAYEREXTPROC) wglGetProcAddress ( "glFramebufferTextureLayerEXT" );
	glFramebufferTextureFaceEXT  = (PFNGLFRAMEBUFFERTEXTUREFACEEXTPROC)  wglGetProcAddress ( "glFramebufferTextureFaceEXT" );
	// EXT_bindable_uniform
	glUniformBufferEXT        = (PFNGLUNIFORMBUFFEREXTPROC)        wglGetProcAddress ( "glUniformBufferEXT" );
	glGetUniformBufferSizeEXT = (PFNGLGETUNIFORMBUFFERSIZEEXTPROC) wglGetProcAddress ( "glGetUniformBufferSizeEXT" );
	glGetUniformOffsetEXT     = (PFNGLGETUNIFORMOFFSETEXTPROC)     wglGetProcAddress ( "glGetUniformOffsetEXT" );
	// OpenGL 2.0 shader support
	glCompileShader       = (PFNGLCOMPILESHADERPROC)      wglGetProcAddress ( "glCompileShader" );
	glCreateProgram       = (PFNGLCREATEPROGRAMPROC)      wglGetProcAddress ( "glCreateProgram" );
	glCreateShader        = (PFNGLCREATESHADERPROC)       wglGetProcAddress ( "glCreateShader" );
	glDeleteProgram       = (PFNGLDELETEPROGRAMPROC)      wglGetProcAddress ( "glDeleteProgram" );
	glDeleteShader        = (PFNGLDELETESHADERPROC)       wglGetProcAddress ( "glDeleteShader" );
	glDetachShader        = (PFNGLDETACHSHADERPROC)       wglGetProcAddress ( "glDetachShader" );
	glGetProgramInfoLog   = (PFNGLGETPROGRAMINFOLOGPROC)  wglGetProcAddress ( "glGetProgramInfoLog" );
	glGetShaderInfoLog    = (PFNGLGETSHADERINFOLOGPROC)   wglGetProcAddress ( "glGetShaderInfoLog" );
	glGetShaderSource     = (PFNGLGETSHADERSOURCEPROC)    wglGetProcAddress ( "glGetShaderSource" );
	glLinkProgram         = (PFNGLLINKPROGRAMPROC)        wglGetProcAddress ( "glLinkProgram" );
	glShaderSource        = (PFNGLSHADERSOURCEPROC)       wglGetProcAddress ( "glShaderSource" );
	glUseProgram          = (PFNGLUSEPROGRAMPROC)         wglGetProcAddress ( "glUseProgram" );
	glValidateProgram     = (PFNGLVALIDATEPROGRAMPROC)    wglGetProcAddress ( "glValidateProgram" );
	glGetProgramiv        = (PFNGLGETPROGRAMIVPROC)       wglGetProcAddress ( "glGetProgramiv" );
	glGetShaderiv         = (PFNGLGETSHADERIVPROC)        wglGetProcAddress ( "glGetShaderiv" );
	glAttachShader        = (PFNGLATTACHSHADERPROC)       wglGetProcAddress ( "glAttachShader" );
	glGetUniformLocation  = (PFNGLGETUNIFORMLOCATIONPROC) wglGetProcAddress ( "glGetUniformLocation" );
	glGetAttribLocation   = (PFNGLGETATTRIBLOCATIONPROC)  wglGetProcAddress ( "glGetAttribLocation" );
	glUniform4fv          = (PFNGLUNIFORM4FVPROC)         wglGetProcAddress ( "glUniform4fv" );
	glUniform3fv          = (PFNGLUNIFORM3FVPROC)		  wglGetProcAddress ( "glUniform3fv" );
	glUniform2fv          = (PFNGLUNIFORM2FVPROC)		  wglGetProcAddress ( "glUniform2fv" );
	glUniform1f           = (PFNGLUNIFORM1FPROC)		  wglGetProcAddress ( "glUniform1f" );
	glUniform1i           = (PFNGLUNIFORM1IPROC)		  wglGetProcAddress ( "glUniform1i" );
	glGetUniformfv        = (PFNGLGETUNIFORMFVPROC)		  wglGetProcAddress ( "glGetUniformfv" );
	glVertexAttrib4fv     = (PFNGLVERTEXATTRIB4FVPROC)	  wglGetProcAddress ( "glVertexAttrib4fv" );
	glGetVertexAttribfv   = (PFNGLGETVERTEXATTRIBFVPROC)  wglGetProcAddress ( "glGetVertexAttribfv" );
	glUniformMatrix2fv    = (PFNGLUNIFORMMATRIX2FVPROC)   wglGetProcAddress ( "glUniformMatrix2fv" );
	glUniformMatrix3fv    = (PFNGLUNIFORMMATRIX3FVPROC)   wglGetProcAddress ( "glUniformMatrix3fv" );
	glUniformMatrix4fv    = (PFNGLUNIFORMMATRIX4FVPROC)   wglGetProcAddress ( "glUniformMatrix4fv" );
	// OpenGL 2 query support
    glGenQueries          = (PFNGLGENQUERIESPROC)        wglGetProcAddress ( "glGenQueries"        );
    glDeleteQueries       = (PFNGLDELETEQUERIESPROC)     wglGetProcAddress ( "glDeleteQueries"     );
    glIsQuery             = (PFNGLISQUERYPROC)           wglGetProcAddress ( "glIsQuery"           );
    glBeginQuery          = (PFNGLBEGINQUERYPROC)        wglGetProcAddress ( "glBeginQuery"        );
    glEndQuery            = (PFNGLENDQUERYPROC)          wglGetProcAddress ( "glEndQuery"          );
    glGetQueryiv          = (PFNGLGETQUERYIVPROC)        wglGetProcAddress ( "glGetQueryiv"        );
    glGetQueryObjectiv    = (PFNGLGETQUERYOBJECTIVPROC)  wglGetProcAddress ( "glGetQueryObjectiv"  );
    glGetQueryObjectuiv   = (PFNGLGETQUERYOBJECTUIVPROC) wglGetProcAddress ( "glGetQueryObjectuiv" );
	// NV_transform_feedback
	glBeginTransformFeedbackNV      = (PFNGLBEGINTRANSFORMFEEDBACKNVPROC)      wglGetProcAddress ( "glBeginTransformFeedbackNV" );
	glEndTransformFeedbackNV        = (PFNGLENDTRANSFORMFEEDBACKNVPROC)        wglGetProcAddress ( "glEndTransformFeedbackNV" );
	glTransformFeedbackAttribsNV    = (PFNGLTRANSFORMFEEDBACKATTRIBSNVPROC)    wglGetProcAddress ( "glTransformFeedbackAttribsNV" );
	glBindBufferRangeNV             = (PFNGLBINDBUFFERRANGENVPROC)             wglGetProcAddress ( "glBindBufferRangeNV" );
	glBindBufferOffsetNV            = (PFNGLBINDBUFFEROFFSETNVPROC)            wglGetProcAddress ( "glBindBufferOffsetNV" );
	glBindBufferBaseNV              = (PFNGLBINDBUFFERBASENVPROC)              wglGetProcAddress ( "glBindBufferBaseNV" );
	glTransformFeedbackVaryingsNV   = (PFNGLTRANSFORMFEEDBACKVARYINGSNVPROC)   wglGetProcAddress ( "glTransformFeedbackVaryingsNV" );
	glActiveVaryingNV               = (PFNGLACTIVEVARYINGNVPROC)               wglGetProcAddress ( "glActiveVaryingNV" );
	glGetVaryingLocationNV          = (PFNGLGETVARYINGLOCATIONNVPROC)          wglGetProcAddress ( "glGetVaryingLocationNV" );
	glGetActiveVaryingNV            = (PFNGLGETACTIVEVARYINGNVPROC)            wglGetProcAddress ( "glGetActiveVaryingNV" );
	glGetTransformFeedbackVaryingNV = (PFNGLGETTRANSFORMFEEDBACKVARYINGNVPROC) wglGetProcAddress ( "glGetTransformFeedbackVaryingNV" );
	// NV_fence
	glDeleteFencesNV = (PFNGLDELETEFENCESNVPROC)		wglGetProcAddress ( "glDeleteFencesNV" );
	glGenFencesNV    = (PFNGLGENFENCESNVPROC)			wglGetProcAddress ( "glGenFencesNV"    );
	glIsFenceNV      = (PFNGLISFENCENVPROC)				wglGetProcAddress ( "glIsFenceNV"      );
	glTestFenceNV    = (PFNGLTESTFENCENVPROC)			wglGetProcAddress ( "glTestFenceNV "   );
	glGetFenceivNV   = (PFNGLGETFENCEIVNVPROC)			wglGetProcAddress ( "glGetFenceivNV"   );
	glFinishFenceNV  = (PFNGLFINISHFENCENVPROC)			wglGetProcAddress ( "glFinishFenceNV"  );
	glSetFenceNV     = (PFNGLSETFENCENVPROC)			wglGetProcAddress ( "glSetFenceNV"     );
	// NV__conditional_render
	glBeginConditionalRenderNV = (PFNGLBEGINCONDITIONALRENDERNVPROC) wglGetProcAddress ( "glBeginConditionalRenderNV" );
	glEndConditionalRenderNV   = (PFNGLENDCONDITIONALRENDERNVPROC)   wglGetProcAddress ( "glEndConditionalRenderNV"   );
	// ARB_get_program_binary
	glGetProgramBinary  = (PFNGLGETPROGRAMBINARYPROC)  wglGetProcAddress ( "glGetProgramBinary" );
	glProgramBinary     = (PFNGLPROGRAMBINARYPROC)     wglGetProcAddress ( "glProgramBinary" );
	glProgramParameteri = (PFNGLPROGRAMPARAMETERIPROC) wglGetProcAddress ( "glProgramParameteri" );													
	// ARB_sampler_objects
	glGenSamplers            = (PFNGLGENSAMPLERSPROC)				wglGetProcAddress ( "glGenSamplers" );
	glDeleteSamplers         = (PFNGLDELETESAMPLERSPROC)			wglGetProcAddress ( "glDeleteSamplers" );
	glIsSampler              = (PFNGLISSAMPLERPROC)					wglGetProcAddress ( "glIsSampler" );
	glBindSampler            = (PFNGLBINDSAMPLERPROC)				wglGetProcAddress ( "glBindSampler" );
	glSamplerParameteri      = (PFNGLSAMPLERPARAMETERIPROC)			wglGetProcAddress ( "glSamplerParameteri" );
	glSamplerParameteriv     = (PFNGLSAMPLERPARAMETERIVPROC)		wglGetProcAddress ( "glSamplerParameteriv" );
	glSamplerParameterf      = (PFNGLSAMPLERPARAMETERFPROC)			wglGetProcAddress ( "glSamplerParameterf" );
	glSamplerParameterfv     = (PFNGLSAMPLERPARAMETERFVPROC)		wglGetProcAddress ( "glSamplerParameterfv" );
	glSamplerParameterIiv    = (PFNGLSAMPLERPARAMETERIIVPROC)		wglGetProcAddress ( "glSamplerParameterIiv" );
	glSamplerParameterIuiv   = (PFNGLSAMPLERPARAMETERIUIVPROC)		wglGetProcAddress ( "glSamplerParameterIuiv" );
	glGetSamplerParameteriv  = (PFNGLGETSAMPLERPARAMETERIVPROC)		wglGetProcAddress ( "glGetSamplerParameteriv" );
	glGetSamplerParameterIiv = (PFNGLGETSAMPLERPARAMETERIIVPROC)	wglGetProcAddress ( "glGetSamplerParameterIiv" );
	glGetSamplerParameterfv  = (PFNGLGETSAMPLERPARAMETERFVPROC)		wglGetProcAddress ( "glGetSamplerParameterfv" );
	glGetSamplerParameterIfv = (PFNGLGETSAMPLERPARAMETERIFVPROC)	wglGetProcAddress ( "glGetSamplerParameterIfv" );
	// ARB_vertex_array_object
	glBindVertexArray    = (PFNGLBINDVERTEXARRAYPROC)		wglGetProcAddress ( "glBindVertexArray" );
	glDeleteVertexArrays = (PFNGLDELETEVERTEXARRAYSPROC)	wglGetProcAddress ( "glDeleteVertexArrays" );
	glGenVertexArrays    = (PFNGLGENVERTEXARRAYSPROC)		wglGetProcAddress ( "glGenVertexArrays" );
	glIsVertexArray      = (PFNGLISVERTEXARRAYPROC)			wglGetProcAddress ( "glIsVertexArray" );
	// ARB_instanced_arrays
	//glVertexAttribDivisor = (PFNGLVERTEXATTRIBDIVISORARBPROC)	wglGetProcAddress ( "glVertexAttribDivisor" );
	
#ifdef  _WIN32
    initWin32Extensions ();
#else
    initLinuxExtensions ();
#endif

    extinitialized = true;
}


/*
==========================
jeank: Extention checks
==========================
*/

boolean FBO_Ext_Supported (void)
{
	if (strstr(gl_extensions, "GL_EXT_framebuffer_object "))
		return true;
	else
		return false;
}

boolean PBO_Ext_Supported (void)
{
	//const char * exts;
	//PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = NULL;
	//wglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)	wglGetProcAddress ( "wglGetExtensionsStringARB" );
	//exts = wglGetExtensionsStringARB ( wglGetCurrentDC () );
	if (strstr(wglGetExtensionsStringARB (wglGetCurrentDC()), "WGL_ARB_extensions"))
		return true;
	else
		return false;
}

int Check_ARB_nonpow2_Extension (void)
{
	if (strstr(gl_extensions, "GL_ARB_texture_non_power_of_two "))
	{
		//Con_Printf("Found GL_ARB_texture_non_power_of_two\n");
		return 1;
	}
	Cvar_SetValue("gl_nonpow2textures", 0);
	return 0;
}

void Check3DfxDisplayModeExtension (void)
{
	char *tmp;
	qboolean display_mode_ext = false;

	tmp = ( unsigned char * )glGetString( GL_EXTENSIONS );
	while( *tmp )
	{
		if (strncmp((const char*)tmp, FX_DISPLAY_MODE_EXT_STRING, strlen(FX_DISPLAY_MODE_EXT_STRING)) == 0)
			display_mode_ext = TRUE;
		tmp++;
	}

	fxDisplayModeExtension = NULL;
	if( !display_mode_ext )
		return;
	if ((fxDisplayModeExtension = (FX_DISPLAY_MODE_EXT)
		wglGetProcAddress((LPCSTR) FX_DISPLAY_MODE_EXT_STRING)) == NULL)
	{
		Sys_Error ("GetProcAddress for gl3DfxDisplayModeExt failed");
		return;
	}
}

void CheckSetPaletteExtension (void)
{
	char *tmp;
	qboolean set_palette_ext = false;
	char *search;

	fxSetPaletteExtension = NULL;
	
	search = NULL;
	if (is_3dfx) search = FX_SET_PALETTE_EXT_STRING;
	if (is_PowerVR) search = VR_SET_PALETTE_EXT_STRING;
	if (!search) return;


	tmp = ( unsigned char * )glGetString( GL_EXTENSIONS );
	while( *tmp )
	{
		if (strncmp((const char*)tmp, search, strlen(search)) == 0)
		{
			if (developer.value) Con_Printf("Using palettized textures!\n");
			set_palette_ext = TRUE;
		}
		tmp++;
	}

	if( !set_palette_ext )
		return;
	if ((fxSetPaletteExtension = (FX_SET_PALETTE_EXT)
		wglGetProcAddress((LPCSTR) search)) == NULL)
	{
		Sys_Error ("GetProcAddress for gl3DfxSetPaletteEXT failed");
		return;
	}
}

void CheckTextureExtensions (void)
{
	char		*tmp;
	qboolean	texture_ext;
	HINSTANCE	hInstGL;

	texture_ext = FALSE;
	/* check for texture extension */
	tmp = (unsigned char *)glGetString(GL_EXTENSIONS);
	while (*tmp)
	{
		if (strncmp((const char*)tmp, TEXTURE_EXT_STRING, strlen(TEXTURE_EXT_STRING)) == 0)
			texture_ext = TRUE;
		tmp++;
	}

	if (!texture_ext || COM_CheckParm ("-gl11") )
	{
		hInstGL = LoadLibrary("opengl32.dll");
		
		if (hInstGL == NULL)
			Sys_Error ("Couldn't load opengl32.dll\n");

		bindTexFunc = (void *)GetProcAddress(hInstGL,"glBindTexture");

		if (!bindTexFunc)
			Sys_Error ("No texture objects!");
		return;
	}

/* load library and get procedure adresses for texture extension API */
	if ((bindTexFunc = (BINDTEXFUNCPTR)
		wglGetProcAddress((LPCSTR) "glBindTextureEXT")) == NULL)
	{
		Sys_Error ("GetProcAddress for BindTextureEXT failed");
		return;
	}
}

void CheckArrayExtensions (void)
{
	char		*tmp;

	/* check for texture extension */
	tmp = (unsigned char *)glGetString(GL_EXTENSIONS);
	while (*tmp)
	{
		if (strncmp((const char*)tmp, "GL_EXT_vertex_array", strlen("GL_EXT_vertex_array")) == 0)
		{
			if (
                ((glArrayElementEXT = wglGetProcAddress("glArrayElementEXT")) == NULL) ||
                ((glColorPointerEXT = wglGetProcAddress("glColorPointerEXT")) == NULL) ||
                ((glTexCoordPointerEXT = wglGetProcAddress("glTexCoordPointerEXT")) == NULL) ||
                ((glVertexPointerEXT = wglGetProcAddress("glVertexPointerEXT")) == NULL) )
			{
				Sys_Error ("GetProcAddress for vertex extension failed");
				return;
			}
			return;
		}
		tmp++;
	}

	Sys_Error ("Vertex array extension not present");
}

int CheckMultitextureExtensionsSGIS (void)
{
	if (strstr(gl_extensions, "GL_SGIS_multitexture "))
	{
		if (developer.value) Con_Printf("SGIS Multitexture extensions found.\n");
		MTexCoord2f = (void *) wglGetProcAddress("glMTexCoord2fSGIS");
		SelectTextureMTex = (void *) wglGetProcAddress("glSelectTextureSGIS");
		gl_mtexable = true;
        gl_max_texture_units = 2;
		GL_MTexture0 = TEXTURE0_SGIS;
		GL_MTexture1 = TEXTURE1_SGIS;

		return 1;
	}

	return 0;
}

int CheckMultitextureExtensionsARB (void)
{
	if (strstr(gl_extensions, "GL_ARB_multitexture "))
	{
		
        glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, &gl_max_texture_units);
		if (developer.value) 
		{
			Con_Printf("ARB Multitexture extensions found.\n");
			Con_Printf("Found %i TMU's support.\n", gl_max_texture_units);
		}
		MTexCoord2f = (void *) wglGetProcAddress("glMultiTexCoord2fARB");
		SelectTextureMTex = (void *) wglGetProcAddress("glActiveTextureARB");
		gl_mtexable = true;
		GL_MTexture0 = GL_TEXTURE0_ARB;
		GL_MTexture1 = GL_TEXTURE1_ARB;
		
        if (gl_max_texture_units >= 3)
            GL_MTexture2 = GL_TEXTURE2_ARB;

		return 1;
	}

	return 0;
}


void CheckMultiTextureExtensions (void)
{
	gl_mtexable = false;

	if (COM_CheckParm("-nomtex"))
	{
		if (developer.value) Con_Printf("Multitexture extensions disabled.\n");
	}
	else if (COM_CheckParm ("-sgis"))
	{
		if (!CheckMultitextureExtensionsSGIS ())
		{
			if (!CheckMultitextureExtensionsARB ())
			{
				if (developer.value) Con_Printf("No multitexture extensions available.\n");
			}
		}
	}
	else
	{
		// don't confuse the stupid compiler
		if (!CheckMultitextureExtensionsARB ())
		{
			if (!CheckMultitextureExtensionsSGIS ())
			{
				if (developer.value) Con_Printf("No multitexture extensions available.\n");
			}
		}
	}

	// start up with the correct texture selected!
	if (gl_mtexable == true) 
	{
		glDisable(GL_TEXTURE_2D);
		SelectTextureMTex (GL_MTexture0);
	}
}

void GL_Check_FBO_PBO (void)
{
	if (gl_fbo_pbo.value == 2 && !FBO_Ext_Supported())
		gl_fbo_pbo.value = 1;

	if (gl_fbo_pbo.value == 1 && !PBO_Ext_Supported())
		gl_fbo_pbo.value = 0;
}

void GL_Init_Extentions (void)
{
	GL_Init_All_Extensions();

	gl_vendor = glGetString (GL_VENDOR);
	gl_renderer = glGetString (GL_RENDERER);
	gl_version = glGetString (GL_VERSION);
	gl_extensions = glGetString (GL_EXTENSIONS);

	if (developer.value)
	{
		Con_Printf ("GL_VENDOR: %s\n", gl_vendor);
		Con_Printf ("GL_RENDERER: %s\n", gl_renderer);
		Con_Printf ("GL_VERSION: %s\n", gl_version);
		Con_Printf ("GL_EXTENSIONS: %s\n", gl_extensions);
	}

	if (!Q_strncasecmp ((char *)gl_renderer, "3dfx",4))
	{
		is_3dfx = true;
	}

	if (!Q_strncasecmp ((char *)gl_renderer, "PowerVR PCX1",12) ||
		!Q_strncasecmp ((char *)gl_renderer, "PowerVR PCX2",12))
	{
		is_PowerVR = true;
	}

	GL_Check_FBO_PBO();
	CheckTextureExtensions ();
    CheckMultiTextureExtensions();
    fxDisplayModeExtension = NULL;
	fxSetPaletteExtension = NULL;
	Check3DfxDisplayModeExtension();
	CheckSetPaletteExtension();

}


/*
boolean    isExtensionSupported2 ( const char * ext, const char * extList )
{
    const char * start = extList;
    const char * ptr;

    while ( ( ptr = strstr ( start, ext ) ) != NULL )
    {
                                            // we've found, ensure name is exactly ext
        const char * end = ptr + strlen ( ext );

        if ( isspace ( *end ) || *end == '\0' )
            return true;

        start = end;
    }

    return false;
}

boolean    isExtensionSupported ( const char * ext )
{
	const char * extensions;
    initExtensions ();                      // since we will need it for platform-specific extensions

    extensions = (const char *) glGetString ( GL_EXTENSIONS );

    if ( isExtensionSupported2 ( ext, extensions ) )
	    return true;

#ifdef  _WIN32                              // check Windoze extensions
    if ( wglGetExtensionsStringARB == NULL )
    	return false;

    return isExtensionSupported2 ( ext, wglGetExtensionsStringARB ( wglGetCurrentDC () ) );
#else                                       // check GLX extensions
    Display * display = glXGetCurrentDisplay ();
    int       screen  = DefaultScreen        ( display );

    return isExtensionSupported2 ( ext, glXQueryExtensionsString ( display, screen ) );
#endif
}



const char * getGeneralExtensions ()
{
    initExtensions ();

	return (const char *) glGetString ( GL_EXTENSIONS );
}

const char * getPlatformExtensions ()
{
    initExtensions ();                      // since we will need it for platform-specific extensions

#ifdef  _WIN32                              // check Windoze extensions
    if ( wglGetExtensionsStringARB == NULL )
    	return "";

    return wglGetExtensionsStringARB ( wglGetCurrentDC () );
#else                                       // check GLX extensions
    Display * display = glXGetCurrentDisplay ();
    int       screen  = DefaultScreen        ( display );

    return glXQueryExtensionsString ( display, screen );
#endif
}

void    assertExtensionsSupported ( const char * extList )
{
	char * ptr;
	char * str;
    
	str = strdup ( extList );

    for ( ptr = strtok ( str, " ,;\t" ); ptr != NULL; ptr = strtok ( NULL, " ,;\t" ) )
        if ( !isExtensionSupported ( ptr ) )
        {
            fprintf ( stderr, "Error - extension %s not supported.\n", ptr );

            free ( str );
            exit ( 1   );
        }

    free ( str );
}

//
// hide platform specific in one place
//

static void * wglGetProcAddress ( const char * name )
{
#ifdef  _WIN32
    return (void *)wglGetProcAddress ( name );
#else
    return (void *)glXGetProcAddressARB ( (const GLubyte *)name );
#endif
}


void    printfInfo ()               // print info about card, driver, version & etc
{
    const char * vendor    = (const char *)glGetString ( GL_VENDOR   );
    const char * renderer  = (const char *)glGetString ( GL_RENDERER );
    const char * version   = (const char *)glGetString ( GL_VERSION  );

    printf ( "Graphics card and driver information:\n" );
    printf ( "Vendor:   %s\nRenderer: %s\nVersion:  %s\n", vendor, renderer, version );

    if ( isExtensionSupported ( "GL_ARB_multitexture" ) )
    {
        int maxTextureUnits;

        glGetIntegerv ( GL_MAX_TEXTURE_UNITS_ARB,    &maxTextureUnits );

        printf ( "ARB_multitexture supported.\nMax texture units %d.\n", maxTextureUnits );


    }
    if ( isExtensionSupported ( "GL_NV_register_combiners" ) )
    {
        int maxCombiners;

        glGetIntegerv ( GL_MAX_GENERAL_COMBINERS_NV, &maxCombiners    );

        printf ( "NV_register_combiners supported.\nMax general combiners %d.\n", maxCombiners );
    }

    if ( isExtensionSupported ( "GL_ARB_vertex_buffer_object" ) )
        printf ( "VBO supported.\n" );

    if ( isExtensionSupported ( "GL_NV_occlusion_query" ) )
        printf ( "NV_occlusion_query extension supported.\n" );

    if ( isExtensionSupported ( "GL_SGIS_generate_mipmap" ) )
        printf ( "GL_SGIS_generate_mipmap extension supported.\n" );

    if ( isExtensionSupported ( "GL_ARB_vertex_program" ) )
        printf ( "GL_ARB_vertex_program extension supported.\n" );
}
*/
