I've just completely recoded my application, and it compiles fine, but doesn't open. I've got the main loop, am handling events correctly (I hope), and am doing everything correctly apparently. However something is going wrong in the code because the final application doesn't open an SFML window. If you can check over my code and possibly debug it, here it is:
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <vector>
sf::RenderWindow rWnd;
sf::Color bgColor;
sf::Font mainFont;
sf::String pre = "System!>";
sf::Text prefix;
sf::String buf;
sf::Text buffer;
sf::String lastStr;
sf::Text lastLine;
std::vector<sf::String> lineVector;
int lineCounter = 1;
int currentVectorPosition = 0;
int i = 0;
void MakeNewLine() {
lineVector.push_back(buf);
lineCounter += 1;
}
void PrintLastLines() {
i = 1;
prefix.setPosition(0, 0);
while(i <= lineCounter) {
lastLine.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, prefix.getPosition().y + prefix.getGlobalBounds().height);
lastLine.setString(lineVector[currentVectorPosition]);
rWnd.draw(prefix);
rWnd.draw(lastLine);
i += 1;
currentVectorPosition += 1;
}
}
void LoadFont() {
mainFont.loadFromFile("dos.ttf");
}
void SetTextInfo() {
prefix.setCharacterSize(18);
prefix.setColor(sf::Color(255, 255, 255));
prefix.setFont(mainFont);
prefix.setPosition(0, 0);
prefix.setString(pre);
prefix.setStyle(sf::Text::Regular);
buffer.setCharacterSize(18);
buffer.setColor(sf::Color(255, 255, 255));
buffer.setFont(mainFont);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);
buffer.setString(buf);
buffer.setStyle(sf::Text::Regular);
lastLine.setCharacterSize(18);
lastLine.setColor(sf::Color(255, 255, 255));
lastLine.setFont(mainFont);
lastLine.setStyle(sf::Text::Regular);
}
int main() {
rWnd.setTitle("OpenCMD [Version 2, Beta 1: Private Build]");
rWnd.setSize(sf::Vector2u(800, 600));
LoadFont();
SetTextInfo();
while(rWnd.isOpen()) {
rWnd.clear(sf::Color(0, 0, 203));
sf::Event event;
while(rWnd.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
rWnd.close();
}
if(event.type == sf::Event::KeyPressed) {
if(event.key.code == sf::Keyboard::Return) {
MakeNewLine(); /* Make this later */
}
if(event.key.code == sf::Keyboard::Escape) {
rWnd.close();
}
}
if(event.type == sf::Event::TextEntered) {
if(event.text.unicode == '\b') {
buf.erase(buf.getSize() - 1, 1);
} else {
buf.insert(buf.getSize(), event.text.unicode);
}
}
}
if(lineCounter == 0) {
prefix.setPosition(0, 0);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, 0);
} else {
PrintLastLines();
prefix.setPosition(0, prefix.getPosition().y + prefix.getGlobalBounds().height + 1);
buffer.setPosition(prefix.getPosition().x + prefix.getGlobalBounds().width + 1, prefix.getPosition().y + prefix.getGlobalBounds().height);
}
buffer.setString(buf);
rWnd.draw(prefix);
rWnd.draw(buffer);
}
}
I doubt this has anything to do with the compiler or linker, so I won't go into my specs just yet.