1
Graphics / using views with a "background" of unlimited size
« on: May 22, 2010, 01:07:03 pm »
I've been working on that basis following your previous suggestion
so thanks for that.
so thanks for that.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
http://www.sfml-dev.org/forum/viewtopic.php?t=1126&sid=acf2a5245ad6fcd4e925af795cd48b57
App.Clear();
Text.SetText( Some_function_that_returns_a_string() );
App.Draw(Text);
App.Display();
http://www.sfml-dev.org/forum/viewtopic.php?t=2189&highlight=
The number one mistake people make in doing text apps in OpenGL is
they do not cache individual character glyphs as textures.
They either reconvert from the font (very slow) each time they draw a character
or
they upload the glyphs (slow) each time they draw the character.
If you create each glyph as a texture with only the alpha plane
you can scale the characters to any size you need and paint them any way you want
and since modern graphics cards are designed to render textures you get the best speed possible.
while ( App.IsOpened() ){
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)) { //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;}
}
}
}
//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;
}