Archived

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

Some OGL Link Error...

This topic is 5148 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

hi... My code:

#include <windows.h>
#include <gl/gl.h>
#include <gl/glu.h>
#include <gl/glaux.h>
#include <iostream>
using namespace std;


WPARAM MainWinLoop();
LRESULT CALLBACK MainMsg(HWND, UINT, WPARAM, LPARAM);
bool RegisterWin(HINSTANCE, WNDPROC, LPSTR);
bool CreateWin(HINSTANCE, HWND&, LPSTR, LPSTR);
bool SetupPixelFormat(HDC&);
bool IntiOGL(HDC&, HWND&, RECT&, HGLRC&);
void DestroyWin(HINSTANCE, HWND&, LPSTR);
void Paint(HWND, PAINTSTRUCT&);
void RenderScene();


HWND g_hWnd = NULL;
HDC g_hDc = NULL;
RECT g_rect;
HGLRC g_hGlrc = NULL;
PAINTSTRUCT g_paintStruct;


float angle = 0;


int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
					LPSTR lpstrCmdLine, int iCmdShow)
{
	if(!RegisterWin(hInstance, MainMsg, "OpenGL_Test"))
	{
		return -1;
	}

	if(!CreateWin(hInstance, g_hWnd, "OpenGL_Test", "OpenGL Test"))
	{
		return -2;
	}
	
	ShowWindow(g_hWnd, SW_SHOWNORMAL);
	UpdateWindow(g_hWnd);

	if(!IntiOGL(g_hDc, g_hWnd, g_rect, g_hGlrc))
	{
		return -3;
	}

	return (int)MainWinLoop();
}


WPARAM MainWinLoop()
{
	MSG msg;
	bool done = false;

	while(!done)
	{
		if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
		{
			if(msg.message == WM_QUIT)
			{
				done = true;
				break;
			}

			TranslateMessage(&msg);
			DispatchMessage(&msg);

		}
		else
		{
			RenderScene();
		}

	}

	return msg.wParam;
}


LRESULT CALLBACK MainMsg(HWND hwnd, UINT uiMsg, WPARAM wParam,
						 LPARAM lParam)
{
	switch(uiMsg)
	{
		case WM_PAINT:
			{
				Paint(hwnd, g_paintStruct);
				break;
			}
		case WM_CREATE:
			{
				break;
			}
		case WM_CLOSE:
			{
				PostQuitMessage(0);
				break;
			}
		case WM_DESTROY:
			{
				break;
			}
		default:
			{
				break;
			}
	}

	return DefWindowProc(hwnd, uiMsg, wParam, lParam);
}


bool RegisterWin(HINSTANCE hInstance, WNDPROC wndProc, LPSTR className)
{
	WNDCLASSEX wcx;
	
	wcx.cbSize = sizeof(WNDCLASSEX);
	wcx.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC;
	wcx.lpfnWndProc = wndProc;
	wcx.lpszClassName = className;
	wcx.hInstance = hInstance;

	wcx.hbrBackground = (HBRUSH)GetStockObject(WHITE_BRUSH);
	wcx.hCursor = LoadCursor(NULL, IDC_ARROW);
	wcx.hIcon = LoadIcon(NULL, IDI_APPLICATION);
	wcx.hIconSm = LoadIcon(NULL, IDI_WINLOGO);

	wcx.cbClsExtra = NULL;
	wcx.cbWndExtra = NULL;
	wcx.lpszMenuName = NULL;

	if(!RegisterClassEx(&wcx))
	{
		return false;
	}
	
	return true;
}


bool CreateWin(HINSTANCE hInstance, HWND &hWnd, LPSTR className, LPSTR winCaption)
{
	hWnd = CreateWindowEx(NULL,
				          className,
                          winCaption,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          CW_USEDEFAULT,
                          NULL,
                          NULL,
                          hInstance,
                          NULL);

	if(!hWnd)
	{
		return false;
    }

	return true;
}


bool SetupPixelFormat(HDC &hDc)
{
	PIXELFORMATDESCRIPTOR pfd;
	int iPixelFormat;

	pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
	pfd.nVersion = 1;
	pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
	pfd.dwLayerMask = PFD_MAIN_PLANE;
	pfd.iLayerType = PFD_TYPE_RGBA;
	pfd.cColorBits = 16;
	pfd.cDepthBits = 16;
	pfd.cAccumBits = 0;
	pfd.cStencilBits = 0;
	
	iPixelFormat = ChoosePixelFormat(hDc,&pfd);

	if(!SetPixelFormat(hDc,iPixelFormat,&pfd))
	{
		return false;
	}

	return true;
}


bool IntiOGL(HDC &hDc, HWND &hWnd, RECT &rect, HGLRC &hGlrc)
{
	GetClientRect(hWnd, &rect); 

	hDc = GetDC(hWnd);

	if(!SetupPixelFormat(hDc))
	{
		return false;
	}

	hGlrc = wglCreateContext(hDc);

	wglMakeCurrent(hDc, hGlrc);

	glViewport(0, 0, rect.right, rect.bottom);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();

	gluPerspective(45.0f, (GLfloat)rect.right/(GLfloat)rect.bottom, 1.0f, 1000.0f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	return true;
}


void DestroyWin(HINSTANCE hInstance, HWND &hWnd, LPSTR className)
{
	UnregisterClass(className, hInstance);
	DestroyWindow(hWnd);
}


void Paint(HWND hWnd, PAINTSTRUCT &paintStruct)
{
	BeginPaint(hWnd, &paintStruct);
	EndPaint(hWnd, &paintStruct);
}


void RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glLoadIdentity();

	angle = angle + 0.1f;

	if(angle >= 360.0f) angle = 0.0f;

	glTranslated(0.0f, 0.0f, -5.0f);
	glRotatef(angle, 0.0f, 0.0f, 1.0f);

	glColor3f(0.0f, 0.0f, 1.0f);

	glBegin(GL_TRIANGLES);
		glVertex3f(0.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 0.0f, 0.0f);
		glVertex3f(1.0f, 1.0f, 0.0f);
	glEnd();

	SwapBuffers(g_hDc);
}
The errors are:
WinOGLTest error LNK2019: unresolved external symbol __imp__glBegin@4 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glColor3f@12 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glEnd@0 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glLoadIdentity@0 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest error LNK2019: unresolved external symbol __imp__glMatrixMode@4 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest error LNK2019: unresolved external symbol __imp__glRotatef@16 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glTranslated@24 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glVertex3f@12 referenced in function "void __cdecl RenderScene(void)" (?RenderScene@@YAXXZ)
WinOGLTest error LNK2019: unresolved external symbol __imp__glViewport@16 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest error LNK2019: unresolved external symbol _gluPerspective@32 referenced in function "bool __cdecl IntiOGL(struct HDC__ * &,struct HWND__ * &,struct tagRECT &,struct HGLRC__ * &)" (?IntiOGL@@YA_NAAPAUHDC__@@AAPAUHWND__@@AAUtagRECT@@AAPAUHGLRC__@@@Z)
WinOGLTest fatal error LNK1120: 13 unresolved externals
Don''t know why..... Please help point out the error in my code......... Thanks

Share this post


Link to post
Share on other sites