GLFW程序编译良好但不运行

时间:2016-08-18 01:58:10

标签: c++ opengl

我编译了GLFW - Documentation的示例代码:

TotalAmt

我在windows 10下使用g ++编译器。

我编译了&使用以下命令链接它:

#include <glfw3.h>

int main(void)
{
    GLFWwindow* window;

    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        glfwTerminate();
        return -1;
    }

    /* Make the window's context current */
    glfwMakeContextCurrent(window);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        /* Render here */
        glClear(GL_COLOR_BUFFER_BIT);

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();
    }

    glfwTerminate();
    return 0;
}

该过程成功终止,但当我尝试执行g++ -I. example.cpp -oexample -lopengl32 -L. -lglfw3dll 文件时,它无效。

请提供任何帮助(我还尝试在源代码的开头添加exe#define GLFW_DLL,但它仍无效)

编辑:调试程序后,似乎未创建#include <windows.h>对象。

2 个答案:

答案 0 :(得分:0)

实际上问题是我的PC显卡不支持最新版本的openGL。我在支持openGL4的PC上执行了代码。 4,它运行良好!!

答案 1 :(得分:-1)

从我提供的代码中可以看出,您没有调用'glfwDefaultWindowHints()'来创建默认属性。有可能,没有指定那些,'GLFW_VISIBLE'标志被设置为false。另一种尝试是静态链接OpenGL库或使用GLEW。对于静态链接,我建议使用像Visual Studio,Code :: Blocks,XCode或您喜欢的任何IDE(我推荐Visual Studio for Windows)。有许多有用的tutorials用于为OpenGL设置IDE。