Setting up...

Started by
4 comments, last by sPriTe 22 years, 2 months ago
I have set up my Microsoft C++ 6.0 Profesional and written the code below from the ''OpenGL Game Programming'' book. It compiles fine but gives me a heap load of linking errors regarding OpenGL functions that it has access to. I''m sure I''ve pointed to all the right folders. Can anyone give us a clue??? Cheers #define WIN32_LEAN_AND_MEAN #include <windows.h> #include <gl/gl.h> #include <gl/glu.h> #include <gl/glaux.h> #define WND_CLASS_NAME "OpenGL Window Class" float angle = 0.0f; HDC g_HDC; void SetupPixelFormat(HDC); LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM); void render( void ); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { WNDCLASSEX windowClass; HWND hwnd; MSG msg; bool done; 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_WINLOGO); windowClass.hCursor = LoadCursor(NULL, IDC_ARROW); windowClass.hbrBackground = NULL; windowClass.lpszMenuName = NULL; windowClass.lpszClassName = "SpinnerClass"; windowClass.hIconSm = LoadIcon(NULL,IDI_WINLOGO); if(!RegisterClassEx(&windowClass)) return 0; hwnd = CreateWindowEx( NULL, "SpinnerClass", "The OpenGL Window Application", WS_OVERLAPPEDWINDOW | WS_VISIBLE | WS_SYSMENU | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, 100, 100, 400, 400, NULL, NULL, hInstance, NULL); if(!hwnd) return 0; ShowWindow(hwnd, SW_SHOW); UpdateWindow(hwnd); done = false; while(!done){ PeekMessage(&msg, hwnd, NULL, NULL, PM_REMOVE); if(msg.message == WM_QUIT) { done = true; } else { render(); TranslateMessage(&msg); DispatchMessage(&msg); } } return msg.wParam; } void SetupPixelFormat(HDC hDC){ int nPixelFormat; static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR), 1, PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER, PFD_TYPE_RGBA, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, PFD_MAIN_PLANE, 0, 0, 0, 0}; nPixelFormat = ChoosePixelFormat(hDC, &pfd); SetPixelFormat(hDC, nPixelFormat, &pfd); } LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { static HGLRC hRC; static HDC hDC; char string[]="Spinner"; int width, height; switch(message){ case WM_CREATE: hDC = GetDC(hwnd); g_HDC = hDC; SetupPixelFormat(hDC); hRC = wglCreateContext(hDC); wglMakeCurrent(hDC, hRC); return 0; break; case WM_CLOSE: wglMakeCurrent(hDC, NULL); wglDeleteContext(hRC); PostQuitMessage(0); return 0; break; case WM_SIZE: height = HIWORD(wParam); width = LOWORD(lParam); if(height == 0) { height = 1; } glViewport(0, 0, width, height); glLoadIdentity(); gluPerspective(45.0f, (GLfloat)width/(GLfloat)height, 1.0f,1000.0f); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); return 0; break; default: break; } return (DefWindowProc(hwnd, message, wParam, lParam)); } void render( void ){ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glLoadIdentity(); angle = angle + 0.1f; if(angle >= 360.0f) angle = 0.0f; glTranslatef(0.0f, 0.0f, -5.0f); glRotatef(angle, 0.0f, 0.0f, 1.0f); glColor3f(1.0f, 0.0f, 0.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); }
//**## sPriTe ##**//
Advertisement
Did you remember to link to opengl libraries?

To do so:

Project->Settings
Click Link tab
Under Object/library models add

opengl32.lib glu32.lib

That should help.
And this should also be in the For Beginners forum... =)

- Mike
"The important thing to remember when programming is: When you're 90% complete, there's still 50% more to go."
I would look at the tutorials at http://nehe.gamedev.net they will be of great help to you. Also they show a better way to link libs

Jason Mickela
ICQ : 873518
E-Mail: jmickela@sbcglobal.net


Please excuse my spelling


-"I''m Cloister the Stupid" Lister (Red Dwarf)
"The paths of glory lead but to the grave." - Thomas GrayMy Stupid BlogMy Online Photo Gallery
Er, are you sure that your OpenGL headers are in your MSVC "include" folder, in a folder named "gl"? Do you have the OpenGL SDK installed? You can get it from OpenGL.org, I think. It will provide the header files, and you can put them in a folder in the "include" directory...

You are also using the extended Windows functions CreateWindowEx, RegisterClassEx, etc. I had problems with this, and had to use the non-extended functions (RegisterClass, CreateWindow), while using OpenGL anyway. This could be the same for your program. Try using the non-extended functions...

iNsAn1tY - the place where imagination and the real world merge...
Try http://uk.geocities.com/mentalmantle - Now updated!
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
quote:Original post by griffenjam
I would look at the tutorials at http://nehe.gamedev.net they will be of great help to you. Also they show a better way to link libs


Sure, you can do:

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

if you want.

- Mike
"The important thing to remember when programming is: When you're 90% complete, there's still 50% more to go."
Disable precompiled headers.
If brute force does not solve your problem....you're not using enough!

This topic is closed to new replies.

Advertisement