42
« on: March 08, 2009, 08:32:57 pm »
I'm trying to create a breakout clone and i'm having problems on mac os x.
I'm calculating a mouse position delta and then using SetCursor pos to position the mouse at the center of the screen. The problem is that i'm getting some stuttering, on mac os x. The PAD moves slow and with big increments in position. Here is some code to replicate the issue:
Edit:
Also with the same code there aren't any problems on windows.
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp>
#pragma comment(lib,"sfml-graphics-s-d.lib")
#pragma comment(lib,"sfml-window-s-d.lib")
#pragma comment(lib,"sfml-system-s-d.lib")
#pragma comment(lib,"opengl32.lib")
#pragma comment(lib,"glu32.lib")
void Cleanup()
{
}
int main()
{
// Create the main window
sf::RenderWindow *App = new sf::RenderWindow(sf::VideoMode(800, 600, 32), "asda", sf::Style::Close);
// Create a clock for measuring time elapsed
sf::Clock Clock;
// Set color and depth clear value
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
// Enable Z-buffer read and write
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// Setup a perspective projection
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(90.f, 1.f, 1.f, 500.f);
// Start game loop
while (App->IsOpened())
{
// Process events
sf::Event Event;
while (App->GetEvent(Event))
{
// Close window : exit
if (Event.Type == sf::Event::Closed)
App->Close();
// Escape key : exit
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape))
App->Close();
// Resize event : adjust viewport
if (Event.Type == sf::Event::Resized)
glViewport(0, 0, Event.Size.Width, Event.Size.Height);
}
// Set the active window before using OpenGL commands
// It's useless here because active window is always the same,
// but don't forget it if you use multiple windows or controls
App->SetActive();
// Clear color and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Apply some transformations
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.f, 0.f, -200.f);
int dispX = App->GetInput().GetMouseX() - 400;
static int posX = 400;
posX += dispX;
if (posX < 0) posX = 0;
if (posX > 800) posX = 800;
if (dispX != 0)
App->SetCursorPosition(400, 300);
glDisable(GL_TEXTURE_2D);
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
glOrtho(0, 800, 0, 600, -1, 1);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
int w = 100;
int h = 30;
glTranslatef(posX, 20, 0);
glBegin(GL_QUADS);
glVertex2f(-w, -h);
glVertex2f(+w, -h);
glVertex2f(+w, +h);
glVertex2f(-w, +h);
glEnd();
glPopMatrix();
glMatrixMode(GL_PROJECTION);
glPopMatrix();
glMatrixMode(GL_MODELVIEW);
glEnable(GL_TEXTURE_2D);
// Finally, display rendered frame on screen
App->Display();
}
delete App;
return EXIT_SUCCESS;
}