Question

I have an openGL window that is 640x480 that I need to center in the middle of the screen. I previously used:

glutInitWindowPosition((GetSystemMetrics(SM_CXSCREEN)-640)/2,
                       (GetSystemMetrics(SM_CYSCREEN)-480)/2);

which WORKED.

But now all of a sudden when I compile...

Linking...
1>Project1.obj : error LNK2028: unresolved token (0A000372) "extern "C" int __stdcall GetSystemMetrics(int)" (?GetSystemMetrics@@$$J14YGHH@Z) referenced in function "int __cdecl main(int,char * *)" (?main@@$$HYAHHPAPAD@Z)
1>Project1.obj : error LNK2019: unresolved external symbol "extern "C" int __stdcall GetSystemMetrics(int)" (?GetSystemMetrics@@$$J14YGHH@Z) referenced in function "int __cdecl main(int,char * *)" (?main@@$$HYAHHPAPAD@Z)
1>C:\Users\My Computer\Documents\School Stuff\CS445\Project1\Debug\Project1.exe : fatal error LNK1120: 2 unresolved externals

Someone please help. This is very annoying and frustrating for me as I don't know a lot about OpenGL and GLUT.

Was it helpful?

Solution

Also, instead of linking user32.lib you can do it solely using glut:

glutGet(GLUT_SCREEN_WIDTH) // returns Screen width

and

glutGet(GLUT_SCREEN_HEIGHT) // returns Screen height

Why depend on Windows when you can be cross-platform?

Hence, your code would look:

glutInitWindowPosition((glutGet(GLUT_SCREEN_WIDTH)-640)/2,
                       (glutGet(GLUT_SCREEN_HEIGHT)-480)/2);

OTHER TIPS

You need to make sure you're linking against User32.lib, the static library where GetSystemMetrics() is defined. Open up your project settings and make sure the User32.lib is listed among all of the .libs that you're linking against.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top