Getting tired of this .h .cpp bug!!!!

Started by
3 comments, last by SnowKing3k 21 years, 1 month ago
Ok... can u for the love of god help me with this f****** bug!!! Main.cpp
      
/* Main.cpp : This is where the OpenGL program will begin. Here we will create the window and
 *		handle the different messages sent from Windows.
 *
 * Date : 15/02/2003 dd/mm/yyyy
 * Creator : Nicolas Courcy
 * Email : SnowKing3k@hotmail.com
 */

#define WIN32_LEAN_AND_MEAN		// Trim excess fat from Windows.

#include <windows.h>		// Standard Windows app includes.
#include <gl/gl.h>			// Standard OpenGL include.
#include <gl/glu.h>			// OpenGL utilities.
#include <gl/glaux.h>		// OpenGL auxiliary functions.

#include "OGLWindow.h"

/******
 * SetupPixelFormat : This function will set the pixel format for the device context.
 */
void SetupPixelFormat(HDC p_hDC)
	{
	int nPixelFormat;		// Your pixel format index.

	static PIXELFORMATDESCRIPTOR pfd= {
		sizeof(PIXELFORMATDESCRIPTOR),		// Size of the structure.
		1,									// Version, always set to 1.
		PFD_DRAW_TO_WINDOW |				// Support window.
		PFD_SUPPORT_OPENGL |				// Support OpenGL.
		PFD_DOUBLEBUFFER,					// Support double buffering.
		PFD_TYPE_RGBA,						// RBGA color mode.
		32,									// Go for 32 bit color mode.
		0, 0, 0, 0, 0, 0,					// Ignore color bits, not used.
		0,									// No alpha buffer.
		0,									// Ignore shift bit.
		0,									// No accumulation buffer.
		0, 0, 0, 0,							// Ignore accumulation bits.
		16,									// 16-bit z-buffer size.
		0,									// No stencil buffer.
		0,									// No auxiliary buffer.
		PFD_MAIN_PLANE,						// Main drawing plane.
		0,									// Reserved.
		0, 0, 0 };							// Layer masks ignored.

	// Choose best matching pixel format, it will return an index.
	nPixelFormat= ChoosePixelFormat(p_hDC, &pfd);

	// Set pixel format to device context.
	SetPixelFormat(p_hDC, nPixelFormat, &pfd);
	}

/*****
 * WndProc : This function will handle almost messages sent from Windows.
 */
LRESULT CALLBACK WndProc(HWND p_hwnd, UINT p_message, WPARAM p_wParam, LPARAM p_lParam)
	{
	static HGLRC hRC;	// Rendering context.
	static HDC hDC;		// Device context.
	int width, height;	// Window width and height.

	switch(p_message)
		{
		case WM_CREATE:		// The window is being create.
			{
			hDC= GetDC(p_hwnd);		// Get current window's device context.
			g_hDC= hDC;
			SetupPixelFormat(hDC);	// Call your pixel format setup function.

			// Create rendering context and make it current.
			hRC= wglCreateContext(hDC);
			wglMakeCurrent(hDC, hRC);

			return 0;
			break;
			}

		case WM_CLOSE:		// The window is closing.
			{
			// Deselect rendering context and delete it.
			wglMakeCurrent(hDC, NULL);
			ReleaseDC(p_hwnd, hDC);
			wglDeleteContext(hRC);

			// Send WM_QUIT to message queue.
			PostQuitMessage(0);

			return 0;
			break;
			}

		case WM_SIZE:
			{
			height= HIWORD(p_lParam);	// Retrieve width and height.
			width= LOWORD(p_wParam);

			if (height == 0)	// To not divide by zero.
				height= 1;

			// Reset the viewport to new dimensions.
			glViewport(0, 0, width, height);
			glMatrixMode(GL_PROJECTION);	// Set projection matrix.
			glLoadIdentity();				// Reset projection matrix.

			// Calculate aspect ratio of window.
			gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f, 1000.0f);

			glMatrixMode(GL_MODELVIEW);		// Set modelview matrix.
			glLoadIdentity();				// Reset modelview matrix.

			return 0;
			break;
			}

		case WM_SYSCOMMAND:	// Intercept systems command.
			{
			switch (p_wParam)	// Verify systems calls.
				{
				case SC_SCREENSAVE:		// If the screensaver try to turn on.
				case SC_MONITORPOWER:	// If the monitor try to get off.
				return 0;	// It will be stop.
				}

			break;
			}

		default:
			break;
		}

	return DefWindowProc(p_hwnd, p_message, p_wParam, p_lParam);
	}

/*****
 * RegisterWindowClass : This function will register your Window class.
 */
bool RegisterWindowClass(HINSTANCE p_hInstance)
	{
	WNDCLASSEX windowClass;		// Window class.

	// Fill out the window class structure.
	windowClass.cbSize= sizeof(WNDCLASSEX);
	windowClass.style= CS_HREDRAW | CS_VREDRAW;
	windowClass.lpfnWndProc= WndProc;
	windowClass.cbClsExtra= 0;
	windowClass.cbWndExtra= 0;
	windowClass.hInstance= p_hInstance;
	windowClass.hIcon= LoadIcon(NULL, IDI_APPLICATION);
	windowClass.hCursor= LoadCursor(NULL, IDC_ARROW);
	windowClass.hbrBackground= NULL;
	windowClass.lpszMenuName= NULL;
	windowClass.lpszClassName= "Coding_Heaven OpenGL";
	windowClass.hIconSm= LoadIcon(NULL, IDI_WINLOGO);

	// Register the window class
	if (!RegisterClassEx(&windowClass))
		{
		MessageBox(NULL, "Unable to register the window.", "ERROR", MB_OK|MB_ICONEXCLAMATION);
		return false;
		}
	
	return true;
	}

/*****
 * WinMain : The main Windows entry point.
 */
int WINAPI WinMain(HINSTANCE p_hInstance, HINSTANCE p_hPrevInstance, LPSTR p_lpCmdLine,
				   int p_nShowCmd)
	{
	COGLWindow OGLWindow;

	RegisterWindowClass(p_hInstance);

	HWND hwnd;	// Window handle.

	OGLWindow.CreateGLWindow(hwnd, p_hInstance, "Coding_Heaven OpenGL", 600, 480, 16, FALSE);

	// Check if window creation failed (hwnd would equal NULL).
	if (!hwnd)
		return 0;

	ShowWindow(hwnd, SW_SHOW);	// Display the window.
	UpdateWindow(hwnd);			// Update the window.

	bool done;					// Flag saying when your app is complete.

	done= false;	// Initialize the loop condition variable.
	
	MSG msg;					// Message.

	while (!done)
		{
		PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE);

		if (msg.message == WM_QUIT)
			done= true;		// If so, time to quit application.
		else
			{
			// Do rendering here
			// Clear screen and depth buffer.
			glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
			glLoadIdentity();		// Reset modelview matrix.

			/************************************************
			**********HERE YOU ENTER YOUR GAME CODE**********
			************************************************/

			SwapBuffers(g_hDC);		// Bring back buffer to foreground.


			TranslateMessage(&msg);		// Translate.

			DispatchMessage(&msg);		// Dispatch to event queue.

			}
		}
	
	return msg.wParam;
	}
  
OGLWindow.cpp
  
#include "OGLWindow.h"

//////////////////////////////////////////////////////////////////////

// Construction/Destruction

//////////////////////////////////////////////////////////////////////


COGLWindow::COGLWindow()
{}

COGLWindow::~COGLWindow()
{}

/*****
 * InitGL : Tout les Setup pour OpenGL se feront ici. C'est à dire le code pour les graphiques
 *		et les jeux.
 */
int COGLWindow::InitGL()
	{
	glShadeModel(GL_SMOOTH);	// Enable Smooth Shading. Smooth Shading
								//  that's what will make a good mix between colors.

	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);	// Set the background color to black.

	glClearDepth(1.0f);			// Clear the screen from all object in depth.
	glEnable(GL_DEPTH_TEST);
	glDepthFunc(GL_LEQUAL);
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);	// The nicest perspective we can have.

	return TRUE;	// We suppose that all went good.
	}

/*****
 * CreateGLWindow : This function will create the OpenGL window.
 */
HWND COGLWindow::CreateGLWindow(HWND& p_es_hwnd, HINSTANCE p_hInstance, char* p_title, int p_width
								, int p_height, int p_bits, bool p_fullscreenflag)
	{
	RECT windowRect;					// Instanciate a variable of the class RECT.
	windowRect.left= (long)0;			// Set left to 0.
	windowRect.right= (long)p_width;	// Set right to the p_width.
	windowRect.top= (long)0;			// Set top to 0.
	windowRect.bottom= (long)p_height;	// Set bottom to p_height.

	g_fullscreen= p_fullscreenflag;	// Set the fullscreen boolean to the what we got in parameter.
	
	DWORD dwExStyle;	// Window Extended Style
	DWORD dwStyle;		// Window Style


	if (g_fullscreen)	// if the user want to be in fullscreen mode.
		{
		DEVMODE dmScrSettings;								// Instanciate a variable of DEVMODE.
		memset(&dmScrSettings, 0, sizeof(dmScrSettings));	// Set a memory space for the
															//  structure.
		dmScrSettings.dmSize= sizeof(dmScrSettings);		// Set the size of the structure.
		dmScrSettings.dmPelsWidth= p_width;					// Selected Screen Width
		dmScrSettings.dmPelsHeight= p_height;				// Selected Screen Height
		dmScrSettings.dmBitsPerPel= p_bits;					// Selected Bits Per Pixel
		dmScrSettings.dmFields= DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;

		// Try to change de display of the screen with the new settings we've made.
		//  NOTE: CDS_FULLSCREEN Gets Rid Of Start Bar.
		if (ChangeDisplaySettings(&dmScrSettings,CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL)
			{
			// If the mode is not supported we give the user two choices. We continue in
			//  windowed mode or we quit.
			if (MessageBox(NULL,"The fullscreen mode if not supported\nby your video card."
				"Would continue in windowed mode?"
				,"Coding_Heaven GL",MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
				g_fullscreen= false;	// Set the fullscreen variable to windowed mode.
			else
				{
				MessageBox(NULL,"The program will now stop."
					,"ERROR",MB_OK|MB_ICONSTOP);

				return false;
				}
			}
		}

	if (g_fullscreen)	// Are we in fullscreen mode?
		{
		dwExStyle= WS_EX_APPWINDOW;	// Window Extended Style
		dwStyle= WS_POPUP;			// Windows Style
		ShowCursor(FALSE);			// Hide Mouse Pointer
		}
	else
		{
		dwExStyle= WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;	// Window Extended Style
		dwStyle= WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_CLIPCHILDREN
				| WS_CLIPSIBLINGS;	// Windows Style
		}
		
	AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);	// Ajusd the window to the
																//  size wanted.

	// Create The Window
	if (!(p_es_hwnd= CreateWindowEx(dwExStyle,					// Extended Style For The Window
								"Coding_Heaven OpenGL",			// Class Name
								p_title,						// Window Title
								dwStyle,						// Required Window Style
								0, 0,							// Window Position
								windowRect.right-windowRect.left,// Calculate Window Width
								windowRect.bottom-windowRect.top,// Calculate Window Height
								NULL,							// No Parent Window
								NULL,							// No Menu
								p_hInstance,					// Instance
								NULL)))							// Dont Pass Anything To WM_CREATE
		{
		//KillGLWindow();	// Return to desktop
		PostQuitMessage(0);
		MessageBox(NULL,"Cannot create the window.","ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
		}

	ShowWindow(p_es_hwnd,SW_SHOW);			// Fait apparaître la fenêtre.
	SetForegroundWindow(p_es_hwnd);			// Met la fenêtre à une priorité plus élevé dans 
											//  les processus
	SetFocus(p_es_hwnd);					// Set le Keyboard en focus sur la fenêtre.
//	ReSizeGLScene(p_width, p_height);	// Set la perspective de notre fenêtre GL.

	if (!InitGL())	// Initialise notre nouvelle fenêtre.
		{
		//KillGLWindow();	// Retourne au Desktop.
		PostQuitMessage(0);
		MessageBox(NULL,"Impossible d'initialiser la fenêtre GL qui a été créer."
			,"ERROR",MB_OK|MB_ICONEXCLAMATION);
		return false;
		}

	return p_es_hwnd;	// Avec tous les tests qu'on a fait on suppose que si on ai rendu ici
						//  c'est que tous c'est bien passé.
	}

/*****
 * KillGLWindow :
 */
void COGLWindow::KillGLWindow()
	{
		
	}
  
OGLWindow.h
        
// OGLWindow.h: interface for the COGLWindow class.

//

//////////////////////////////////////////////////////////////////////


#if !defined(AFX_OGLWINDOW_H__F1CF4758_8266_4481_A28D_92462D6C1B07__INCLUDED_)
#define AFX_OGLWINDOW_H__F1CF4758_8266_4481_A28D_92462D6C1B07__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000


#define WIN32_LEAN_AND_MEAN		// Trim excess fat from Windows.


#include <windows.h>		// Standard Windows app includes.
#include <gl/gl.h>			// Standard OpenGL include.
#include <gl/glu.h>			// OpenGL utilities.
#include <gl/glaux.h>		// OpenGL auxiliary functions.


#include "Declarations.h"	// This header file will caontain all the global variables.


class COGLWindow  
{
public:
	COGLWindow();
	virtual ~COGLWindow();

	void KillGLWindow();
	int InitGL();
	HWND CreateGLWindow(HWND& p_es_hwnd, HINSTANCE p_hInstance, char* p_title
		, int p_width, int p_height, int p_bits, bool p_fullscreenflag);


};

#endif // !defined(AFX_OGLWINDOW_H__F1CF4758_8266_4481_A28D_92462D6C1B07__INCLUDED_)

  
Declarations.h
        
#if !defined DECLARATIONS_H_INCLUS
#define DECLARATIONS_H_INCLUS

#include <windows.h>

bool g_fullscreen;
HDC g_hDC;	// Global device context.


struct TypeOGLWindow
	{
	char* windowTitle;
	int windowWidth;
	int windowHeight;
	int windowBits;
	bool fullscreen;
	};

#endif
  
These are the bugs it gives me.... OGLWindow.obj : error LNK2005: "bool g_fullscreen" (?g_fullscreen@@3_NA) already defined in Main.obj OGLWindow.obj : error LNK2005: "struct HDC__ * g_hDC" (?g_hDC@@3PAUHDC__@@A) already defined in Main.obj LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main Debug/OGLWindow.exe : fatal error LNK1120: 1 unresolved externals thx for ya help!!! ------------------------- Knowledge Is For Everyone SnowKing3k SnowKing3k@hotmail.com [edited by - SnowKing3k on March 2, 2003 8:14:38 PM] [edited by - SnowKing3k on March 2, 2003 8:20:04 PM]
-------------------------Knowledge Is For EveryoneSnowKing3kSnowKing3k@hotmail.com
Advertisement
Change

bool g_fullscreen;
HDC g_hDC;// Global device context.

to

extern bool g_fullscreen;
extern HDC g_hDC;// Global device context.

and add

bool g_fullscreen;
HDC g_hDC;// Global device context.

to one of the cpp files.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
It may also be set to compile as a console program, which doesn''t seem like what you want.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
I had
bool g_fullscreen;
HDC g_hDC;// Global device context.
in the constructor of COGLWindow
and now....

c:\opengl\framework\framework\main.cpp(21) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file ''msc1.cpp'', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information
OGLWindow.cpp
c:\opengl\framework\framework\oglwindow.cpp(11) : fatal error C1001: INTERNAL COMPILER ERROR
(compiler file ''msc1.cpp'', line 1786)
Please choose the Technical Support command on the Visual C++
Help menu, or open the Technical Support help file for more information

-------------------------
Knowledge Is For Everyone

SnowKing3k
SnowKing3k@hotmail.com
-------------------------Knowledge Is For EveryoneSnowKing3kSnowKing3k@hotmail.com
No it''s an OpenGL FrameWork that I''m beginning to do...

thx

-------------------------
Knowledge Is For Everyone

SnowKing3k
SnowKing3k@hotmail.com
-------------------------Knowledge Is For EveryoneSnowKing3kSnowKing3k@hotmail.com

This topic is closed to new replies.

Advertisement