Skip to content

Commit

Permalink
Check graphic card compatibility during startup
Browse files Browse the repository at this point in the history
Ref #26, ref #27
  • Loading branch information
soulweaver91 committed Apr 26, 2016
1 parent e476686 commit 38949be
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 7 deletions.
30 changes: 25 additions & 5 deletions src/CarrotQt5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

CarrotQt5::CarrotQt5(QWidget *parent) : QMainWindow(parent),
#ifdef CARROT_DEBUG
currentTempModifier(0), dbgShowMasked(false), dbgOverlaysActive(true),
currentTempModifier(0), dbgShowMasked(false), dbgOverlaysActive(true), initialized(false),
#endif
paused(false), levelName(""), frame(0), gravity(0.3), isMenu(false), menuObject(nullptr), fps(0) {
#ifndef CARROT_DEBUG
Expand Down Expand Up @@ -72,14 +72,25 @@ CarrotQt5::CarrotQt5(QWidget *parent) : QMainWindow(parent),
// Fill the player pointer table with zeroes
std::fill_n(players, 32, nullptr);

// Read the main font
mainFont = std::make_shared<BitmapFont>("Data/Assets/ui/font_medium.png", 29, 31, 1, 224, 32, 256);

resourceManager = std::make_unique<ResourceManager>();
controlManager = std::make_shared<ControlManager>();

ShaderSource::initialize();
bool shadersSupported = ShaderSource::initialize();
int maxTextureSize = sf::Texture::getMaximumSize();
if (!shadersSupported || maxTextureSize < 4096) {
QMessageBox::critical(nullptr, "System unsupported", QString(
"Your graphics card is not compatible with Project Carrot. For running Project Carrot, "
"support for OpenGL shaders and a minimum texture size of 4096 by 4096 pixels is required.\n\n"
"Your graphics card does%1 support shaders.\n"
"Your graphics card has a maximum texture size of %2 by %2 pixels."
).arg(shadersSupported ? "" : " not").arg(maxTextureSize));
exit(EXIT_FAILURE);
return;
}

// Read the main font
mainFont = std::make_shared<BitmapFont>("Data/Assets/ui/font_medium.png", 29, 31, 1, 224, 32, 256);

installEventFilter(this);

// Define pause screen resources
Expand All @@ -95,9 +106,14 @@ CarrotQt5::CarrotQt5(QWidget *parent) : QMainWindow(parent),
pausedText->setAnimation(true, 0.0, 6.0, 0.015, 1.25);

lastTimestamp = QTime::currentTime();
initialized = true;
}

CarrotQt5::~CarrotQt5() {
if (!initialized) {
return;
}

if (!isMenu) {
cleanUpLevel();
}
Expand All @@ -106,6 +122,10 @@ CarrotQt5::~CarrotQt5() {
}

void CarrotQt5::parseCommandLine() {
if (!initialized) {
return;
}

QStringList param = QCoreApplication::arguments();
QString level = "";
if (param.size() > 1) {
Expand Down
1 change: 1 addition & 0 deletions src/CarrotQt5.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ protected slots:
bool isMenu;
QTime lastTimestamp;
float fps;
bool initialized;

private slots:
void gameTick();
Expand Down
4 changes: 3 additions & 1 deletion src/graphics/ShaderSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ QMap<QString, std::shared_ptr<sf::Shader>> ShaderSource::shaders = QMap<QString,

bool ShaderSource::systemSupportsShaders = false;

void ShaderSource::initialize() {
bool ShaderSource::initialize() {
systemSupportsShaders = sf::Shader::isAvailable();
if (systemSupportsShaders) {
loadShader("ColorizeShader");
loadShader("LightingShader");
}

return systemSupportsShaders;
}

void ShaderSource::teardown() {
Expand Down
2 changes: 1 addition & 1 deletion src/graphics/ShaderSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class ShaderSource {
public:
ShaderSource() = delete;
~ShaderSource() = delete;
static void initialize();
static bool initialize();
static void teardown();
static std::shared_ptr<sf::Shader> getShader(const QString& name);

Expand Down

0 comments on commit 38949be

Please sign in to comment.