【发布时间】:2017-12-18 16:32:13
【问题描述】:
这是我的代码:
// 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
(还没开始写makefile)
这会生成一个名为 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
这确实会创建一个黑色窗口(如预期的那样),但我怀疑一旦我开始使用 SFML/Graphics.hpp 中的绘图功能,它就会出现段错误,因为当我尝试编译示例文件时发生了这种情况(它打印了相同的错误以及)。
当我创建 sf::ContextSettings 时,我将其设置为 attributeFlags 到 sf::ContextSettings::Default,因此据我了解,它应该创建一个兼容性上下文(因为 SFML 使用一些遗留代码,这是必须的)。
附:如果重要的话,我在 Void Linux 上,我从 repos 安装了我在此处使用的所有内容的最新版本
【问题讨论】:
-
给我们看看你的实际源代码怎么样?
-
代码进入问题in。 不在站外链接后面。它应该以 text 的形式发布,并且应该是 minimal reproducible example.
-
我们不发布整个代码,只是初始化部分。
-
你们去吧伙计们,我认为这已经足够了
-
您使用的是什么显示驱动程序/OpenGL 实现?如果你使用 Mesa,它只支持 Core Profile。