Renderer::Renderer(MaterialManager* const mM, ShaderManager* const sM, const int w, const int h, const bool f, const int aa): mManager{mM},sManager{sM},openglContext{} { SDL_Init(SDL_INIT_VIDEO); createContext(w,h,f,aa); initialize(); guiInitialize(); }
//No settings file found Renderer::Renderer(MaterialManager* const mM, ShaderManager* const sM): mManager{mM},sManager{sM},openglContext{} { SDL_DisplayMode desktop; SDL_Init(SDL_INIT_VIDEO); SDL_GetDesktopDisplayMode(0,&desktop); createContext(desktop.w,desktop.h,true,1); initialize(); guiInitialize(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); ui->PixelDisplay1->setSize(DISPLAY_XSIZE, DISPLAY_YSIZE); ui->PixelDisplay1->setDataEncoding(PixelDisplay::MONOCHROME_3310_8bit); ui->PixelDisplay1->setScale(3.0); ui->PixelDisplay2->setSize(DISPLAY_XSIZE, DISPLAY_YSIZE); ui->PixelDisplay2->setDataEncoding(PixelDisplay::MONOCHROME_3310_8bit); ui->PixelDisplay2->setScale(3.0); StatusLabel_LCD0 = new QLabel(this); StatusLabel_LCD1 = new QLabel(this); ui->statusBar->addWidget(StatusLabel_LCD0); ui->statusBar->addWidget(StatusLabel_LCD1); keyDriver1 = new keyDriver(this, 10, 300, 50); // size of enum buttons ? // Signals and slots mapping // View viewSignalMapper = new QSignalMapper(this); viewSignalMapper->setMapping(ui->actionX1, 1); viewSignalMapper->setMapping(ui->actionX2, 2); viewSignalMapper->setMapping(ui->actionX3, 3); viewSignalMapper->setMapping(ui->actionX4, 4); viewSignalMapper->setMapping(ui->actionX5, 5); connect(ui->actionX1, SIGNAL(triggered()), viewSignalMapper, SLOT (map())); connect(ui->actionX2, SIGNAL(triggered()), viewSignalMapper, SLOT (map())); connect(ui->actionX3, SIGNAL(triggered()), viewSignalMapper, SLOT (map())); connect(ui->actionX4, SIGNAL(triggered()), viewSignalMapper, SLOT (map())); connect(ui->actionX5, SIGNAL(triggered()), viewSignalMapper, SLOT (map())); connect(viewSignalMapper, SIGNAL(mapped(const int &)), this, SLOT(on_viewScale_changed(const int &))); // Control buttons press btnPressSignalMapper = new QSignalMapper(this); btnPressSignalMapper->setMapping(ui->pushButton_esc, APP_KEY_ESC); btnPressSignalMapper->setMapping(ui->pushButton_left, APP_KEY_LEFT); btnPressSignalMapper->setMapping(ui->pushButton_right, APP_KEY_RIGHT); btnPressSignalMapper->setMapping(ui->pushButton_ok, APP_KEY_OK); btnPressSignalMapper->setMapping(ui->pushButton_encoder, APP_KEY_ENCODER); connect(ui->pushButton_esc, SIGNAL(pressed()), btnPressSignalMapper, SLOT(map())); connect(ui->pushButton_left, SIGNAL(pressed()), btnPressSignalMapper, SLOT(map())); connect(ui->pushButton_right, SIGNAL(pressed()), btnPressSignalMapper, SLOT(map())); connect(ui->pushButton_ok, SIGNAL(pressed()), btnPressSignalMapper, SLOT(map())); connect(ui->pushButton_encoder, SIGNAL(pressed()), btnPressSignalMapper, SLOT(map())); connect(btnPressSignalMapper, SIGNAL(mapped(const int &)), keyDriver1, SLOT(keyPress(const int &))); // Control buttons release btnReleaseSignalMapper = new QSignalMapper(this); btnReleaseSignalMapper->setMapping(ui->pushButton_esc, APP_KEY_ESC); btnReleaseSignalMapper->setMapping(ui->pushButton_left, APP_KEY_LEFT); btnReleaseSignalMapper->setMapping(ui->pushButton_right, APP_KEY_RIGHT); btnReleaseSignalMapper->setMapping(ui->pushButton_ok, APP_KEY_OK); btnReleaseSignalMapper->setMapping(ui->pushButton_encoder, APP_KEY_ENCODER); connect(ui->pushButton_esc, SIGNAL(released()), btnReleaseSignalMapper, SLOT(map())); connect(ui->pushButton_left, SIGNAL(released()), btnReleaseSignalMapper, SLOT(map())); connect(ui->pushButton_right, SIGNAL(released()), btnReleaseSignalMapper, SLOT(map())); connect(ui->pushButton_ok, SIGNAL(released()), btnReleaseSignalMapper, SLOT(map())); connect(ui->pushButton_encoder, SIGNAL(released()), btnReleaseSignalMapper, SLOT(map())); connect(btnReleaseSignalMapper, SIGNAL(mapped(const int &)), keyDriver1, SLOT(keyRelease(const int &))); connect(keyDriver1, SIGNAL(onKeyEvent(int,int)), this, SLOT(onKeyDriverEvent(int, int))); connect(ui->updateButton,SIGNAL(clicked()),this, SLOT(on_LCD_update())); connect(&updateTimer,SIGNAL(timeout()),this,SLOT(on_LCD_update())); connect(&secondsTimer,SIGNAL(timeout()),this,SLOT(on_secondsTimer())); connect(ui->PixelDisplay1, SIGNAL(touchMove()), this, SLOT(on_touchMove()) ); connect(ui->PixelDisplay1, SIGNAL(touchPress()), this, SLOT(on_touchPress()) ); connect(ui->PixelDisplay1, SIGNAL(touchRelease()), this, SLOT(on_touchRelease()) ); connect(ui->PixelDisplay2, SIGNAL(touchMove()), this, SLOT(on_touchMove()) ); connect(ui->PixelDisplay2, SIGNAL(touchPress()), this, SLOT(on_touchPress()) ); connect(ui->PixelDisplay2, SIGNAL(touchRelease()), this, SLOT(on_touchRelease()) ); qApp->installEventFilter( this ); // This does shrinking of a form when inner widgets are resized //layout()->setSizeConstraint(QLayout::SetFixedSize); pt2Myself = this; registerLogCallback((cbLogPtr)&MainWindow::addLogWrapper); registerLcdUpdateCallback((cbLcdUpdatePtr)&MainWindow::updateDisplayWrapper); guiInitialize(); // Start seconds timer //secondsTimer.start(1000); // Start update timer if (ui->updateCheckBox->checkState()) { updateTimer.start(ui->updateSpinBox->value()); } }
void Renderer::createContext(const int width, const int height, const bool fullscreen, const int aa) { bool needRecover{false}; if(height>0) { aspectRatio=static_cast<float>(width)/static_cast<float>(height); aspectRatioGUI=(height+((width-height)/2))/(float)(width); } else { throwFatalError("Divide by zero in createContext"); } contextW=width; contextH=height; if(openglContext!=0) { for(auto m: models) m->destroy(); program->destroy(); guiprogram->destroy(); sManager->destroyShaders(); mManager->destroyMaterials(); destroyContext(); guiDestroy(); needRecover=true; } //OpenGL parameters SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE,24); SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER,1); SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION,2); SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION,0); //Setup AA parameters const int level{requestAntiAliasingLevel(aa)}; SDL_GL_SetAttribute(SDL_GL_MULTISAMPLEBUFFERS,level==1?0:1); SDL_GL_SetAttribute(SDL_GL_MULTISAMPLESAMPLES,level==1?0:level); //Window parameters Uint32 arguments{SDL_WINDOW_OPENGL|SDL_WINDOW_SHOWN}; if(fullscreen) arguments|=SDL_WINDOW_FULLSCREEN; window=SDL_CreateWindow(GAMENAME,SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,width,height,arguments); if(window==nullptr) throwFatalError(SDL_GetError()); openglContext=SDL_GL_CreateContext(window); if(openglContext==nullptr) throwFatalError(SDL_GetError()); #ifdef __ANDROID_GAME__ #else SDL_SetRelativeMouseMode(SDL_TRUE); //FIXME move #endif glEnable(GL_DEPTH_TEST); if(needRecover) { guiInitialize(); for(auto m: models) m->recover(); sManager->recoverShaders(); program->recover(); guiprogram->recover(); mManager->recoverMaterials(); } }