Hi all,
I'm teaching myself OpenGL, using SFML for a context. I've finally gotten to the point where I want to be able to move the camera. So you know, press 'w' and the camera's "move foward" becomes true.
I'm having a problem getting the input to actually trigger something though. My guess is there is something simple I'm just missing, perhaps some one can help.
// My main function is where the message loop is:
sf::Event pEvent;
bool open = (app.isOpen()? true : false);
while (open)
{
while (app.pollEvent(pEvent))
{
open = prgEvent(pEvent);
}
display();
app.display();
}
app.close();
delete model;
delete terra;
delete cam;
return 0;
// prgEvent(pEvent) takes the event and splits it into types,
// returning false if program should end
bool prgEvent(sf::Event& pEvent)
{
// A false return signals the end of the program
switch (pEvent.type)
{
case sf::Event::KeyPressed: return prgKeyPressed(pEvent.key.code);
case sf::Event::Closed: return false; // Note that this works
}
return true;
}
//prgKeyPressed() makes a switch on the actual key
#define print1(x) std::cout << x << '\n'
bool prgKeyPressed(sf::Keyboard::Key& kpCode)
{
// A false return signals the end of the program
switch (kpCode)
{
case sf::Keyboard::Escape: print1(kpCode); return false;
}
return true;
}
@Exploiter: Like those tags? :)
So, in the case of sf::Keyboard::Escape I print kpCode (which is 36), and then return false, right?
I get 36 printing on console, but the program doesn't quit. Like I said, I must be missing something here.
Thanks
Putting breaks after the returns doesn't do anything.
Edit: Okay, so in the main() message loop:
while (app.pollEvent(pEvent))
{
open = prgEvent(pEvent);
print1(open);
}
I am getting a zero printed when I hit escape. ?? case sf::Event::Closed: return false; quits my program ?
Edit2: However this:
std::ofstream out("test.txt");
while (open)
{
while (app.pollEvent(pEvent))
{
open = prgEvent(pEvent);
}
out << open << std::endl;
display();
app.display();
}
out.close();
Prints a whole bunch of 1s to test.txt with only a zero from when I acitvate sf::Event::Closed:
What the heck is going on? it's like I lost scope.
Strange how copy pasting code to make it clear for someone else finds the bug itself.
while (app.pollEvent(pEvent))
I sent more than one event when I hit Escape. The first being the KeyPress of escape, the second I don't know (27), and then the KeyRelease of escape. Of course, the key press set open to false, but the others set to true!
while (app.pollEvent(pEvent) && open)
As a side, I noticed:
while (app.pollEvent(pEvent))
{
open = prgEvent(pEvent);
print1(pEvent.key.code); // This prints the X location of the mouse on the window
}
Also, is there a link to how I can figure out what that mysterious 27 was?