
#define GLH_EXT_SINGLE_FILE
// #include <glh/glh_extensions.h>
#include "glh_extensions.h"

extern "C" GLenum glewInit ();
// extern GLenum glewInit ();

void ViInitOpengl ()
{
	// extern void InitializeGlExtensions ();
	// InitializeGlExtensions ();

	/*
	 *	Multisampling
	 *
	extern GLenum glewInit ();
	
	// _glewInit_GL_ARB_multisample
	// GLEW_ARB_multisample = glewGetExtension((const GLubyte*)"GL_ARB_multisample");
	// GLboolean wglewGetExtension (const GLubyte *name)
	 */
	/*
	extern "C" { 
		GLenum glewInit ();
	}
	*/
	glewInit ();
    if (!glh_init_extensions(
                             "GL_ARB_multitexture "                            
                             "GL_ARB_multisample "
                             )) 
    {
        fprintf(stderr, "Warning - extensions were not supported: %s", glh_get_unsupported_extensions());
    }
}


#ifdef LATERS
void ViInitOpengl (HWND hWnd, int iWidth, int iHeight, int iPixelFormat)
{
    ViAssert(m_iWidth > 0 && m_iHeight > 0);
    m_iSaveWidth = m_iWidth;
    m_iSaveHeight = m_iHeight;

    m_hWnd		= hWnd;
    m_hWindowDC = ::GetDC(m_hWnd);

    // select format for drawing surface
    PIXELFORMATDESCRIPTOR kPFD;
    memset(&kPFD,0,sizeof(PIXELFORMATDESCRIPTOR));
    kPFD.nSize = sizeof(PIXELFORMATDESCRIPTOR);
    kPFD.nVersion = 1;
    kPFD.dwFlags =
        PFD_DRAW_TO_WINDOW |
        PFD_SUPPORT_OPENGL |
        PFD_GENERIC_ACCELERATED;
    if (m_kBufferParams.Buffering == BufferParams::BP_BUFFERED_DOUBLE)
    {
        kPFD.dwFlags |= PFD_DOUBLEBUFFER;
    }

    // m_kBufferParams.Format is ignored, always create 32-bit RGBA buffer
    kPFD.iPixelType = PFD_TYPE_RGBA;
    kPFD.cColorBits = 32;

    switch (m_kBufferParams.Depth)
    {
    case BufferParams::BP_DEPTH_NONE:  kPFD.cDepthBits =  0;  break;
    case BufferParams::BP_DEPTH_16:    kPFD.cDepthBits = 16;  break;
    case BufferParams::BP_DEPTH_24:    kPFD.cDepthBits = 24;  break;
    case BufferParams::BP_DEPTH_32:    kPFD.cDepthBits = 32;  break;
    default:                           kPFD.cDepthBits = 16;  break;
    }

    if (m_kBufferParams.Stencil == BufferParams::BP_STENCIL_8)
    {
        kPFD.cStencilBits = 8;
    }
    else
    {
        kPFD.cStencilBits = 0;
    }

    // set the pixel format for the rendering context
    bool bFirstTime = (iPixelFormat == 0 ? true : false);
    if (bFirstTime)
    {
        // First time creation.  If multisampling is requested, a second
        // creation will occur and the input pixel format will be supplied
        // directly to SetPixelFormat.
        iPixelFormat = ChoosePixelFormat(m_hWindowDC,&kPFD);
        if (iPixelFormat == 0)
        {
            return;
        }
    }

    BOOL bSuccess = SetPixelFormat(m_hWindowDC,iPixelFormat,&kPFD);
    if (!bSuccess)
    {
        return;
    }

    // create an OpenGL context
    m_hWindowRC = wglCreateContext(m_hWindowDC);
    if (!m_hWindowRC)
    {
        return;
    }

    bSuccess = wglMakeCurrent(m_hWindowDC,m_hWindowRC);
    if (!bSuccess)
    {
        return;
    }

    if (bFirstTime)
    {
        // Load the function pointers for the OpenGL extensions.  This only
        // needs to occur once.
        InitializeOpenGL();
        InitializeWgl();
    }

    // disable the wait for vertical sync
    if (wglSwapIntervalEXT)
    {
        wglSwapIntervalEXT(0);
    }

    // use the system font as default
    DisplayListInfo kInfo;
    int iFirstChar = int(' ');
    kInfo.Quantity = 127 - iFirstChar;
    kInfo.Start = glGenLists(kInfo.Quantity);
    kInfo.Base = kInfo.Start - iFirstChar;
    m_kDLInfo.Append(kInfo);
    m_hOldFont = SelectObject(m_hWindowDC,GetStockObject(SYSTEM_FONT)); 
    wglUseFontBitmaps(m_hWindowDC,iFirstChar,kInfo.Quantity,kInfo.Start);

    InitializeState();
}
#endif