Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Weird link error

This topic is 5685 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I''m doign my framework and i get this weird link error... LIBCD.lib(crt0.obj) : error LNK2001: unresolved external symbol _main these are my sources 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"

HDC g_hDC;	// Global device context.

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

		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.

		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;

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

			// Send WM_QUIT to message queue.

			return 0;

		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;

		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.



	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;


	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.
			// Do rendering here
			// Clear screen and depth buffer.
			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: implementation of the COGLWindow class.



#include "OGLWindow.h"


// Construction/Destruction


	m_fullscreen= false;


 * InitGL : Tout les Setup pour OpenGL se feront ici. C''est à dire le code pour les graphiques
 *		et les jeux.
bool 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.
	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.
bool 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.

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

	if (m_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

		// 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?"
				m_fullscreen= false;	// Set the fullscreen variable to windowed mode.
				MessageBox(NULL,"The program will now stop."

				return false;

	if (m_fullscreen)	// Are we in fullscreen mode?
		dwExStyle= WS_EX_APPWINDOW;	// Window Extended Style
		dwStyle= WS_POPUP;			// Windows Style
		ShowCursor(FALSE);			// Hide Mouse Pointer
		dwExStyle= WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;	// Window Extended Style
				| 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
		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.
		MessageBox(NULL,"Impossible d''initialiser la fenêtre GL qui a été créer."
		return false;

	return true;	// 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: 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.

class COGLWindow  
	virtual ~COGLWindow();

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

	bool m_fullscreen;


#endif // !defined(AFX_OGLWINDOW_H__F1CF4758_8266_4481_A28D_92462D6C1B07__INCLUDED_)

thx for ya help ------------------------- Knowledge Is For Everyone SnowKing3k SnowKing3k@hotmail.com

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!