Help with Run Time Error

Started by
0 comments, last by Morpheus011 17 years, 7 months ago
Hey All: I am new to open GL I have my program up and running but I am having issues running it. I am running the tutorial 6, at this point it is not working. Does anyone have any ideas? Shut Down Error: Could not unregister class. What does this mean? Please help!

#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glu32.lib")
#pragma comment(lib, "glut32.lib")
#pragma comment(lib, "glaux.lib")
//#pragma comment(lib, "LIBCMT.lib")

#include "windows.h"
#include "stdio.h"
#include "GL/gl.h"
#include "GL/glu.h"
#include "GL/glaux.h"
//#include "AFX.h"
#include "stdafx.h"
#include "SCI.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif
//#define CDS_FULLSCREEN4

HDC hDC = NULL;
HGLRC hRC = NULL;
HWND hWnd = NULL;
HINSTANCE hInstance;

bool keys[256];
bool active = TRUE;
bool fullscreen = TRUE;

// varibale to store address of character
unsigned char ua;

//X Rotation
GLfloat xrot;
//Y Rotation
GLfloat yrot;
//Z Rotation
GLfloat zrot;
//X Rotation Speed
GLfloat xspeed;
//Y Rotation Speed
GLfloat yspeed;
// Depth into the screen
GLfloat z = -5.0f;

//Which filter to use
GLuint filter;
//Storage for 3 textures
GLuint texture[3];

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

AUX_RGBImageRec *LoadBMP(char *Filename)
{
	//File handle
	FILE *File = NULL;
	//Check filename was given
	if(!Filename)
	{
		return NULL;
	}
	
	// Check to see if the file exists
	File = fopen(Filename, "r");

	//Does the file exist?
	if(File)
	{
		// close the handle
		fclose(File);
		//Load the bitmap and return the pointer
		return auxDIBImageLoad(Filename);
	}
	//if load failed to return null
	return NULL;
}

int LoadGLTextures()
{
	//Status indicator
	int Status = FALSE;
	// Create storage space for the texture
	AUX_RGBImageRec	*TextureImage[1];
	//Set the pointer to null
	memset(TextureImage, 0, sizeof(void*)*1);
	//Load the bitmap, check for errors, If bitmap's not found quit
	if(TextureImage[0]=LoadBMP("Data/crate.bmp"))
	{
		Status = TRUE;
		//Create 3 textures
		glGenTextures(3, &texture[0]);

		//Create nearest filtered texture
		glBindTexture(GL_TEXTURE_2D, texture[0]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		//Create Linear Filtered Texture
		glBindTexture(GL_TEXTURE_2D, texture[1]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
		glTexImage2D(GL_TEXTURE_2D, 0, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, 0, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

		// Create MipMapped Texture
		glBindTexture(GL_TEXTURE_2D, texture[2]);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
		glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_NEAREST);

		gluBuild2DMipmaps(GL_TEXTURE_2D, 3, TextureImage[0]->sizeX, TextureImage[0]->sizeY, GL_RGB, GL_UNSIGNED_BYTE, TextureImage[0]->data);

	}
	if(TextureImage[0])
	{
		//If texture image exists
		if(TextureImage[0]->data)
		{
			//Free the texture image memory
			free(TextureImage[0]->data);
		}
		//Free the image structure	
		free(TextureImage[0]);
	}
	return Status;
}

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	// Prevents a divide by 0
	if(height == 0)
	{
		height = 1;
	}
	// Reset the current viewport
	glViewport(0,0,width,height);
	//Select the Modelview matrix
	glMatrixMode(GL_PROJECTION);
	//Reset the Projection Matrix
	glLoadIdentity();

	//calculate the aspect ratio of the window
	gluPerspective(45.0f,(GLfloat)width/(GLfloat)height,0.1f,100.0f);
	//Select the Modelview Matrix
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int InitGL(GLvoid)
{
	//Jump to texture loading routine
	if(!LoadGLTextures())
	{
		return FALSE;
	}
	
	//Enable Texture Mappning
	glEnable(GL_TEXTURE_2D);
	// Enable smooth shading
	glShadeModel(GL_SMOOTH);
	// Black Background (red, green, blue, alpha)
	// Range 0.0f(darkest)-1.0f(brightest)
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	// Depth buffer setup
	glClearDepth(1.0f);
	// Enables depth testing
	glEnable(GL_DEPTH_TEST);
	// The Type of Depth Test To Do
	glDepthFunc(GL_LEQUAL);
	// Perspective calculations for the view to look better
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	//Set up the ambient light
	//glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
	//Set up diffuse light
	//glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
	// Position the light
	//glLightfv(GL_LIGHT1, GL_POSITION, LightPosition);
	//Enable Light One
	//glEnable(GL_LIGHT1);
	//Initialization went correctly
	return TRUE;
}

int DrawGLScene(GLvoid)
{

	// Clear screen and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	// Reset the current modelview matrix
	glLoadIdentity();
	//translates into/out of the screen by z-axis
	glTranslatef(0.0f, 0.0f, z);
	//rotate on the x-axis by xrot
	glRotatef(xrot, 0.5f, 0.0f, 0.0f);
	//rotate on the y-axis by yrot
	glRotatef(yrot, 0.0f, 0.5f, 0.0f);
	//rotate on the z-axis by yrot
	glRotatef(zrot, 0.0f, 0.0f, 0.5f);
	//Select a texture based on filter
	glBindTexture(GL_TEXTURE_2D, texture[filter]);
	//Start Drawing Quads
	glBegin(GL_QUADS);
	// Front Face
		glNormal3f( 0.0f, 0.0f, 1.0f);					// Normal Pointing Towards Viewer
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Point 1 (Front)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Point 2 (Front)
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Point 3 (Front)
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Point 4 (Front)
		// Back Face
		glNormal3f( 0.0f, 0.0f,-1.0f);					// Normal Pointing Away From Viewer
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Point 1 (Back)
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Point 2 (Back)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Point 3 (Back)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Point 4 (Back)
		// Top Face
		glNormal3f( 0.0f, 1.0f, 0.0f);					// Normal Pointing Up
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Point 1 (Top)
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Point 2 (Top)
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Point 3 (Top)
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Point 4 (Top)
		// Bottom Face
		glNormal3f( 0.0f,-1.0f, 0.0f);					// Normal Pointing Down
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Point 1 (Bottom)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Point 2 (Bottom)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Point 3 (Bottom)
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Point 4 (Bottom)
		// Right face
		glNormal3f( 1.0f, 0.0f, 0.0f);					// Normal Pointing Right
		glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f, -1.0f);	// Point 1 (Right)
		glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f, -1.0f);	// Point 2 (Right)
		glTexCoord2f(0.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);	// Point 3 (Right)
		glTexCoord2f(0.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);	// Point 4 (Right)
		// Left Face
		glNormal3f(-1.0f, 0.0f, 0.0f);					// Normal Pointing Left
		glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f, -1.0f);	// Point 1 (Left)
		glTexCoord2f(1.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);	// Point 2 (Left)
		glTexCoord2f(1.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);	// Point 3 (Left)
		glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f, -1.0f);	// Point 4 (Left)
	glEnd();								// Done Drawing Quads
	xrot+=xspeed;								// Add xspeed To xrot
	yrot+=yspeed;								// Add yspeed To yrot
	return TRUE;								// Keep Going
}

// Function to properly kill the window
GLvoid KillGLWindow(GLvoid)
{
	// In full screen mode?
	if(fullscreen)
	{
		// If so switch back to the desktop
		ChangeDisplaySettings(NULL, 0);
		// Show mouse pointer
		ShowCursor(TRUE);
	}
	// Check for rendering context
	if(hRC)
	{
		// Check to see if able to release RC and DC context
		if(!wglMakeCurrent(NULL,NULL))
		{
			MessageBox(NULL, "Release of DC and RC Failed", "SHUTDOWN ERROR", MB_OK|MB_ICONINFORMATION);
		}
		// Check to see if able to delete RC
		if(!wglDeleteContext(hRC))
		{
			// Error message if not able to.
			MessageBox(NULL, "Release Rendering Context Failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		}
		// Set the RC to Null
		hRC = NULL;
	}
	//Check to see if able to release the DC
	if(hDC && !ReleaseDC(hWnd, hDC))
	{
		// Error message if unable to release the DC
		MessageBox(NULL, "Release device context failed.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		// Set DC to null.
		hDC = NULL;
	}
	//Check to see if able to destroy the window
	if(hWnd && !DestroyWindow(hWnd))
	{
		MessageBox(NULL, "Could not release hWnd.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		// Set hWnd to null.
		hWnd = NULL;
	}
	// Check to see if unable to register class
	if(!UnregisterClass("OpenGL", hInstance))
	{
		MessageBox(NULL, "Could not unregister class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		hInstance = NULL;
	}
}

BOOL CreateGLWindow(char* title, int width, int height, int bits, bool fullscreenflag)
{
	// Contains the result after searching for a match
	GLuint		PixelFormat;
	// Windows class structure
	WNDCLASS	wc;
	// Window Extended Style
	DWORD		dwExStyle;
	// Window Style
	DWORD		dwStyle;
	// Grabs Rectangle Upper Left/ Lower Right
	RECT		WindowRect;

	/*****Values*****/
	// Set left value to 0
	WindowRect.left = (long)0;
	// Set right value to requested width
	WindowRect.right = (long) width;
	// Set top value to 0.
	WindowRect.top = (long)0;
	// Set bottom value to requested height
	WindowRect.bottom = (long) height;

	//Set the global fullscreen flag
	fullscreen = fullscreenflag;

	// Grab an instance for the window
	hInstance = GetModuleHandle(NULL);
	//Redraw On Size, And Own DC for Window
	wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	// WndProc Handling messages
	wc.lpfnWndProc = (WNDPROC) WndProc;
	// No extra window data
	wc.cbClsExtra = 0;
	// No extra window data
	wc.cbWndExtra = 0;
	// Set the instance
	wc.hInstance = hInstance;
	// Load the default icon
	wc.hIcon = LoadIcon(NULL, IDI_WINLOGO);
	// Load the Arrow Pointer
	wc.hCursor = LoadCursor(NULL, IDC_ARROW);
	// No background required.
	wc.hbrBackground = NULL;
	// No Menu
	wc.lpszMenuName = NULL;
	// Set the class name
	wc.lpszClassName = "OpenGL";
	
	// Check to see if class is registered
	if(!RegisterClass(&wc))
	{
		MessageBox(NULL, "Failed to register the window class.", "SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION);
		return FALSE;
	}
	//Try fullscreen mode
	if(fullscreen)
	{
		// Device Mode
		DEVMODE dmScreenSettings;
		// Clear Memory
		memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
		// Size of DEVMODE structure
		dmScreenSettings.dmSize = sizeof(dmScreenSettings);
		// Selected screen width
		dmScreenSettings.dmPelsWidth = width;
		// Selected screen height
		dmScreenSettings.dmPanningHeight = height;
		//Seleted bits per pixel
		dmScreenSettings.dmBitsPerPel = bits;
		dmScreenSettings.dmFields = DM_BITSPERPEL| DM_PELSWIDTH | DM_PELSHEIGHT;
		//Select Mode
		if(ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
		{
			if(MessageBox(NULL, "The Requested Fullscreen Mode is Not Supported By \n Your Video Card.  Use Windowed Mode Instead?", "FSL GL", MB_YESNO|MB_ICONEXCLAMATION) ==
				IDYES)
			{
				// Windowed mode selected
				fullscreen = FALSE;
			}
			else
			{	
				//Program closing message
				MessageBox(NULL, "Program Closing", "ERROR", MB_OK|MB_ICONSTOP);
				return FALSE;
			}
		}
	}
	// Check to see if in Full Screen Mode
	if(fullscreen)
	{
		//Window extended Style
		dwExStyle = WS_EX_APPWINDOW;
		//Windows style
		dwStyle = WS_POPUP;
		// Hide Mouse pointer
		ShowCursor(FALSE);
	}
	else
	{
		dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
		dwStyle = WS_OVERLAPPEDWINDOW;
	}

	//Adjust window to requested size
	AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

	//Create Window
	if(!(hWnd = CreateWindowEx(	dwExStyle,							// Extended Style For The Window
								"OpenGL",							// Class Name
								title,
								dwStyle|							// Selected Window Style								// Window Title
								WS_CLIPSIBLINGS |					// Required Window Style
								WS_CLIPCHILDREN,					// Required Window Style								
								0, 0,								// Window Position
								WindowRect.right-WindowRect.left,	// Calculate Adjusted Window Width
								WindowRect.bottom-WindowRect.top,	// Calculate Adjusted Window Height
								NULL,								// No Parent Window
								NULL,								// No Menu
								hInstance,							// Instance
								NULL)))								// Don't Pass Anything To WM_CREATE
	{
		KillGLWindow();
		MessageBox(NULL, "Window Creation Error", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	static PIXELFORMATDESCRIPTOR pfd = 
	{
			sizeof(PIXELFORMATDESCRIPTOR),					// Size Of This Pixel Format Descriptor
			1,												// Version Number
			PFD_DRAW_TO_WINDOW |							// Format Must Support Window
			PFD_SUPPORT_OPENGL |							// Format Must Support OpenGL
			PFD_DOUBLEBUFFER,								// Must Support Double Buffering
			PFD_TYPE_RGBA,									// Request An RGBA Format
			bits,											// Select Our Color Depth
			0, 0, 0, 0, 0, 0,								// Color Bits Ignored
			0,												// No Alpha Buffer
			0,												// Shift Bit Ignored
			0,												// No Accumulation Buffer
			0, 0, 0, 0,										// Accumulation Bits Ignored
			16,												// 16Bit Z-Buffer (Depth Buffer)
			0,												// No Stencil Buffer
			0,												// No Auxiliary Buffer
			PFD_MAIN_PLANE,									// Main Drawing Layer
			0,												// Reserved
			0, 0, 0											// Layer Masks Ignored
	};

	//Check to see if we recieved device context
	if(!(hDC=GetDC(hWnd)))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't create a GL device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}
	
	//Check for matching pixel format
	if(!(PixelFormat=ChoosePixelFormat(hDC, &pfd)))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't Find a suitable pixel format.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}
	
	//Check to see if able to set pixel format
	if(!SetPixelFormat(hDC, PixelFormat, &pfd))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't set the pixel format.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	// Check for Rendering Context
	if(!(hRC = wglCreateContext(hDC)))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't create a GL device Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	// Check to see if able to get Rendering Context
	if(!(hRC = wglCreateContext(hDC)))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't create a GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	// Try to activate the rendering context
	if(!wglMakeCurrent(hDC, hRC))
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Can't create a GL Rendering Context.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}

	//Show the window.
	ShowWindow(hWnd, SW_SHOW);
	//Giving it higher priority (foreground window)
	SetForegroundWindow(hWnd);
	//Set the keyboard focus to this window
	SetFocus(hWnd);
	//Set up our perspective GL screen
	ReSizeGLScene(width, height);

	//Initialize our newly created GL
	if(!InitGL())
	{
		// Reset the display
		KillGLWindow();
		MessageBox(NULL, "Initialization Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return FALSE;
	}
	return TRUE;
}

	
LRESULT CALLBACK WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
	// Check for windows message
	switch (uMsg)
	{
	// Watch for windows activate message
	case WM_ACTIVATE:
		{
			//Check minimazation state
			if(!HIWORD(wParam))
			{
				// Program is active
				active=TRUE;
			}
			else
			{
				//Program is no longer active
				active=FALSE;
			}
			return 0;
		}
	// Intercept system command
	case WM_SYSCOMMAND:
		{
			// check system calls
			switch(wParam)
			{
				// Check to see if screen saver trying to start
			case SC_SCREENSAVE:
				// Check to see if the monitor is trying to enter power save
			case SC_MONITORPOWER:
				// Prevent from happening
				return 0;
			}
			break;
		}

	// Did we recieve a close message
	case WM_CLOSE:
		{
			// Send a quit message
			PostQuitMessage(0);
			// Jump Back
			return 0;
		}

	// Check to see if a key is being held down
	case WM_KEYDOWN:
		{
			keys[wParam]=TRUE;
			return 0;
		}

	// Check to see if a key has been released
	case WM_KEYUP:
		{
			keys[wParam]=FALSE;
			return 0;
		}

	// Resize the OpenGL window
	case WM_SIZE:
		{
			// LoWord = Width, HiWord = Height
			ReSizeGLScene(LOWORD(lParam), HIWORD(lParam));
			return 0;
		}
	}
	return DefWindowProc(hWnd, uMsg, wParam, lParam);
}
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	MSG		msg;
	BOOL	done=FALSE;

	// Ask the User which screen mode they prefer?
	if(MessageBox(NULL, "Would you like to run in Fullscreen Mode?", "Start Fullscreen", MB_YESNO|MB_ICONQUESTION) == IDNO)
	{
		//Windowed mode
		fullscreen = FALSE;
	}

	//Open up communication port.
	bool bOK=SCIopen();
	if (!bOK)
	{
		// If COM 4 does not open then Kill window and display error message.
		KillGLWindow();
		MessageBox(NULL, "COM 4 Failed.", "ERROR", MB_OK | MB_ICONEXCLAMATION);
		return 0;
	}
	
	//Handshake with hardware
	SCIwrite("R", 1);
	ua = ' ';
	SCIread(ua,1);
	if(ua != 'N')
	{
		KillGLWindow();
		MessageBox(NULL, "Handshake failed!", "ERROR", MB_OK | MB_ICONEXCLAMATION);
	}

	//Get Calibration Values


	//Create our OpenGLWindow
	if(!CreateGLWindow("FSL OpenGL Framework", 640, 480, 16, fullscreen))
	{
		// Quit if the window has not been created
		return 0;
	}

	// Loop that runs while done=False
	while(!done)
	{
		// Check to see if message is waiting
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			//Check to see if quit message has been received
			if(msg.message==WM_QUIT)
			{
				done=TRUE;
			}
			// Deal with window message
			else
			{
				// Translate the message
				TranslateMessage(&msg);
				// Dispatch the message
				DispatchMessage(&msg);
			}
		}
		else
		{
			//Draw the Scene. Watch for ESC key and Quit Messages from DrawGLScene
			if(active)
			{
				// Was ESC Pressed
				if(keys[VK_ESCAPE])
				{
					// ESC signaled a quit
					done = TRUE;
				}
				// Not time to quit update the screen
				else
				{
					
					//Draw the scene
					DrawGLScene();
					// Swap buffers (double buffering)
					SwapBuffers(hDC);
					/*if (keys['L'] && !lp)				// L Key Being Pressed Not Held?
					{
						// lp becomes TRUE
						lp=TRUE;
						// toggle light TRUE/FALSE
						light=!light;
						// If not light
						if(!light)
						{
							//disable lighting
							glDisable(GL_LIGHTING);
						}
						else
						{
							//Enable Lighting
							glEnable(GL_LIGHTING);
						}
					}
					if (keys['F'] && !fp)				// Is F Key Being Pressed?
					{
						fp=TRUE;				// fp Becomes TRUE
						filter+=1;				// filter Value Increases By One
						if (filter>2)				// Is Value Greater Than 2?
						{
							filter=0;			// If So, Set filter To 0
						}
					}
					if (!keys['F'])					// Has F Key Been Released?
					{
						fp=FALSE;				// If So, fp Becomes FALSE
					}*/

					if (keys['Z'])				// Is Page Up Being Pressed?
					{
						z-=0.02f;				// If So, Move Into The Screen
					}
					/*if (keys[VK_NEXT])				// Is Page Down Being Pressed?
					{
						z+=0.02f;				// If So, Move Towards The Viewer
					}*/
					if (keys['X'])				// Is Up Arrow Being Pressed?
					{
						xrot += 0.1f;				// If So, Decrease xspeed?
					}
					/*if (keys[VK_DOWN])				// Is Down Arrow Being Pressed?
					{
						xrot -= 0.1f;
					}*/
					if (keys['Y'])				// Is Right Arrow Being Pressed?
					{
						yrot +=0.1f;				// If So, Increase yspeed
					}
					/*if (keys[VK_LEFT])				// Is Left Arrow Being Pressed?
					{
						yrot -= 0.1f;
					}*/
				}
			}
			// Is F1 being pressed?
			if (keys[VK_F1])
			{
				//if so make key FALSE
				keys[VK_F1]=FALSE;
				// Kill our current window
				KillGLWindow();
				// Toggle Full Screen/ Windowed Mode
				fullscreen = !fullscreen;
				//Recreate OpenGL Window
				if(!CreateGLWindow("FSL OpenGL Framework", 640,480,16,fullscreen))
				{
					return 0;
				}
			}
		}
	}
	// Shutdown
	// Kill The window
	KillGLWindow();
	//Exit the program
	return(1);//msg.wParam);


 	
	return 0;
}

Advertisement
please only post relavent code next time, if people have to wade through all the extra fluff you are much less likely to get good help ;)

The error you're getting is because the function UnregisterClass() is failing (i.e. returning false). The MSDN is your friend. The MSDN is my friend too, and it tells me that the UnregisterClass function unregisters a window class, freeing the memory required for the class.

The first parameter is the lpClassName and is the name of the window class. If this string was not used to register the class initially with the RegisterClass() function then the UnregisterClass() function will fail. It looks like you're using the same name in both places so I'm assuming somehow the hInstance is getting corrupted. Debug the code and see what the value of your hInstance is when you make the call to UnregisterClass()

EDIT: digging deeper into the MSDN I found that the function returns 0 if the class could not be found or if a window still exists that was created with the class. You can get more helpful info by calling GetLastError()

This topic is closed to new replies.

Advertisement