Regarding the integer stuff, think of the mouse not as a pointer, but as a physical joystick-like thing. It makes perfect sense to have an input that represents the speed of a finger moving over it.
As for minimal code... I tried.
The line you're looking for is this:
if (nFrame %1 == 0) { // <-- The offending number
When that number is 2:
- mouse stays in center
- square moves up
- escape events are caught
When that number is 1:
- mouse stays in center
- the square moves up (so I guess the loop has not crashed)
- escape events are not caught
- spinning beach ball of death
#include <iostream>
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
int main(int argc, char** argv) {
sf::VideoMode DesktopMode = sf::VideoMode::GetDesktopMode();
sf::ContextSettings OGLContext(
24, // depth
8, // stencil
4, // antialiasing
2, // major
0); // minor
float WIDTH = DesktopMode.Width;
float HEIGHT = DesktopMode.Height;
float AspectRatio = float(WIDTH)/float(HEIGHT);
sf::Window Window(DesktopMode, "SFML Window", sf::Style::Fullscreen, OGLContext);
Window.SetActive();
const sf::Input& WInput = Window.GetInput();
Window.ShowMouseCursor(true);
Window.SetCursorPosition(WIDTH/2, HEIGHT/2);
// glSetup
glClearDepth(1.f);
glClearColor(0.f, 0.f, 0.f, 0.f);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
// glPerspective
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(70.f, AspectRatio, .1f, 500.f);
glMatrixMode(GL_MODELVIEW);
// Setup for event handling
sf::Event Event;
bool Running = true;
// Main Loop
unsigned int nFrame = 0;
while (Running) {
++nFrame;
// Event Handling
while (Window.GetEvent(Event)) {
if (Event.Type == sf::Event::Closed)
{Running = false;}
else if (Event.Type == sf::Event::KeyPressed) {
if (Event.Key.Code == sf::Key::Escape)
{Running = false; }
}
}
// Move Mouse
if (nFrame %1 == 0) { // <-- The offending number
Window.SetCursorPosition(WIDTH/2, HEIGHT/2);
}
// Rendering Setup
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
// Draw a square with colors
glPushMatrix();
glTranslatef(5.f, 0.f, -10.f);
glTranslatef(0, nFrame/float(100), 0);
glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_QUADS);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.0f,0.0f,1.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glEnd();
glPopMatrix();
// Display Window
Window.Display();
}
return EXIT_SUCCESS;
}