Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: I want to draw my mesh by using texture of SFML without using sf::window and...  (Read 1779 times)

0 Members and 2 Guests are viewing this topic.

mr.ao

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
I want to draw my mesh by using  texture of SFML without using from (sf::window ,sf::Renderwindow....)
    sf::RenderTexture renderTexture;
    renderTexture.create(800,600);
    renderTexture.clear(sf::Color::Blue);

    sf::Text text;
    // select the font
    sf::Font font;
    if (!font.loadFromFile("BNazanin.ttf"))
    {
        // error...
    }
    text.setFont(font); // font is a sf::Font
    // set the string to display
    text.setString("hello");
    // set the character size
    text.setCharacterSize(40); // in pixels, not points!
    // set the color
    text.setColor(sf::Color::Red);
    // set the text style
    text.setStyle(sf::Text::Bold | sf::Text::Underlined);

    renderTexture.draw(text); // or any other drawable
    renderTexture.display();

    //renderTexture.getTexture().copyToImage().saveToFile("test.png");
    const sf::Texture& texture = renderTexture.getTexture()

   sf::Texture::bind(&texture);

  _shaderProgram->bind();
  _shaderProgram->setUniformValue("modelInWorldMatrix", _model2WorldMatrix);
  glFlush();
  QOpenGLContext::currentContext()->functions()->glDrawArrays(_mode, startVertex, std::min(vertexCount, verticesCount()));;

it save texture correctly, but when i use binded texture for drawing my mesh in Qt Scene, it Doesn't work!
« Last Edit: December 25, 2017, 11:17:02 am by mr.ao »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
"Doesn't work" is not really a problem description.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

mr.ao

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
sorry @eXpl0it3r, My description was not enough!
I think my Opengl context is differ from sf::RenderTexture and I can not bind sf::Texture of RenderTexture to my mesh.

I maked a program for drawing mesh in video every frame in Qt by Opengl,  I binded texure and draw mesh correctly, but when I change texture (with SFML::Texture in above code), it didn't work.(I didn't use from sf::window and ...)
« Last Edit: December 25, 2017, 11:34:37 am by mr.ao »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
I have no experience with this cross-context sharing. Personally, I don't see a reason to use SFML in this situation, since you just want to use Qt, you may as well stick to it. Otherwise, there's also some Qt widget out there that use sf::Window and should make it easier to work in combination with SFML.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything