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

Author Topic: Sprites being draw to world coordinates instead of screen  (Read 2217 times)

0 Members and 1 Guest are viewing this topic.

evil_twinkie

  • Newbie
  • *
  • Posts: 7
    • View Profile
Sprites being draw to world coordinates instead of screen
« on: February 25, 2011, 11:39:13 pm »
I am working on a project that is used on both Macs and Linux machines.  

In linux, the program runs just fine.  I have a few sprites for a menu that are mapped to the screen coordinates and shows up correctly.  On a mac, this same program maps the sprites to the world coordinates instead of the screen coordinates, so there is a gigantic menu bar in the 3D space.  I've double checked to make sure I am pushing the gl_projection and gl_modelview matrices before I draw the sprites, and then pop them after (along with the other openGL cleanup stuff).

Is there a known bug or issue that I am not compensating for?  Can anyone point me to information on this problem?

Thanks

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprites being draw to world coordinates instead of screen
« Reply #1 on: February 26, 2011, 01:53:19 pm »
Can you show your code? It's not clear at all what you're doing, you're talking about sprites and OpenGL projection matrices... how do you mix them together?
Laurent Gomila - SFML developer

evil_twinkie

  • Newbie
  • *
  • Posts: 7
    • View Profile
Sprites being draw to world coordinates instead of screen
« Reply #2 on: February 28, 2011, 05:47:31 pm »
I am using both SFML (window, system, and graphics) and OpenGl. SFML for the windowing/menu and opengl for rendering the scene.  I can't really provide a small working example because the whole project is pretty split up.

Currently all I use opengl for is displaying a bunch of cubes:
Code: [Select]
void drawScene(){
  glBegin(GL_QUADS);
  {
    glVertex3f(...);
  ...
  }
}


I use shapes/sprites to draw the menu (this is just the background, but other parts are made similarly):
Code: [Select]
void createMenu(){
  sf::Shape fileMenuBackground;
  ...
}


Before and after I draw the menu (after I draw the scene of openGL cubes) I call these two functions:

Code: [Select]
void preSFML(){
glMatrixMode(GL_MODELVIEW);  glPushMatrix();
glMatrixMode(GL_PROJECTION); glPushMatrix();
glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT   | GL_ENABLE_BIT  |
GL_TEXTURE_BIT | GL_TRANSFORM_BIT | GL_VIEWPORT_BIT);

glDisable(GL_ALPHA_TEST);
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
}


Code: [Select]
void Gui::postSFML(){

glMatrixMode(GL_PROJECTION); glPopMatrix();
glMatrixMode(GL_MODELVIEW);  glPopMatrix();
glPopAttrib();
}


So it looks something like this:

Code: [Select]
drawScene();
preSFML();
     App->Draw(fileMenuBackground);
     ...
postSFML();


All of this runs just fine in linux.  The menu is properly drawn to the 2D screen coordinates and the cubes drawn to the 3D scene coordinates.  When I run this program on a mac, both the menu and the cubes are drawn to the 3D scene coordinates.  Hopefully this illustrates my problem a little bit better.  I am probably just be doing something wrong or have a misconception on how openGL works.  

What I was asking in my first post is if there is a known issue of why the menu is being drawn to the 3D coordinates.  Is there something I'm doing in the preSFML and postSFML functions that does not work properly on a mac?  Possibly anything else?  I appreciate the help.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprites being draw to world coordinates instead of screen
« Reply #3 on: February 28, 2011, 08:12:39 pm »
Try using window.PreserveOpenGLStates (once at init) instead of your own functions.

Another explanation could be a bug in the Mac OS X port, if it's working on Linux. Try testing on Windows if you can.
Laurent Gomila - SFML developer

evil_twinkie

  • Newbie
  • *
  • Posts: 7
    • View Profile
Sprites being draw to world coordinates instead of screen
« Reply #4 on: March 01, 2011, 01:08:26 am »
window.PreserveOpenGLStates seemed to work.  Is this because PreserveOpenGLStates works differently for mac than it does for linux?  I don't know why I didn't think about that...

Thanks for the help Laurent.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprites being draw to world coordinates instead of screen
« Reply #5 on: March 01, 2011, 07:46:23 am »
No it works the same. Maybe you forgot to save/restore a state in your own functions, and the behaviour depended on some default value, I don't know. Sometimes results can be different depending on the graphics driver.
Laurent Gomila - SFML developer

 

anything