使用 GLUT 将 OpenGL 窗口居中

发布于 2024-08-20 06:40:08 字数 906 浏览 3 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

定格我的天空 2024-08-27 06:40:08

另外,您可以单独使用 glut 来链接 user32.lib,而不是链接 user32.lib:

glutGet(GLUT_SCREEN_WIDTH) // returns Screen width

glutGet(GLUT_SCREEN_HEIGHT) // returns Screen height

当您可以跨平台时,为什么还要依赖 Windows

因此,您的代码将如下所示:

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

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);
暖阳 2024-08-27 06:40:08

您需要确保链接到静态库 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.

痴者 2024-08-27 06:40:08

首先
glutInitWindowSize(720, 720);

其次
glutInitWindowPosition(600, 200);

最后
glutCreateWindow("OpenGL 窗口");

Firstly:
glutInitWindowSize(720, 720);

Secondly:
glutInitWindowPosition(600, 200);

Finally:
glutCreateWindow("OpenGL Window");

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文