SFML OpenGL:如何同时与他们一起工作
SFML+OpenGL: How to work with them at the same time?
我尝试将SFML OpenGL一起使用,但我不明白。在教程中,我写的是我使用 window.setActive(false(。
我的代码:
#include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream>
#include <sstream>
#include <math.h>
using namespace std;
int main()
{
sf::RenderWindow window(sf::VideoMode(640, 480), "SFML works!");
sf::FloatRect frect;
sf::Font font;
font.loadFromFile("PaPYRUS.ttf");
int z=45;
int x=0, y=0;
stringstream l;
l<<z;
cout<<l.str()<<endl;
string s="Lololololooooooooooooooooooooooooo0000000000oooooooooonlololololol "+l.str()+" lololo";
sf::Text text(s, font, 20);
text.setPosition(20, 40);
frect=text.getGlobalBounds();
cout<<frect.height<<" "<<frect.left<<" "<<frect.top<<" "<<frect.width;
bool running=true;
int x2=0, y2=0;
sf::CircleShape shape(30);
shape.setFillColor(sf::Color::Green);
while (running)
{
sf::Event event;
while (window.pollEvent(event))
{
x2+=2;
y2++;
shape.setPosition(x2, y2);
if (event.type == sf::Event::Closed)
running=false;
}
// From that place problems begin
window.setActive(true);
glClearColor(0.0f, 0.0f, 0.1f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
window.setActive(false);
window.draw(shape);
window.draw(text);
window.setActive(true);
glColor3f(1.0f, 0.0f, 0.1f);
glBegin(GL_POLYGON);
for (float i = 0; i<2 * 3.14; i += float(3.14 / 4))
{
glVertex2f(20 + 5*sinf(i), 40 + 6*cosf(i));
}
window.setActive(false);
window.display();
}
return 0;
}
当我用圆圈的绘制评论OpenGL部分时,一切都可以。我将window.setactive(false(放在其他代码的地方,但它不起作用。
错误:"无法激活窗口的上下文"无法停用openGL上下文:a
请,如果可以的话,请显示如何正确制定此代码。
pushGLStates
和 popGLStates
是您应该使用的。根据教程,您需要在使用SFML图形模块绘制之前推动状态,然后在完成后弹出状态,并希望返回使用RAW OPENGL:
glDraw...
window.pushGLStates();
window.draw(...);
window.popGLStates();
glDraw...
如果您仍然遇到麻烦,则可以用来验证来源的示例,没有更严重的问题
相关文章:
- 将数组作为参数传递给函数安全吗?作为第三方职能部门,可以探索他们想要的之外的其他元素
- 如何将enable-if与模板参数和参数包一起使用
- 如何将PERF_AMPLE_READ与mmap一起使用
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将C++中的库和头与MinGW一起使用
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 为什么我不能将 rand() 与数组的大小一起使用?
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 不能将复制初始化与隐式转换的多个步骤一起使用
- 将fold表达式与std::一起用于两个元组
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- 将 std::allocate_shared 与多态资源分配器一起使用
- 即使没有满足他们的条件,我也无法通过一些 do-while 循环
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 将 exprtk 与自定义类的对象一起使用
- 将 std::set 与基于键的比较器一起使用
- 将 C++ 类与 Rcpp 一起使用,从 C 或 R 修改它
- 如何将 Eigen::Ref 与 pybind11 一起使用?
- SFML OpenGL:如何同时与他们一起工作