当要求兼容性时,核心OpenGL上下文?



这是我的代码:

// Display.cpp
#include <memory>
#include <SFML/Graphics.hpp>
#include <GL/glew.h>
namespace Display
{
constexpr static int WIDTH  = 1280; constexpr static int HEIGHT = 720;
std::unique_ptr<sf::RenderWindow> window;
void init() {
sf::ContextSettings settings;
settings.depthBits = 24;
settings.majorVersion = 3;
settings.minorVersion = 3; // OpenGL 3.3
settings.attributeFlags = sf::ContextSettings::Default;
window = std::make_unique<sf::RenderWindow>(sf::VideoMode(WIDTH, HEIGHT),
"Fcku",
sf::Style::Close,
settings);
glewInit();
glViewport(0, 0, WIDTH, HEIGHT);
}
void close() {
window->close();     
}
void clear() {
glClearColor(0.0, 0.0, 0.0, 0.0);
glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
}
void update() {
window->display();
}
void checkForClose() {
sf::Event e;
while (window->pollEvent(e))
if (e.type == sf::Event::Closed) close();
}
bool isOpen() {
return window->isOpen();
}
} // namespace Display
int main()
{
Display::init();
while (Display::isOpen()) {
Display::clear();
Display::update();
Display::checkForClose();
}
return 0;
}

我像这样编译上述文件:

g++ Display.cpp -Wall -O2 --std=c++14 -fexceptions -o test.o -lsfml-graphics -lsfml-audio -lsfml-network -lsfml-window -lsfml-system -lGL -lGLU -lGLEW -DGLEW_STATIC

(还没有开始编写生成文件(

这将生成一个名为test的二进制文件,但当我运行它时,我收到以下警告:

Warning: The created OpenGL context does not fully meet the settings that were requested
Requested: version = 4.1 ; depth bits = 24 ; stencil bits = 0 ; AA level = 0 ; core = false ; debug = false ; sRGB = false
Created: version = 3.3 ; depth bits = 24 ; stencil bits = 0 ; AA level = 0 ; core = true ; debug = false ; sRGB = false

这确实创建了一个黑色窗口(如预期的那样(,但我怀疑一旦我开始使用 Drawing 函数SFML/Graphics.hpp它就会出现段错误,因为当我尝试编译示例文件时就会发生这种情况(它也打印了相同的错误(。

当我创建sf::ContextSettings时,我将其设置为attributeFlagssf::ContextSettings::Default因此根据我的理解,它应该创建一个兼容性上下文(因为 SFML 使用一些遗留代码,这是必须的(。

附言如果这很重要,我在 Void Linux 上,我从存储库中安装了我在这里使用的所有内容的最新版本

好的,似乎解决方案是使用 OpenGL 3.0 而不是 3.3,后者确实支持兼容性配置文件。但是现在我不能使用GLSL 3.30,这是一个很大的混乱,所以我会尝试SDL2,GLFW和Raylib。

最新更新