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

Author Topic: sf::View with OpenGL on top  (Read 2658 times)

0 Members and 1 Guest are viewing this topic.

Halsys

  • Jr. Member
  • **
  • Posts: 66
  • Halsys like Hal.sys
    • View Profile
    • Email
sf::View with OpenGL on top
« on: January 07, 2013, 10:10:29 am »
I'm setting up Box2D with my game still and I need the DebugDraw stuff on top (of SFML) to see whats going on under the hood. In my game the sf::View Camera fallows the player but doesn't move with the OpenGL stuff... I expected that but is there a way to cheaply fix it to where I can move all this OpenGL geometry to be lined up with the Camera as a whole? I could code all the DebugDraw stuff to use SFML instead but I did a lot of work for this so far. Any help on this would be awesome. :)

If you notice I put "....", in my sentences way too much... I'm sorry.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::View with OpenGL on top
« Reply #1 on: January 07, 2013, 10:37:46 am »
Get the view's matrix and set it as your OpenGL projection matrix.
Laurent Gomila - SFML developer

Halsys

  • Jr. Member
  • **
  • Posts: 66
  • Halsys like Hal.sys
    • View Profile
    • Email
Re: sf::View with OpenGL on top
« Reply #2 on: January 07, 2013, 01:11:13 pm »
I looked at glulookat(Which removed the geometry or moved it out of view) and I think that would have worked if I wasn't so tired from working on this. Sounds like I'm going to have to man up and code the DebugDraw in SFML... Which I thought about first but I figured out I could copy/paste the testbed draw stuff and modified it to my scale for the screen and objects of SFML. I'll work on this tomorrow(later today) but if you or anyone else found/finds/knows a fix for it, I'd be grateful.

I also thought about adding the cameras position to each OpenGL point as a offset, for an illusion of a camera... Which might be a mess of code in the end... It might work... It might also be very inaccurate.

Also a simple 3D camera would be a nice feature for SFML, Maybe with some fancy 3D stuff like triangles and quads... Considering that the OpenGL camera is really hard to work with.... Makes me want to use DirectX. :/
If you notice I put "....", in my sentences way too much... I'm sorry.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: sf::View with OpenGL on top
« Reply #3 on: January 07, 2013, 01:37:34 pm »
You must do this:
glMatrixMode(GL_PROJECTION);
glLoadMatrixf(m_view.getTransform().getMatrix());

Quote
Also a simple 3D camera would be a nice feature for SFML, Maybe with some fancy 3D stuff like triangles and quads...
I'm not planning to add a 3D module to SFML.

Quote
Considering that the OpenGL camera is really hard to work with.... Makes me want to use DirectX. :/
It's not hard to work with. It's just a set of transformations. And 2D cameras are even easier to work with, there's no perspective stuff.
And DirectX handles cameras the exact same way; in the end it's just a 4x4 matrix.
Laurent Gomila - SFML developer

Halsys

  • Jr. Member
  • **
  • Posts: 66
  • Halsys like Hal.sys
    • View Profile
    • Email
Re: sf::View with OpenGL on top
« Reply #4 on: January 08, 2013, 07:53:23 am »
Thanks for helping me on that. The code you gave me and the window pushGL/pullGL got it working. Now I can continue working on the game and work on more complicated stuff with DebugDraw. Sorry for taking your time and thanks again! :)

And for the "No" on the 3D module, Sorry for sounding lazy. Also what I said about DirectX, That's what I used first before SFML... I switched to this because I felt like DirectX lacked a lot of things I wanted... Being cross platform was one of them.

Anyway, Thanks.
If you notice I put "....", in my sentences way too much... I'm sorry.