opengl - GLFW - 无法打开窗口

标签 opengl window glfw

在我寻找跨平台框架/库的过程中,GLFW 被多次提及。所以,我决定尝试一下。现在,似乎我什至无法启动窗口。 :-/

#include 
#include 
#include 

int main(int argc, char *argv[])
{
    int running = GL_TRUE;
    srand(time(NULL));

    if (!glfwInit())
        exit(EXIT_FAILURE);

    if (!glfwOpenWindow(300, 300, 0, 0, 0, 0, 0, 0, GLFW_WINDOW))
    {
        glfwTerminate();
        exit(EXIT_FAILURE);
    }

    while (running)
    {
        glClear(GL_COLOR_BUFFER_BIT);
        glClearColor(rand() % 255 + 1, rand() % 255 + 1, rand() % 255 + 1, 0);

        glfwSwapBuffers();

        running = !glfwGetKey(GLFW_KEY_ESC) && glfwGetWindowParam(GLFW_OPENED);
    }

    glfwTerminate();

    exit(EXIT_SUCCESS);
}

I typed this in MVC++ 2010, linked the header, and 2 lib files (and it had 1 DLL file, so I threw that into the SysWOW64 folder), and I get these errors:

1>------ Build started: Project: glfwTest, Configuration: Debug Win32 ------
1> test.cpp
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(8): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>c:\users\andrew\documents\visual studio 2010\projects\glfwtest\glfwtest\test.cpp(22): warning C4244: 'argument' : conversion from 'int' to 'GLclampf', possible loss of data
1>test.obj : error LNK2019: unresolved external symbol __imp__glClearColor@16 referenced in function _main
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClearColor@16
1>test.obj : error LNK2019: unresolved external symbol __imp__glClear@4 referenced in function _main
1>GLFW.lib(window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp__glClear@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglGetProcAddress@4 referenced in function _initWGLExtensions
1>GLFW.lib(win32_glext.obj) : error LNK2001: unresolved external symbol __imp__wglGetProcAddress@4
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglMakeCurrent@8 referenced in function _createWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglCreateContext@4 referenced in function _createContext
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__wglDeleteContext@4 referenced in function _destroyWindow
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetFloatv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(win32_window.obj) : error LNK2019: unresolved external symbol __imp__glGetIntegerv@8 referenced in function __glfwPlatformSetWindowSize
1>GLFW.lib(glext.obj) : error LNK2001: unresolved external symbol __imp__glGetIntegerv@8
1>GLFW.lib(glext.obj) : error LNK2019: unresolved external symbol __imp__glGetString@4 referenced in function __glfwParseGLVersion
1>c:\users\andrew\documents\visual studio 2010\Projects\glfwTest\Debug\glfwTest.exe : fatal error LNK1120: 9 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

我理解前几个随机颜色,但后面的对我来说毫无意义。知道这有什么问题吗?

我很确定我已经正确链接了库。我将它们放入 C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib 目录 甚至将它们链接到我的 C:\SDK\GLFW\glfw-2.7.bin.WIN32\lib-msvc100\debug 目录。

GLFW 包是一个 .zip 文件,所以我只是将其解压缩到我的默认 SDK 文件夹(用于我的所有 API 和其他内容)。所以 C:\SDK\GLFW 是我的 GLFW 默认值。

最佳答案

您需要链接到opengl32.lib

为此,如下图所示,转到项目设置,然后链接器>输入>附加依赖项并在那里添加opengl32.lib(使用 ; 分隔不同的库)。

请注意,您实际上不需要在任何地方都有 opengl32.lib 文件。 Visual Studio 知道在哪里可以找到它。

Linking to extra libs in Visual Studio

编辑:我应该注意,除了添加 opengl32.lib 之外,您不需要执行任何操作。其他的东西就无关紧要了。此外,如果两者都存在,请尝试交换顺序,这在某些情况下很重要。

关于opengl - GLFW - 无法打开窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5643172/

相关文章:

c++ - 我可以在不使用全局变量的情况下将信息传递给函数指针回调吗?

c++ - 使用 SDL_Renderer 绘制 2D 内容,使用 SDL_GLContext 绘制 OpenGL 内容

c++ - OpenGL 透视相机

c++ - 简单的 openGL 程序无法通过编译

c++ - 在 Mac OS X 10.9 中使用 GLFW 创建 OpenGL 3.3 上下文

c++ - 需要以合理的精度创建自定义数据 2D 纹理

c++ - 在 openGL 中使用透视

ios - 为什么我在 iOS 上设置窗口背景颜色时蒙版的背景颜色会发生变化?

javascript - 不理解 $(window).width() 的结果

c++ - 在 Qt 中更改 show() 上的窗口位置