31
Feature requests / core profile
« on: May 20, 2011, 07:13:46 pm »
ok thanks
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.
int main(int argc, char* argv[])
{
glutInit(&argc, argv);
glutInitContextVersion(4, 1);
glutInitContextFlags(GLUT_FORWARD_COMPATIBLE);
glutInitContextProfile(GLUT_CORE_PROFILE);
...
}
I can honestly not say which is better...
process_text_input(the_events.Text.Unicode);
void loop::display_text()
{
the_context.Clear(sf::Color(255, 255, 255)); //the the_context is a sf::RenderWindow object
if (the_clock.GetElapsedTime() < 0.400f) //this whole time checking is for the blinking | sign
{
the_text.SetString(the_string.substr(0, the_string.length()).insert(the_pos, 1, '|'));
}
else
{
the_text.SetString(the_string.substr(0, the_string.length()).insert(the_pos, 1, ' '));
if (the_clock.GetElapsedTime() > 0.800f)
{
the_clock.Reset();
}
}
the_context.Draw(the_text); //the the_text is a sf::text object
the_context.Display();
}
void loop::start()
{
the_context.Create(sf::VideoMode(1280, 720, 32), "This is an SFML based text editor.", sf::Style::Resize | sf::Style::Close);
the_context.Show(true);
the_context.SetFramerateLimit(30);
if (!the_font.LoadFromFile("verdana.ttf")) //this font does contain utf-8 characters
{
std::cerr << "Couldn't load font.\n";
exit(1);
}
the_text.SetFont(the_font);
the_text.SetColor(sf::Color(0, 0, 0));
the_text.SetCharacterSize(20);
while (the_context.IsOpened())
{
// Process events
process_events();
display_text();
}
}
#include "keyboard.h"
void keyboard::process_keypress(sf::Key::Code keycode) //if a key is pressed then let's handle it
{
keys[keycode] = true;
if (keys[sf::Key::Back] == true)
{
//backslash pressed
if (the_string.length() > 0)
{
if (!save_state)
{
if (the_pos > 0)
{
the_string = the_string.replace(the_pos - 1, 1, "");
the_pos--;
}
}
else
{
if (the_pos > save_pos)
{
the_string = the_string.replace(the_pos - 1, 1, "");
the_pos--;
}
}
}
}
if (keys[sf::Key::Delete] == true)
{
//delete pressed
if (the_pos < the_string.length())
{
the_string = the_string.replace(the_pos, 1, "");
}
}
if (keys[sf::Key::Return] == true)
{
//enter pressed
the_string.insert(the_pos, 1, '\n');
the_pos += 1;
if (save_state)
{
std::string tmp_str = the_string.substr(the_string.substr(0, the_string.length() - 1).rfind("\n") + 1);
tmp_str = tmp_str.substr(0, tmp_str.length() - 1);
std::fstream f;
f.open(tmp_str.c_str(), std::fstream::out);
if (f.is_open())
{
f << write_out;
f.close();
the_string = write_out + "\nText successfully saved!\n";
the_pos = the_string.length();
}
else
{
the_string = write_out + "\nCouldn't save the text!\n";
the_pos = the_string.length();
}
save_state = false;
}
}
if (keys[sf::Key::Escape] == true)
{
//escape pressed
the_context.Close();
}
if (keys[sf::Key::Left] == true)
{
if (!save_state)
{
if (the_pos > 0)
{
the_pos--;
}
}
else
{
if (the_pos > save_pos)
{
the_pos--;
}
}
}
if (keys[sf::Key::Right] == true)
{
if (the_pos < the_string.length())
{
the_pos++;
}
}
if (keys[sf::Key::RControl] == true || keys[sf::Key::LControl] == true)
{
if (keys[sf::Key::S] == true)
{
write_out = the_string;
the_string += "\nPlease enter the filename to save the text to: \n";
the_pos = the_string.length();
save_pos = the_pos;
save_state = true;
is_not_text = true;
}
}
}
void keyboard::process_keyrelease(sf::Key::Code keycode)
{
keys[keycode] = false;
}
void keyboard::process_text_input(const unsigned int& char_code)
{
for (int c = 0; c < not_text.size(); c++)
{
if (keys[not_text[c]] == true)
{
is_not_text = true;
}
}
if (!is_not_text) //if it is text
{
the_string.insert(the_pos, 1, (wchar_t)char_code); //I think the problem lies here: I convert the incoming unsigned integer to a wchar_t which is supposed to be utf-8 right?
the_pos++;
}
is_not_text = false;
}
it sounds like SDL uses software rendering, as opposed to the OpenGL-based hardware acceleration SFML uses
I'm not curious about the two libraries' own 2D drawing performance.