Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <application.h>
- #include <stdexcept>
- #include <opengl/types.h>
- #include <QHBoxLayout>
- #include <QScrollArea>
- #include <QToolBar>
- #include <QMenuBar>
- #include <QLayout>
- #include <QDir>
- #include <QSettings>
- #include <QTime>
- #include <QGLWidget>
- #include <QGLFormat>
- #include <QFontDatabase>
- #include <QTranslator>
- #include <QLocale>
- #include <QLibraryInfo>
- #include <QFileDialog>
- namespace noggit
- {
- application::application (int& argc, char** argv)
- : QApplication (argc, argv)
- , _settings (NULL)
- {
- #ifndef _DEBUG
- RegisterErrorHandlers();
- #endif
- InitLogging();
- _settings = new QSettings (this);
- QTranslator* qtTranslator (new QTranslator (this));
- qtTranslator->load ("qt_" + QLocale::system().name(), QLibraryInfo::location (QLibraryInfo::TranslationsPath));
- installTranslator (qtTranslator);
- QTranslator* appTranslator (new QTranslator (this));
- appTranslator->load ("noggit_" + QLocale::system().name());
- installTranslator (appTranslator);
- qsrand (QTime::currentTime().msec());
- initialize_video();
- Menu* map_selection_menu (new Menu (NULL));
- connect (map_selection_menu, SIGNAL (create_world_view_request ()), SLOT (create_main_window()));
- map_selection_menu->show();
- }
- application::~application()
- {
- }
- class dummy_gl_widget : public QGLWidget
- {
- public:
- dummy_gl_widget (const QGLFormat& format)
- : QGLWidget (format)
- {
- updateGL();
- }
- protected:
- virtual void initializeGL()
- {
- const GLenum err (glewInit());
- if( GLEW_OK != err )
- {
- LogError << "GLEW: " << glewGetErrorString (err) << std::endl;
- throw std::runtime_error ("unable to initialize glew.");
- }
- //! \todo Fallback for old and bad platforms.
- if (!glGenBuffers) glGenBuffers = glGenBuffersARB;
- if (!glBindBuffer) glBindBuffer = glBindBufferARB;
- if (!glBufferData) glBufferData = glBufferDataARB;
- LogDebug << "GL: Version: " << glGetString (GL_VERSION) << std::endl;
- LogDebug << "GL: Vendor: " << glGetString (GL_VENDOR) << std::endl;
- LogDebug << "GL: Renderer: " << glGetString (GL_RENDERER) << std::endl;
- }
- };
- void application::initialize_video()
- {
- if (!QGLFormat::hasOpenGL())
- LogError << "Your system does not support OpenGL. Sorry, this application can't run without it." << std::endl;
- QGLFormat format;
- format.setStencilBufferSize (1);
- format.setDepthBufferSize (16);
- format.setAlphaBufferSize (8);
- if (_settings->value ("antialiasing").toBool())
- {
- format.setSampleBuffers (true);
- format.setSamples (4);
- }
- _dummy_gl_widget = new dummy_gl_widget (format);
- }
- void application::create_main_window()
- {
- MainWindow* main_window(_dummy_gl_widget, _settings);
- const int xResolution (_settings->value ("resolution/x").toInt());
- const int yResolution (_settings->value ("resolution/y").toInt());
- main_window->show();
- main_window->resize (xResolution, yResolution);
- }
- }
- application& app()
- {
- return* reinterpret_cast<application*> (qApp);
- }
- MainWindow::MainWindow(QGLWidget* _dummy_gl_widget, QSettings* _settings)
- {
- setWindowTitle("Application");
- QWidget* centralWidget (new QWidget);
- setCentralWidget(centralWidget);
- MapView* map_view(new MapView ( _dummy_gl_widget, centralWidget));
- QScrollArea* glWidgetArea (new QScrollArea);
- glWidgetArea->setWidget(map_view);
- glWidgetArea->setWidgetResizable(true);
- glWidgetArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- glWidgetArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
- glWidgetArea->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Ignored);
- glWidgetArea->setMinimumSize(480, 480);
- QHBoxLayout* widgetLayout (new QHBoxLayout);
- widgetLayout->addWidget(_dummy_gl_widget);
- centralWidget->setLayout(widgetLayout);
- }
- QToolBar* MainWindow::tool_bar()
- {
- return _toolBar;
- }
- }
- int main (int argc, char* argv[]);
- #ifdef Q_WS_WIN
- int __stdcall WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
- {
- return main (__argc, __argv);
- }
- #endif
- int main (int argc, char* argv[])
- {
- try
- {
- application application (argc, argv);
- return application.exec();
- }
- catch (const std::exception& e)
- {
- LogError << "Unrecoverable error: " << e.what() << std::endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement