OpenGL Debugging

Started by
6 comments, last by orcblood 20 years, 9 months ago
Hello, Im back . I''ve gone through my OpenGL program - or atleast I''ve gone thorough the first example of NeHe''s tutorials. I had 36 errors originally but I cut them down to 13. I don''t know how to fix these errors - I''ve had them before some I con''t seem to figure out whats wrong. So if someone could help me out by telling me what to fix and where then I would be greatful. I have posted the source code and errors below. Thanks alot, orcblood Errors: C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(136) : error C2065: ''GLunit'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(136) : error C2146: syntax error : missing '';'' before identifier ''PixelFormat'' C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(136) : error C2065: ''PixelFormat'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(149) : error C2039: ''Style'' : is not a member of ''tagWNDCLASS'' c:\program files\microsoft visual studio\vc98\include\winuser.h(1184) : see declaration of ''tagWNDCLASS'' C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(149) : error C2065: ''CS_HREDAW'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(149) : error C2065: ''CS_VREDAW'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(209) : error C2065: ''CreateWindowEX'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(214) : error C2065: ''WS_CHIPSIBLINGS'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(215) : error C2065: ''WS_CHIPCHILDREN'' : undeclared identifier C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(223) : error C2440: ''='' : cannot convert from ''int'' to ''struct HWND__ *'' Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(431) : error C2143: syntax error : missing '';'' before ''}'' C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(431) : error C2143: syntax error : missing '';'' before ''}'' C:\Windows\Desktop\OrcishProductions\OrcishRendering\WinMain.cpp(431) : error C2143: syntax error : missing '';'' before ''}'' Error executing cl.exe.

/*
Source code for the main window of OrcishRendering

Below is the OpenGL code for:
Initializing the window and setting up OpenGL,
Opening and writing a .ms3d file into the assigned views,
Rendering the .ms3d model in the Rendering Window.
*/

//
// Include Files
//

#include <windows.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>

//
// The resource files

#include "resource.h"

//
// Handles and contexts
//

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

//
// Flags and Arrays
//

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

//
// Declair WinProc
//

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

//
// Resize the window and the OpenGL view

GLvoid ReSizeGLScene(GLsizei width, GLsizei height)
{
	if (height == 0)
	{
		height = 1;
	}
	
	glViewport(0, 0, width, height);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	// calculate the ratio of the window
	gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 0.1f, 100.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
}

int InitGL(GLvoid)
{
	glShadeModel(GL_SMOOTH);
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
	glClearDepth(1.0f);
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
	return TRUE;
}

int DrawGLScene(GLvoid)
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();
	return TRUE;
}

GLvoid KillGLWindow(GLvoid)
{
	if (fullscreen)
	{
		ChangeDisplaySettings(NULL, 0);
		ShowCursor(TRUE);
	}

	if (hRC)
	{
		if(!wglMakeCurrent(NULL, NULL))
		{
			MessageBox(NULL, "Release of DC and RC failed, a shutdown error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONINFORMATION);
		}
	
		if (!wglDeleteContext(hRC))
		{
			MessageBox(NULL, "Reneasing the Rendering Context failed, a shutdown error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONINFORMATION);
		}
		hRC = NULL;
	}

	if (hDC && !ReleaseDC(hWnd, hDC))
	{
		MessageBox(NULL, "Releasing the Device Context failed, a shutdown error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONINFORMATION);
		hDC = NULL;
	}

	if (hWnd && !DestroyWindow(hWnd))
	{
		MessageBox(NULL, "The Window Handle could not be released, a shutdown error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONINFORMATION);
		hWnd = NULL;
	}

	if (!UnregisterClass("OpenGL", hInstance))
	{		
		MessageBox(NULL, "The Window Handle could not be unregistered, a shutdown error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONINFORMATION);		
		hInstance = NULL;	
}
}


/*
Create the OpenGL window''s parameteres
title, widht, height, bits, and the fullscreenflag.
*/

BOOL CreateGLWindow(char * title, int width, int height, int bits, bool fullscreenflag)
{
	GLunit	PixelFormat;
	WNDCLASS	wc;
	DWORD	dwExStyle;
	DWORD	dwStyle;
	RECT	WindowRect;
	WindowRect.left = (long)0;
	WindowRect.right = (long)width;
	WindowRect.top = (long)0;
	WindowRect.bottom = (long)height;

	fullscreen = fullscreenflag;

	hInstance = GetModuleHandle(NULL);
	wc.Style	= CS_HREDAW | CS_VREDAW | CS_OWNDC;
	wc.lpfnWndProc	= (WNDPROC) WndProc;
	wc.cbClsExtra	= 0;
	wc.cbWndExtra	= 0;
	wc.hInstance	= hInstance;
	wc.hIcon		= (HICON)LoadImage(hInstance,MAKEINTRESOURCE(IDI_PGRMICON),IMAGE_ICON,0,0,LR_DEFAULTSIZE);
	wc.hCursor	= LoadCursor(NULL, IDC_ARROW);
	wc.hbrBackground	= NULL;
	wc.lpszMenuName  = "IDR_MAINMENU";
	wc.lpszClassName	= "OpenGL";

	if (!RegisterClass(&wc))
	{
		MessageBox(NULL, "Failure to Register the Window''s Class, an error has occured.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (fullscreen)
	{
		DEVMODE dmScreenSettings;
		memset (&dmScreenSettings, 0, sizeof(dmScreenSettings));
		dmScreenSettings.dmSize = sizeof(dmScreenSettings);
		dmScreenSettings.dmPelsWidth = width;
		dmScreenSettings.dmPelsHeight = height;
		dmScreenSettings.dmBitsPerPel = bits;
		dmScreenSettings.dmFields = DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

	//
	// try setting fullscreen mode
	if (ChangeDisplaySettings(&dmScreenSettings, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
	{
		// if the change fails...
		if (MessageBox(NULL, "An error occured while trying to switch to FullScreenMode.  Use windowed mode instead?", "OrcishRendering - Error", MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
		{
			fullscreen = FALSE;
		}
		else
		{
			// tell the user that the program will now close
			MessageBox(NULL, "The Program will not close.", "OrcishRendering - ERROR", MB_OK|MB_ICONSTOP);
			return FALSE;
		}
	}
}

if (fullscreen)
{
	dwExStyle = WS_EX_APPWINDOW;
	dwStyle = WS_POPUP;
	ShowCursor(FALSE);
}
else
{
dwExStyle = WS_EX_APPWINDOW|WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW;
}

AdjustWindowRectEx(&WindowRect, dwStyle, FALSE, dwExStyle);

// create the window
if (!(hWnd = CreateWindowEX(
				dwExStyle,
				"OpenGL",
				title, 
				dwStyle|
				WS_CHIPSIBLINGS|
				WS_CHIPCHILDREN,
				0,
				0,
				WindowRect.right-WindowRect.left,
				WindowRect.bottom-WindowRect.top,
				NULL,
				wc.lpszMenuName  = "IDR_MAINMENU",	// menu
				hInstance,
				NULL)))

	{
		KillGLWindow();
		MessageBox(NULL, "An error occured while createing the window.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	static PIXELFORMATDESCRIPTOR pfd =
	{
		sizeof(PIXELFORMATDESCRIPTOR),
		1,
		PFD_DRAW_TO_WINDOW|
		PFD_SUPPORT_OPENGL|
		PFD_DOUBLEBUFFER,
		PFD_TYPE_RGBA,
		bits,
		0, 0, 0, 0, 0, 0,
		0,
		0,
		0,
		0, 0, 0, 0,
		16,
		0,
		0,
		PFD_MAIN_PLANE,
		0,
		0, 0, 0
	};

	if (!(hDC = GetDC(hWnd)))
	{
		KillGLWindow();
		MessageBox(NULL, "A Device Context could not be created.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd)))
	{
		KillGLWindow();
		MessageBox(NULL, "A suitable PixelFormat could not be found.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	if(!SetPixelFormat(hDC, PixelFormat, &pfd))
	{
		KillGLWindow();
		MessageBox(NULL, "Unable to set a Pixel Format.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	if (!(hRC = wglCreateContext(hDC)))
	{
		KillGLWindow();
		MessageBox(NULL, "Unable to create a Rendering Context.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	if(!wglMakeCurrent(hDC, hRC))
	{
		KillGLWindow();
		MessageBox(NULL, "Unable to activate the GL Rendering Context.", "OrcishRendering - ERROR", MB_OK|MB_ICONEXCLAMATION);
		return FALSE;
	}

	ShowWindow(hWnd, SW_SHOW);
	SetForegroundWindow(hWnd);						
	SetFocus(hWnd);									
	ReSizeGLScene(width, height);					

	if (!InitGL())									
	{
		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)			
{
	switch (uMsg)									
	{
		case WM_ACTIVATE:							
		{
			if (!HIWORD(wParam))					
			{
				active=TRUE;						
			}
			else
			{
				active=FALSE;						
			}

			return 0;								
		}

		case WM_SYSCOMMAND:							
		{
			switch (wParam)							
			{
				case SC_SCREENSAVE:					
				case SC_MONITORPOWER:				
				return 0;							
			}
			break;									
		}

		case WM_CLOSE:								
		{
			PostQuitMessage(0);						
			return 0;								
		}

		case WM_KEYDOWN:							
		{
			keys[wParam] = TRUE;					
			return 0;								
		}

		case WM_KEYUP:								
		{
			keys[wParam] = FALSE;					
			return 0;								
		}

		case WM_SIZE:								
		{
			ReSizeGLScene(LOWORD(lParam),HIWORD(lParam));  
			return 0;								
		}
	}

	return DefWindowProc(hWnd,uMsg,wParam,lParam);
}

int WINAPI WinMain(	HINSTANCE	hInstance,			
					HINSTANCE	hPrevInstance,		
					LPSTR		lpCmdLine,			
					int			nCmdShow)			
{
	MSG		msg;									
	BOOL	done=FALSE;								

	
	if (MessageBox(NULL,"Would You Like To Run In Fullscreen Mode?", "Start FullScreen?",MB_YESNO|MB_ICONQUESTION)==IDNO)
	{
		fullscreen=FALSE;							
	}

	// Create Our OpenGL Window
	if (!CreateGLWindow("NeHe''s OpenGL Framework",640,480,16,fullscreen))
	{
		return 0;									
	}

	while(!done)									
	{
		if (PeekMessage(&msg,NULL,0,0,PM_REMOVE))	
		{
			if (msg.message==WM_QUIT)				
			{
				done=TRUE;							
			}
			else									
			{
				TranslateMessage(&msg);				
				DispatchMessage(&msg);				
			}
		}
		else										
		{
			
			if (active)								
			{
				if (keys[VK_ESCAPE])				
				{
					done=TRUE;						
				}
				else								
				{
					DrawGLScene();					
					SwapBuffers(hDC);				
				}
			}

			if (keys[VK_F1])						
			{
				keys[VK_F1]=FALSE;					
				KillGLWindow();						
				fullscreen=!fullscreen;				
				
				if (!CreateGLWindow("NeHe''s OpenGL Framework",640,480,16,fullscreen))
				{
					return 0;						
				}
			}
		}
	}

	
	KillGLWindow();								
	return (msg.wParam);							
}
}
 
Advertisement
You need to include:

opengl32.lib || glu32.lib || glut32.lib || glaux.lib

I guess it's only the first two, if not add one after the other,
this should solve the error.

edit: typos

P.S: Thank for all the source code to skip

[edited by - Wildfire on July 2, 2003 10:01:07 AM]
How do I set my laser printer on stun?
if you can't figure out those errors maybe you shouldn't be
making games just yet... i mean most of them are typos which
tells me you don't know the first thing about win32 programming
or programming in general. I'm not trying to be meen, but you
would do yourself a big favor by learning the basics first.

[edited by - nafdahlix on July 2, 2003 10:16:03 AM]
Never said this had anything to do with a game, now did I? Just because Im posting something about 3D programming doesn''t automatically make it so that Im making a game . Not to be mean or nast or anything like that I appreciate your comment(s). Thanks for the help. Its gone down to one error now. How come NeHe didn''t include those in the source? I guess it doesnt really matter...

Thanks,
orcblood
quote:Original post by orcblood
How come NeHe didn''t include those in the source?


Excerpt from lesson 1:
quote:
After you have created a new Win32 Application (NOT a console application) in Visual C++, you will need to link the OpenGL libraries. In Visual C++ go to Project, Settings, and then click on the LINK tab. Under "Object/Library Modules" at the beginning of the line (before kernel32.lib) add OpenGL32.lib GLu32.lib and GLaux.lib. Once you''ve done this click on OK. You''re now ready to write an OpenGL Windows program.


Excerpt from download for lesson 31
#pragma comment( lib, "opengl32.lib" )								// Search For OpenGL32.lib While Linking ( NEW )#pragma comment( lib, "glu32.lib" )									// Search For GLu32.lib While Linking    ( NEW )#pragma comment( lib, "glaux.lib" )									// Search For GLaux.lib While Linking    ( NEW )


It''s in there.

-solo (my site)
-solo (my site)
Well, I suppose that makes some sense . Suppose I should have double checked . Thanks.

orcblood
So you''re good to go... good luck!

-solo (my site)
-solo (my site)
yay I got it to work! Thanks for your help. I have one question - I already have it set so fullscreen mode will not come up - since I am making a windows program it only makes sense. I was wondering: how would I add a menu? Would it be the same process as adding a menu to a normal Win32 program? I tried adding the wc.lpszMenuName = "IDR_MENU"; feature that you would normally put - according to a book and a website tutorial that I have - though spelling may be off because I have not checked (I assume that you get my meaning though)... How would I go about adding the menu. once ther I can code the features for each specific part easily enough.

Thanks for any help,
orcblood

[edited by - orcblood on July 2, 2003 6:05:50 PM]

This topic is closed to new replies.

Advertisement