使用 GLUT 将 OpenGL 窗口居中
我有一个 640x480 的 openGL 窗口,我需要将其置于屏幕中央。我以前用过:
glutInitWindowPosition((GetSystemMetrics(SM_CXSCREEN)-640)/2,
(GetSystemMetrics(SM_CYSCREEN)-480)/2);
哪个有效。
但现在当我编译时突然...
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
请有人帮忙。这对我来说非常烦人和令人沮丧,因为我对 OpenGL 和 GLUT 知之甚少。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
另外,您可以单独使用 glut 来链接 user32.lib,而不是链接 user32.lib:
?
当您可以跨平台时,为什么还要依赖 Windows
因此,您的代码将如下所示:
Also, instead of linking user32.lib you can do it solely using glut:
and
Why depend on Windows when you can be cross-platform?
Hence, your code would look:
您需要确保链接到静态库 User32.lib,其中
GetSystemMetrics()
。打开项目设置并确保 User32.lib 列在您要链接的所有 .lib 中。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.首先:
glutInitWindowSize(720, 720);
其次:
glutInitWindowPosition(600, 200);
最后:
glutCreateWindow("OpenGL 窗口");
Firstly:
glutInitWindowSize(720, 720);
Secondly:
glutInitWindowPosition(600, 200);
Finally:
glutCreateWindow("OpenGL Window");