#include <string.h>
#include "stdafx.h"
#include "wglext.h"

char* gGLExtensions = 0;
char* gWGLExtensions = 0;

// Must be called after initializing OpenGL
bool
InitializeExtensions()
{
	bool theResult = true;

	// Normal extensions
	int theLength = strlen((char *) glGetString(GL_EXTENSIONS)) + 2; //extra blank + 0
	gGLExtensions = new char[theLength];
	strcpy(gGLExtensions, (char *) glGetString(GL_EXTENSIONS) );
	gGLExtensions[theLength - 2] = ' ';
	gGLExtensions[theLength - 1] = 0;	

	/*
	if (strstr("GL_EXT_texture_env ", gGLExtensions) )
	{
		
	}
	else theResult = false;
	*/

	// WGL Extensions
	PFNWGLGETEXTENSIONSSTRINGARBPROC pwglGetExtensionsStringARB = 0;
    pwglGetExtensionsStringARB = (PFNWGLGETEXTENSIONSSTRINGARBPROC)wglGetProcAddress("wglGetExtensionsStringARB");
	if (! pwglGetExtensionsStringARB) // try again with other enum
	wglGetExtensionsStringEXT
	if (pwglGetExtensionsStringARB)
	{
		theLength = strlen((char *) pwglGetExtensionsStringARB(wglGetCurrentDC())) + 2; //extra blank + 0
		gWGLExtensions = new char[theLength];
		strcpy(gWGLExtensions, (char *) pwglGetExtensionsStringARB(wglGetCurrentDC()) );
		gWGLExtensions[theLength - 2] = ' ';
		gWGLExtensions[theLength - 1] = 0;
	}

	// Load required WGL Extensions

	
	return theResult;
}


void
FinalizeExtensions()
{
	delete gGLExtensions;
	gGLExtensions = 0;
	delete gWGLExtensions;
	gWGLExtensions = 0;
}