Skip to main content
GameDev.net gamedev.net
🔒 Locked

Help with my windows code

Started by knealeaj May 4, 2004 at 9:48 AM 3 replies 300+ views
Original Post
knealeaj
knealeaj
I am suffering with these errors. Can anyone suggest anything.The errors and code will be displayed below Thanks Window.obj : error LNK2001: unresolved external symbol __imp__wglMakeCurrent@8 Window.obj : error LNK2001: unresolved external symbol __imp__wglCreateContext@4 Window.obj : error LNK2001: unresolved external symbol __imp__wglDeleteContext@4 Window.obj : error LNK2001: unresolved external symbol _gluPerspective@32 Window.obj : error LNK2001: unresolved external symbol __imp__glLoadIdentity@0 Window.obj : error LNK2001: unresolved external symbol __imp__glMatrixMode@4 Window.obj : error LNK2001: unresolved external symbol __imp__glViewport@16 Window.obj : error LNK2001: unresolved external symbol "public: __thiscall Window::~Window(void)" (??1Window@@QAE@XZ) Debug/Project.exe : fatal error LNK1120: 8 unresolved externals Error executing link.exe. ///////////////////////////////////////////////////////////////// Window.h #ifndef _WINDOW_H_ #define _WINDOW_H_ //HEADER FILE THAT DEFINES A CLASS FOR THE WINDOW #define WIN32_LEAN_AND_MEAN //trim extra fat from windows //INCLUDES/////////////////////////////////////////////////////////////////// #include <windows.h> //standard windows app include #include <gl/gl.h> //standard OpenGL include #include <gl/glu.h> //OpenGL utilities #include <gl/glaux.h> //OpenGL auxillary functions ///////////////////////////////////////////////////////////////////////////// //CLASS DECLERATION////////////////////////////////////////////////////////// class Window { private: HWND hwnd; //window handle HGLRC hRC; //rendering context HDC hDC; //device context //The Windows Procedure event handler friend LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam); //function to set up the pixel format for the device context void SetupPixelFormat(); bool Create(); //WM_CREATE void Destroy(); //WM_DESTROY void Size(); //WM_SIZE public: int width; //width of window int height; //height of window bool fullscreen; //Fullscreen?? int bits; //no of bits //Default Constructor//////////////////////////////////////////////////// Window(){} //Constructor//////////////////////////////////////////////////////////// Window(const char* windowName,bool fscreen,int w,int h,int b); //Destructor///////////////////////////////////////////////////////////// ~Window(); //Register Window //Must be used before the class is used as it is static static bool RegisterWindow(HINSTANCE hInstance); }; #endif /////////////////////////////////////////////////////////////// Window.cpp #include "Window.h" /////////////////FUNCTIONS///////////////////////////////////////////////////////////////// void Window::SetupPixelFormat() { int pixelFormat; //the pixel format index static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), //size of structure 1, //version always set to one PFD_DRAW_TO_WINDOW|PFD_SUPPORT_OPENGL|PFD_DOUBLEBUFFER, //support window,opengl and double buffering PFD_TYPE_RGBA, //RGBA colour mode 32, //32 bit colour mode 0,0,0,0,0,0, //colour bits not used 0, //no alpha buffer 0, //ignore shift bit 0, //no acclumulation buffer 0,0,0,0, //ignore accumulation bits 16, //16-bit depth buffer 0, //no stencil buffer 0, //no auxillary buffer PFD_MAIN_PLANE, //main drawing plane 0, //reserved 0,0,0}; //ignore layers mask //choose best matching pixel format pixelFormat = ChoosePixelFormat(hDC,&pfd); //set pixel format to device context SetPixelFormat(hDC,pixelFormat,&pfd); } //Creates the window bool Window::Create() { hDC = GetDC(hwnd); //get windows current device context SetupPixelFormat(); //call the pixel format setup function //create rendering context and make it current hRC = wglCreateContext(hDC); wglMakeCurrent(hDC,hRC); return true; //on creation of window retun true } //Destroy the window void Window::Destroy() { if(hRC) { //deselect rendering context and delete it wglMakeCurrent(hDC,NULL); wglDeleteContext(hRC); } SetWindowLong(hwnd, GWL_USERDATA, (LONG)NULL); DestroyWindow(hwnd); } //resizing of the window void Window::Size() { if(height ==0) //dont want to divide by zero { height =1; } //reset the viewport to the new dimensions glViewport(0,0,width,height); glMatrixMode(GL_PROJECTION); //set the projection matrix glLoadIdentity(); //reset projection matrix //calculate aspect ratio of window gluPerspective(45.0f,(float)width/(float)height,1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); //set matrix mode to modelview glLoadIdentity(); //reset modelview matrix } LRESULT CALLBACK WndProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam) { Window OpenGLwindow; switch(message) { case WM_CREATE: { OpenGLwindow.hwnd = hwnd; //create the window OpenGLwindow.Create(); }break; case WM_QUIT: case WM_CLOSE: { //close the window OpenGLwindow.Destroy(); PostQuitMessage(0); return 0; }break; case WM_DESTROY: { OpenGLwindow.Destroy(); PostQuitMessage(0); return 0; }break; case WM_SIZE: { OpenGLwindow.height = HIWORD(lParam); //retrieve width and height OpenGLwindow.width = LOWORD(lParam); OpenGLwindow.Size(); return 0; }break; default : break; } return (DefWindowProc(hwnd,message,wParam,lParam)); } bool Window::RegisterWindow(HINSTANCE hInstance) { WNDCLASSEX windowClass; //the 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 = hInstance; windowClass.hIcon = LoadIcon(NULL,IDI_APPLICATION); windowClass.hCursor = LoadCursor(NULL,IDC_ARROW); windowClass.hbrBackground = NULL; windowClass.lpszMenuName = NULL; windowClass.lpszClassName = "FatHead Engine"; windowClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO); //register the class if(!RegisterClassEx(&windowClass)) return false; return true; } ///////////////////////////////////////////////////////////////// WinMain.cpp #include <windows.h> #include "Window.h" int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nShowCmd) { HWND hwnd; //window handle MSG msg; //message bool done; //is the application finished if(!Window::RegisterWindow(hInstance)) { MessageBox(NULL,"Cannot register window class","Error",MB_OK); return -1; } hwnd = CreateWindowEx(NULL, //extended style "Fathead Engine", //class name "Fathead Engine", //application name WS_OVERLAPPEDWINDOW|WS_VISIBLE|WS_SYSMENU|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 100,100, //x,y coordinate 400,400, //width,height NULL, NULL, hInstance, //application instance NULL); //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 done = false; //Main message loop while(!done) { PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE); if(msg.message == WM_QUIT) { done = true; } else { TranslateMessage(&msg); //send event to queue DispatchMessage(&msg); } } return msg.wParam; }
VolkerG
VolkerG
- Did you link with opengl32.lib and glu32.lib?
- Where is the implementation of the destructor for the Window class (Window::~Window)?
NicolasX
NicolasX
You can link with the OGL libraries in code by:

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

knealeaj
knealeaj
THANKS GUYS
MauMan
MauMan
Off topic but please put source code between [source] ... [/source] tags.

Cheers!
---CyberbrineDreamsSuspected implementation of the Windows idle loop: void idle_loop() { *((char*)rand()) = 0; }

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.