Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. Problem using a 3D engine with SFML and Qt
QtWS25 Last Chance

Problem using a 3D engine with SFML and Qt

Scheduled Pinned Locked Moved Game Development
3 Posts 2 Posters 4.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alejandro
    wrote on last edited by
    #1

    Hello to the community and thank you for at least reading the topic.

    Skip next paragraph if you want to go to the problem.

    Without trying to explain why I have chosen this combination, I would like to say that I am very satisfied with what "SFML":http://www.sfml-dev.org/ (based on OpenGL) does with 2D graphics and I use Qt for everything else since it is a great project and offers pretty much everything else a game developer might need in one consistently improving package. Recently I found a project which implements 3D graphics on top of SFML, but I'm having some problems making it work as it should within a Qt widget.

    Basically what I do is setup an SFML widget based on this "tutorial":http://www.sfml-dev.org/tutorials/1.6/graphics-qt.php and then "link" the 3D engine to that widget (as it requires an SFML rendering window for drawing). In the update method (which is used for drawing calls) I put the engine specific code for setting up the 3D and 2D drawings of the scene and here is where the problem occurs. The engine has 2 calls that should be done before rendering anything D and they're called prepareDView. What I do is something like:
    @
    context->Prepare2DView();
    context->Render(_2DSprite);
    context->Prepare3DView();
    context->Render(_3DObject);
    @
    But this doesn't render the 3D object at all. If I use this:
    @
    context->Render(_3DObject);
    context->Prepare2DView();
    context->Render(_2DSprite);
    context->Prepare3DView();
    @
    however the 3D object is rendered underneath the 2D sprite as it should. Another thing is that if I want to draw something 2D I have to make a prepare3D call after that If I want to make it appear on the screen like so:
    @
    context->Prepare2DView();
    context->Render(_2DSprite);
    context->Prepare3DView();
    @

    My guess is that for 3D some OpenGL states, or whatever they are, or something else needs to be set and since SFML doesn't create the window by itself, they don't get initialized by the Qt widget. I've tried setting the SFML context to active and whatnot to be sure that OpenGL renders to the right context, but to no avail. (I've also tried using the GL widget but following the example's code I couldn't even get it to render a 2D drawing from those libraries)

    Just to mention so that there aren't any confusions, there is nothing wrong with SFML or the engine as if I try the exact same code, without integrating SFML into a Qt widget it works perfectly as it should.

    If this information isn't enough (which is likely true) to help pinpoint what might be wrong, I would be more than happy to provide a simple project source code + the libraries if that would help anyone interested solve the problem.

    Thank you for your time,

    Alejandro

    1 Reply Last reply
    0
    • C Offline
      C Offline
      coyotte508
      wrote on last edited by
      #2

      Did you try:

      App.PreserveOpenGLStates(true);

      Where App is your SFML rendering window?

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alejandro
        wrote on last edited by
        #3

        Since I am using SFML 2 this is a deprecated function so I cannot use it, but I have used it's equivalent - Save/Restore GLStates but to no avail.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved