【问题标题】:Why does SFML with an Opengl 3.0 context draw twice?为什么带有 Opengl 3.0 上下文的 SFML 会绘制两次?
【发布时间】:2013-04-06 07:07:33
【问题描述】:

我一直在开发一个使用 SFML 进行上下文创建和 OpenGL 3.0 的 3D 应用程序。出于某种原因,当我尝试使用 OpenGL 3.0 创建上下文时,它似乎将图像绘制得稍微变窄并加倍,中间有一个黑条,并且由于某种原因,屏幕似乎被绿色而不是红色清除了。如果我将上下文更改为 2.1,它会正常绘制。最初我在使用现代 OpenGL 代码时遇到了这个问题,但我提供了一个使用固定函数管道的示例,这样问题就更清楚了。

#include <SFML/Window.hpp>
#include <SFML/OpenGL.hpp>

int main()
{
    // create the window
    sf::ContextSettings settings;
    settings.depthBits = 24;
    settings.stencilBits = 8;
    settings.antialiasingLevel = 4;
    settings.majorVersion = 3;
    settings.minorVersion = 0;

sf::Window window(sf::VideoMode(800, 600), "OpenGL", sf::Style::Default, settings);

// load resources, initialize the OpenGL states, ...
glClearColor(1.0, 0.0, 0.0, 1.0);

// run the main loop
bool running = true;
while (running)
{
    // handle events
    sf::Event event;
    while (window.pollEvent(event))
    {
        if (event.type == sf::Event::Closed)
        {
            // end the program
            running = false;
        }
    }

    // clear the buffers
    glClear(GL_COLOR_BUFFER_BIT);

    // draw...
    glBegin(GL_TRIANGLES);
    glVertex3f( 0.0, 1.0, 0.0);
    glVertex3f(-1.0,-1.0, 0.0);
    glVertex3f( 1.0,-1.0, 0.0);
    glEnd();

    // end the current frame (internally swaps the front and back buffers)
    window.display();
}

return 0;
}

如果我改变这两行:

   settings.majorVersion = 3;
   settings.minorVersion = 0;

致这些:

   settings.majorVersion = 2;
   settings.minorVersion = 1;

窗口正常绘制。

这里是正在发生的事情的屏幕截图。

第二张图片有点乱,因为我的电脑滞后。它不应该有那种橙色的色调。

我的设置是:

Ubuntu 12.10 英特尔 i7-3630QM 英特尔核芯显卡 4000

来自 glxinfo: OpenGL 渲染器字符串:Mesa DRI Intel(R) Ivybridge Mobile OpenGL 版本字符串:3.0 Mesa 9.0.2 OpenGL着色语言版本字符串:1.30

来自 lspci: 正在使用的内核驱动程序:i915

我认为这可能是驱动程序问题,但我已经成功地使用 GLUT 运行 OpenGL 3.0 程序并且没有弃用的功能,因此它一定是在创建有效的 OpenGL 3.0 上下文并正常工作。

我很困惑为什么会这样。

【问题讨论】:

  • 尝试在您的绘图函数上方粘贴一个 window.setActive()。
  • 它是否适用于英特尔的 Windows 驱动程序?
  • 最有趣的。 glBegin/glEnd 在 3.0 规范中肯定已被弃用,但并未从中删除。我认为您的代码没有问题。一定是驱动程序错误。

标签: opengl 3d sfml opengl-3


【解决方案1】:

SFML 使用兼容性上下文,因为在内部它仍然有一些旧样式的 opengl。您可以使用 glBegin 和 glEnd 等的原因是因为兼容性上下文。我没有你的问题的答案,但它是在一年前提出的。如果您有解决方案,请发布。

【讨论】:

    猜你喜欢
    • 2012-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-05
    • 2013-05-27
    • 1970-01-01
    • 2017-12-03
    相关资源
    最近更新 更多