C++ 无法初始化 GLEW。缺少 GL 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14276444/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 18:11:07  来源:igfitidea点击:

Failed to Initialize GLEW. Missing GL version

c++openglqt-creatorsfmlglew

提问by Bugster

I've tried to set up SFML 2.0 with the latest version of the qt creator, I've set up SFML right and I imported a small game I wrote in visual studio. Upon compilation, I get this:

我尝试使用最新版本的qt creator 设置SFML 2.0,我已经正确设置了SFML并导入了我在visual studio中编写的小游戏。编译后,我得到这个:

enter image description here

在此处输入图片说明

What I tried

我试过的

  • Reinstalling the entire qt SDK and qt creator IDE from scratch
  • Reinstalling SFML
  • reinstalling mingw
  • I tried to write a simple program to make sure it's not my code, the program compiles correctly but when I close the application, I get OpenGL errors which is not normal
  • I tried posting a thread on the SFML forums but to no avail.
  • Googling the errors shows a few results, which are specific to OpenGL, and which are too localized, they don't apply to me, no answer for this happening in SFML 2.0
  • 从头开始重新安装整个 qt SDK 和 qt creator IDE
  • 重新安装 SFML
  • 重新安装mingw
  • 我试图编写一个简单的程序来确保它不是我的代码,程序编译正确,但是当我关闭应用程序时,我收到了不正常的 OpenGL 错误
  • 我尝试在 SFML 论坛上发帖,但无济于事。
  • 谷歌搜索错误显示了一些结果,这些结果是特定于 OpenGL 的,并且过于本地化,它们不适用于我,SFML 2.0 中发生这种情况没有答案

Additional details

额外细节

  • I'm running windows XP SP3, latest version of mingw and qt SDK and SFML

  • The code I'm trying to work with works without any errors or even warningson Visual Studio 2010 andCode::Blocks

  • Yes, I am sure that SFML is set up on my IDE, basic code works but shows those errors and more advanced code shows all sprites and text as boxes.
  • I did not compile SFML myself

  • My gcc version is 4.6.2

  • My gcc is a DW2 one

  • 我正在运行 Windows XP SP3,最新版本的 mingw 和 qt SDK 以及 SFML

  • 我正在尝试使用的代码在 Visual Studio 2010Code::Blocks上没有任何错误甚至警告

  • 是的,我确信在我的 IDE 上设置了 SFML,基本代码可以工作但会显示这些错误,更高级的代码将所有精灵和文本显示为框。
  • 我没有自己编译 SFML

  • 我的 gcc 版本是 4.6.2

  • 我的 gcc 是 DW2 的

I'm getting no results, I don't even know how to remotely get close to fixing this, not even where to start.

我没有得到任何结果,我什至不知道如何远程解决这个问题,甚至不知道从哪里开始。

EDITI can't show you all of my code, it's over 20 files and I'm almost 90% sure it's not my code, I've said it above: I can run this code without any warnings or even errors on any IDE except qt creator.

编辑我无法向您展示我的所有代码,它有超过 20 个文件,我几乎 90% 确定这不是我的代码,我上面已经说过:我可以在任何 IDE 上运行此代码而不会出现任何警告甚至错误除了 qt 创建者。

回答by Quentin Perez

It's because you are not initializing OpenGL. Example with the lib glut.

这是因为您没有初始化 OpenGL。lib 过剩的例子。

Wrong:

错误的:

 glewInit();  // ERROR MISSING GL VERSION
 glutInitDisplayMode(GLUT_RGB); 

Good:

好的:

 glutInitDisplayMode(GLUT_RGB);
 glewInit();

EDITI think for SFML:

编辑我认为SFML:

 sf::Window   App(sf::VideoMode(400, 400, 32), "Window");
 glewInit();

EDIT 2Test this code.

编辑 2测试此代码。

#include <SFML/Window.hpp>
#include <iostream>
#include <GL/glew.h>

int
main(int, const char**)
{
    GLenum      err;

    std::cout << "Start" << std::endl;
    std::cout << "Test 1" << std::endl;
    if ((err = glewInit()) != GLEW_OK)
        std::cout << glewGetErrorString(err) << std::endl;

    std::cout << "Init window" << std::endl;
    sf::Window  app(sf::VideoMode(400, 400, 32), "Windows");

    std::cout << "Test 2" << std::endl;
    if ((err = glewInit()) != GLEW_OK)
        std::cout << glewGetErrorString(err) << std::endl;
    std::cout << "End" << std::endl;
    return 0;
}

My output:

我的输出:

Start
Test 1
Missing GL version
Init window
Test 2
End

Compile with: g++ -W -Wall -Werror main.cpp -lsfml-window -lGLEW

编译: g++ -W -Wall -Werror main.cpp -lsfml-window -lGLEW

Good Luck ;)

祝你好运 ;)

回答by Syler

At the request of user3648895, I am posting my answer outside of the comments separately.

应用户 3648895 的要求,我将我的回答单独发布在评论之外。

For those using GLFW instead of SFML, you need to call glewInit() after glfwMakeContextCurrent

对于那些使用 GLFW 而不是 SFML 的,你需要在 glfwMakeContextCurrent 之后调用 glewInit()

回答by Telhar

If you're using glew with glfw, use glfwMakeContextCurrent(https://github.com/Cloudef/glhck/issues/15)

如果您在 glfw 中使用 glew,请使用glfwMakeContextCurrenthttps://github.com/Cloudef/glhck/issues/15

回答by linkin

putting the glewInit(); after the sf::window creation that solves my problem for using glew with sfml

把glewInit(); 在 sf::window 创建解决了我在 sfml 中使用 glew 的问题之后

回答by Codecat

For those using SDL2's Renderer functions, it needs to be right after SDL_CreateRenderer.

对于那些使用 SDL2 的 Renderer 功能的人来说,它需要紧跟在SDL_CreateRenderer.