程序问答   发布时间:2022-06-01  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败?

开发过程中遇到SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败的问题如何解决?下面主要结合日常开发的经验,给出你关于SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败的解决方法建议,希望对你解决SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败有所启发或帮助;

我正在尝试在 SFML 中创建一个包含字符串和 RectangeShape 的 button 类。当我实例化它并在我的 main 中调用它时,button 类本身实际上工作正常,但我想为我想要的特定项目创建一个按钮链接列表。这是当我遇到一个奇怪的错误时:

An internal OpenGL call Failed in Texture.cpp(98).
Expression:
   glFlush()
Error description:
   GL_INVALID_OPERATION
   The specifIEd operation is not allowed in the current state.

我已将此错误范围缩小为在使用 setFont() 函数或我的 DoublylinkedList 类的 append() 函数时发生。我的字体是我的按钮类的成员变量,所以它不会被破坏。我已经在下面粘贴了我的代码的重要部分,如果您要使用相同的东西,您应该会遇到相同的错误。谁能让我更深入地了解这个错误?我在网上查过,但没有多少清晰的搜索结果出现。

按钮.h:

class button : public sf::Drawable,public sf::transformable
{
public:
    button();
    button(String text,sf::Vector2f position,int charSizE);
    virtual voID draw(sf::rendertarget &window,sf::renderStates statE) const;
private:
    sf::Font Font;
    sf::Text name;
    sf::rectangleShape Box;
};

button.cpp:

button::button() {}

button::button(String text,int charSizE)
{
    float padding = 30;

    if (!Font.loadFromfile("../ParkLaneNF.ttf"))
        cout << "Error loading Font file." << endl;
    name.setFont(Font);
    name.setString(text);
    name.setposition(position.x + padding,position.y);
    name.setCharacterSize(charSizE);

    sf::floatRect bounds = name.getLocalBounds();
    Box.setSize({Bounds.wIDth + 2 * padding,bounds.height + 2 * padding});
    Box.setposition(position);
    Box.setFillcolor(sf::color::Green);
}

voID button::draw(sf::rendertarget &window,sf::renderStates statE) const
{
    window.draw(BoX);
    window.draw(Name);
}

(部分)DoublylinkedList 类:

DoublylinkedList<T>::DoublylinkedList() : head(nullptr),tail(nullptr) {}

voID DoublylinkedList<T>::append(T value)
{
    Node<T>* temp = new Node<T>;
    temp->data = value;
    temp->next = nullptr;

    if (empty())
    {
        head = temp;
        temp->prev = nullptr;
    }
    else
    {
        tail->next = temp;
        temp->prev = tail;
    }
    tail = temp;
}

主要功能:

int main()
{
    DoublylinkedList<button> buttons;
    button btn("Hello",{0,0},100);
    buttons.append(btn);

    sf::renderWindow window(sf::VIDeoMode(1920,1080,32),"button");
    window.setFrameratelimit(60);

    while(window.isopen())
    {
        sf::Event event;
        while(window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed) window.close();
        }
        window.clear();
        window.draw(btn);
        for (int i = 0; i < buttons.size(); i++)
            window.draw(buttons.getAt(i));
        window.display();
    }
}

解决方法

glFlush() 返回 GL_INVALID_OPERATION 的唯一情况是它在 glBeginglEnd 之间执行

大佬总结

以上是大佬教程为你收集整理的SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败全部内容,希望文章能够帮你解决SFML 中按钮的 LinkedList 获取错误:Texture.cpp(98) 中的内部 OpenGL 调用失败所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。