You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Visual Studio 2019中用GLFW 3.3.8创建C++窗口失败求助

GLFW窗口创建失败退出码-1的解决方法

刚安装了GLFW,正在测试创建窗口的示例项目,但无法正常运行。创建窗口时程序因窗口未创建而以-1状态退出,请问该如何解决?

编辑:已自行解决,将编译器改为x86并调整了部分代码。

示例代码如下:

#include <GL/glew.h>
#include <GLFW/glfw3.h>

#include <iostream>

int main(void)
{
    /* Initialize GLFW Library */
    if (!glfwInit()) {
        std::cout<<"ERROR: While initializing GLFW!"<<std::endl;
        exit(-1);
    }

    /* Create a windowed mode window and its OpenGL context */
    auto* window = glfwCreateWindow(640, 480, "Hello World", NULL, NULL);
    if (!window)
    {
        std::cout<<"ERROR: While creating Window Object!"<<std::endl;
        glfwTerminate();
        exit(-1);
    }

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

    /* Initialize GLEW Library */
    GLenum err = glewInit();
    if (err != GLEW_OK) {
        fprintf(stderr,"ERROR: %s\n", 
        glewGetErrorString(err));
        exit(-1);
    }
    fprintf(stdout,"Using GLEW %s\n", 
    glewGetString(GLEW_VERSION));

    //TODO: Create and compile shaders here (vertex and frament shaders)
    // and finally draw something with moder OpenGL!

    /* 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();
    exit(0);
}

内容的提问来源于stack exchange,提问作者Stupid Dev

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 10:40:25