SFML community forums
Help => Graphics => Topic started by: evil_twinkie 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
-
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?
-
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:
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):
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:
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);
}
void Gui::postSFML(){
glMatrixMode(GL_PROJECTION); glPopMatrix();
glMatrixMode(GL_MODELVIEW); glPopMatrix();
glPopAttrib();
}
So it looks something like this:
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.
-
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.
-
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.
-
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.