This is my first program built from the samples and source codes.
I'm pleased to see the facility for non-blocking keyboard input
but I would also like to single step through a frame at a time.
Can someone please show me how to modify this program so that you can use eg the spacebar to step through the program a frame at a time.
Thank you in anticipation
//just testing display of set with capacity of 1000 that gets filled then emptied
//g++ text_opengl.cpp -lsfml-graphics -lsfml-window -lsfml-system -lGLU -lGL
#include <SFML/Graphics.hpp>
//#include <SFML/Graphics/Color.hpp> //Red, this include already included by <SFML/Graphics.hpp>?
#include <iostream>
#include <string>
#include <iomanip> //setprecision
#include <sstream> //stringstream
#include <math.h> //log10
using namespace std;
string Set_string(int capacity, int items_in_set){
int max_digits;
int items_digits;
stringstream ss;
if (capacity > 0) {max_digits = ( (int) log10(capacity) + 1 );}
else {max_digits = 0;}
if (items_in_set > 0){items_digits = ( (int) log10(items_in_set) + 1 );}
else {items_digits = 0;}
int leading_0s = max_digits - items_digits;
ss << string(leading_0s,'0') << items_in_set;
return ss.str();
}
int Display_set(){
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML_App");
sf::Font TextFont;
if (!TextFont.LoadFromFile("/home/me/Desktop/bench/cheeseburger.ttf", 30)) {return 1;}
const char * String = "AZERTYUIOPQSDFGHJKLMWXCVBNazertyuiopqsdfghjklmwxcvbn0123456789";
sf::String Text(String, TextFont, 30.f);
Text.SetColor(sf::Color::Red);
Text.SetX(50.f);
Text.SetY(10.f);
int capacity = 100, i=0, count_up=1; //i simulates the qty of items in set with capacity for 1000 of them
while ( App.IsOpened() ){
//This is non-blocking!
sf::Event Event;
while ( App.GetEvent(Event) ){
if (Event.Type == sf::Event::Closed) {App.Close();} //mouse click window close or alt/F4
if ((Event.Type == sf::Event::KeyPressed) && (Event.Key.Code == sf::Key::Escape)) {App.Close();} //Esc key
}
App.Clear();
Text.SetText( Set_string(capacity,i) );
App.Draw(Text);
App.Display();
if (count_up){ if (i<capacity) i++; }
else { if (i>0) i--; }
if (i == capacity) {count_up=0;}
}
return 0;
}
int main(){
Display_set();
return 0;
}