- added ability to change background color and take screenshots (see file and Custom Color menus)
This commit is contained in:
parent
66261ad662
commit
685c338f97
|
@ -82,6 +82,7 @@ MainWindow::MainWindow(const string &modelPath)
|
||||||
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load P&rojectile Particle XML"), wxT("Press ctrl before menu for keeping current projectile particles"));
|
menuFile->Append(miFileLoadProjectileParticleXML, wxT("Load P&rojectile Particle XML"), wxT("Press ctrl before menu for keeping current projectile particles"));
|
||||||
menuFile->Append(miFileLoadSplashParticleXML, wxT("Load &Splash Particle XML"), wxT("Press ctrl before menu for keeping current splash particles"));
|
menuFile->Append(miFileLoadSplashParticleXML, wxT("Load &Splash Particle XML"), wxT("Press ctrl before menu for keeping current splash particles"));
|
||||||
menuFile->Append(miFileClearAll, wxT("&Clear All"));
|
menuFile->Append(miFileClearAll, wxT("&Clear All"));
|
||||||
|
menuFile->Append(miFileSaveScreenshot, wxT("Sa&ve a Screenshot"));
|
||||||
menuFile->AppendSeparator();
|
menuFile->AppendSeparator();
|
||||||
menuFile->Append(wxID_EXIT);
|
menuFile->Append(wxID_EXIT);
|
||||||
menu->Append(menuFile, wxT("&File"));
|
menu->Append(menuFile, wxT("&File"));
|
||||||
|
@ -103,6 +104,7 @@ MainWindow::MainWindow(const string &modelPath)
|
||||||
|
|
||||||
//custom color
|
//custom color
|
||||||
menuCustomColor= new wxMenu();
|
menuCustomColor= new wxMenu();
|
||||||
|
menuCustomColor->AppendCheckItem(miChangeBackgroundColor, wxT("Change Background Color"));
|
||||||
menuCustomColor->AppendCheckItem(miColorRed, wxT("&Red\t0"));
|
menuCustomColor->AppendCheckItem(miColorRed, wxT("&Red\t0"));
|
||||||
menuCustomColor->AppendCheckItem(miColorBlue, wxT("&Blue\t1"));
|
menuCustomColor->AppendCheckItem(miColorBlue, wxT("&Blue\t1"));
|
||||||
menuCustomColor->AppendCheckItem(miColorGreen, wxT("&Green\t2"));
|
menuCustomColor->AppendCheckItem(miColorGreen, wxT("&Green\t2"));
|
||||||
|
@ -257,6 +259,30 @@ void MainWindow::onMouseMove(wxMouseEvent &event){
|
||||||
lastY= y;
|
lastY= y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::OnChangeColor(wxCommandEvent &event) {
|
||||||
|
//wxColour color = colorPicker->GetColour();
|
||||||
|
wxColourData data;
|
||||||
|
data.SetChooseFull(true);
|
||||||
|
for (int i = 0; i < 16; i++)
|
||||||
|
{
|
||||||
|
wxColour colour(i*16, i*16, i*16);
|
||||||
|
data.SetCustomColour(i, colour);
|
||||||
|
}
|
||||||
|
|
||||||
|
wxColourDialog dialog(this, &data);
|
||||||
|
if (dialog.ShowModal() == wxID_OK)
|
||||||
|
{
|
||||||
|
wxColourData retData = dialog.GetColourData();
|
||||||
|
wxColour col = retData.GetColour();
|
||||||
|
|
||||||
|
renderer->setBackgroundColor(col.Red()/255.0f, col.Green()/255.0f, col.Blue()/255.0f, col.Alpha()/255.0f);
|
||||||
|
//wxBrush brush(col, wxSOLID);
|
||||||
|
//myWindow->SetBackground(brush);
|
||||||
|
//myWindow->Clear();
|
||||||
|
//myWindow->Refresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
void MainWindow::onMenuFileLoad(wxCommandEvent &event){
|
||||||
string fileName;
|
string fileName;
|
||||||
|
|
||||||
|
@ -326,6 +352,28 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
|
||||||
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
|
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
|
||||||
|
|
||||||
|
|
||||||
|
void MainWindow::onMenuFileSaveScreenshot(wxCommandEvent &event) {
|
||||||
|
string path = "screens/";
|
||||||
|
if(isdir(path.c_str()) == true) {
|
||||||
|
//Config &config= Config::getInstance();
|
||||||
|
//string fileFormat = config.getString("ScreenShotFileType","png");
|
||||||
|
string fileFormat = "png";
|
||||||
|
|
||||||
|
for(int i=0; i < 1000; ++i) {
|
||||||
|
path = "screens/";
|
||||||
|
path += string("screen") + intToStr(i) + string(".") + fileFormat;
|
||||||
|
FILE *f= fopen(path.c_str(), "rb");
|
||||||
|
if(f == NULL) {
|
||||||
|
renderer->saveScreen(path);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
fclose(f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
|
void MainWindow::onMenuFileClearAll(wxCommandEvent &event) {
|
||||||
modelPathList.clear();
|
modelPathList.clear();
|
||||||
particlePathList.clear();
|
particlePathList.clear();
|
||||||
|
@ -927,6 +975,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
||||||
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
|
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
|
||||||
EVT_MENU(miFileLoadSplashParticleXML, MainWindow::onMenuFileLoadSplashParticleXML)
|
EVT_MENU(miFileLoadSplashParticleXML, MainWindow::onMenuFileLoadSplashParticleXML)
|
||||||
EVT_MENU(miFileClearAll, MainWindow::onMenuFileClearAll)
|
EVT_MENU(miFileClearAll, MainWindow::onMenuFileClearAll)
|
||||||
|
EVT_MENU(miFileSaveScreenshot, MainWindow::onMenuFileSaveScreenshot)
|
||||||
EVT_MENU(wxID_EXIT, MainWindow::onMenuFileExit)
|
EVT_MENU(wxID_EXIT, MainWindow::onMenuFileExit)
|
||||||
|
|
||||||
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
|
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
|
||||||
|
@ -945,6 +994,8 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
||||||
EVT_MENU(miColorCyan, MainWindow::onMenuColorCyan)
|
EVT_MENU(miColorCyan, MainWindow::onMenuColorCyan)
|
||||||
EVT_MENU(miColorOrange, MainWindow::onMenuColorOrange)
|
EVT_MENU(miColorOrange, MainWindow::onMenuColorOrange)
|
||||||
EVT_MENU(miColorMagenta, MainWindow::onMenuColorMagenta)
|
EVT_MENU(miColorMagenta, MainWindow::onMenuColorMagenta)
|
||||||
|
|
||||||
|
EVT_MENU(miChangeBackgroundColor, MainWindow::OnChangeColor)
|
||||||
END_EVENT_TABLE()
|
END_EVENT_TABLE()
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
#include <wx/wx.h>
|
#include <wx/wx.h>
|
||||||
#include <wx/glcanvas.h>
|
#include <wx/glcanvas.h>
|
||||||
|
//#include <wx/clrpicker.h>
|
||||||
|
#include <wx/colordlg.h>
|
||||||
|
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
@ -36,12 +38,14 @@ public:
|
||||||
miFileLoadProjectileParticleXML,
|
miFileLoadProjectileParticleXML,
|
||||||
miFileLoadSplashParticleXML,
|
miFileLoadSplashParticleXML,
|
||||||
miFileClearAll,
|
miFileClearAll,
|
||||||
|
miFileSaveScreenshot,
|
||||||
miModeWireframe,
|
miModeWireframe,
|
||||||
miModeNormals,
|
miModeNormals,
|
||||||
miModeGrid,
|
miModeGrid,
|
||||||
miSpeedSlower,
|
miSpeedSlower,
|
||||||
miSpeedFaster,
|
miSpeedFaster,
|
||||||
miRestart,
|
miRestart,
|
||||||
|
miChangeBackgroundColor,
|
||||||
miColorRed,
|
miColorRed,
|
||||||
miColorBlue,
|
miColorBlue,
|
||||||
miColorGreen,
|
miColorGreen,
|
||||||
|
@ -65,6 +69,8 @@ private:
|
||||||
wxMenu *menuCustomColor;
|
wxMenu *menuCustomColor;
|
||||||
wxFileDialog *fileDialog;
|
wxFileDialog *fileDialog;
|
||||||
|
|
||||||
|
wxColourDialog *colorPicker;
|
||||||
|
|
||||||
Model *model;
|
Model *model;
|
||||||
|
|
||||||
std::vector<string> modelPathList;
|
std::vector<string> modelPathList;
|
||||||
|
@ -108,6 +114,7 @@ public:
|
||||||
void onMenuFileLoadProjectileParticleXML(wxCommandEvent &event);
|
void onMenuFileLoadProjectileParticleXML(wxCommandEvent &event);
|
||||||
void onMenuFileLoadSplashParticleXML(wxCommandEvent &event);
|
void onMenuFileLoadSplashParticleXML(wxCommandEvent &event);
|
||||||
void onMenuFileClearAll(wxCommandEvent &event);
|
void onMenuFileClearAll(wxCommandEvent &event);
|
||||||
|
void onMenuFileSaveScreenshot(wxCommandEvent &event);
|
||||||
void onMenuFileExit(wxCommandEvent &event);
|
void onMenuFileExit(wxCommandEvent &event);
|
||||||
void onMenuModeNormals(wxCommandEvent &event);
|
void onMenuModeNormals(wxCommandEvent &event);
|
||||||
void onMenuModeWireframe(wxCommandEvent &event);
|
void onMenuModeWireframe(wxCommandEvent &event);
|
||||||
|
@ -115,6 +122,7 @@ public:
|
||||||
void onMenuSpeedSlower(wxCommandEvent &event);
|
void onMenuSpeedSlower(wxCommandEvent &event);
|
||||||
void onMenuSpeedFaster(wxCommandEvent &event);
|
void onMenuSpeedFaster(wxCommandEvent &event);
|
||||||
void onMenuRestart(wxCommandEvent &event);
|
void onMenuRestart(wxCommandEvent &event);
|
||||||
|
void OnChangeColor(wxCommandEvent &event);
|
||||||
void onMenuColorRed(wxCommandEvent &event);
|
void onMenuColorRed(wxCommandEvent &event);
|
||||||
void onMenuColorBlue(wxCommandEvent &event);
|
void onMenuColorBlue(wxCommandEvent &event);
|
||||||
void onMenuColorGreen(wxCommandEvent &event);
|
void onMenuColorGreen(wxCommandEvent &event);
|
||||||
|
|
|
@ -79,6 +79,12 @@ Renderer::Renderer(){
|
||||||
textureManager = NULL;
|
textureManager = NULL;
|
||||||
particleRenderer = NULL;
|
particleRenderer = NULL;
|
||||||
modelManager = NULL;
|
modelManager = NULL;
|
||||||
|
width=0;
|
||||||
|
height=0;
|
||||||
|
red = 0.3f;
|
||||||
|
green = 0.3f;
|
||||||
|
blue = 0.3f;
|
||||||
|
alpha = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer::~Renderer() {
|
Renderer::~Renderer() {
|
||||||
|
@ -110,10 +116,8 @@ void Renderer::transform(float rotX, float rotY, float zoom){
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::checkGlCaps() {
|
void Renderer::checkGlCaps() {
|
||||||
|
|
||||||
//opengl 1.3
|
//opengl 1.3
|
||||||
if(!isGlVersionSupported(1, 3, 0)) {
|
if(!isGlVersionSupported(1, 3, 0)) {
|
||||||
|
|
||||||
string message;
|
string message;
|
||||||
|
|
||||||
message += "Your system supports OpenGL version \"";
|
message += "Your system supports OpenGL version \"";
|
||||||
|
@ -125,13 +129,13 @@ void Renderer::checkGlCaps(){
|
||||||
}
|
}
|
||||||
|
|
||||||
//opengl 1.4 or extension
|
//opengl 1.4 or extension
|
||||||
if(!isGlVersionSupported(1, 4, 0)){
|
if(isGlVersionSupported(1, 4, 0) == false) {
|
||||||
checkExtension("GL_ARB_texture_env_crossbar", "MegaGlest");
|
checkExtension("GL_ARB_texture_env_crossbar", "MegaGlest");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Renderer::checkExtension(const string &extension, const string &msg) {
|
void Renderer::checkExtension(const string &extension, const string &msg) {
|
||||||
if(!isGlExtensionSupported(extension.c_str())){
|
if(isGlExtensionSupported(extension.c_str()) == false) {
|
||||||
string str= "OpenGL extension not supported: " + extension + ", required for " + msg;
|
string str= "OpenGL extension not supported: " + extension + ", required for " + msg;
|
||||||
throw runtime_error(str);
|
throw runtime_error(str);
|
||||||
}
|
}
|
||||||
|
@ -147,12 +151,20 @@ Model * Renderer::getNewModel() {
|
||||||
return newModel;
|
return newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::setBackgroundColor(float red, float green, float blue, float alpha) {
|
||||||
|
this->red = red;
|
||||||
|
this->green = green;
|
||||||
|
this->blue = blue;
|
||||||
|
this->alpha= alpha;
|
||||||
|
glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3
|
||||||
|
//glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
|
||||||
|
//glFlush();
|
||||||
|
//SwapBuffers();
|
||||||
|
}
|
||||||
|
|
||||||
void Renderer::init() {
|
void Renderer::init() {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
//!!!glInitNames();
|
|
||||||
//!!!checkGlCaps();
|
|
||||||
|
|
||||||
GraphicsFactory *gf= new GraphicsFactoryGl();
|
GraphicsFactory *gf= new GraphicsFactoryGl();
|
||||||
GraphicsInterface::getInstance().setFactory(gf);
|
GraphicsInterface::getInstance().setFactory(gf);
|
||||||
|
|
||||||
|
@ -206,7 +218,7 @@ void Renderer::init(){
|
||||||
customTextureMagenta->getPixmap()->init(1, 1, 3);
|
customTextureMagenta->getPixmap()->init(1, 1, 3);
|
||||||
customTextureMagenta->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 1.f));
|
customTextureMagenta->getPixmap()->setPixel(0, 0, Vec3f(1.f, 0.5f, 1.f));
|
||||||
|
|
||||||
glClearColor(0.3f, 0.3f, 0.3f, 1.0f); //backgroundcolor constant 0.3
|
glClearColor(red, green, blue, alpha); //backgroundcolor constant 0.3
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
glFrontFace(GL_CW);
|
glFrontFace(GL_CW);
|
||||||
glEnable(GL_CULL_FACE);
|
glEnable(GL_CULL_FACE);
|
||||||
|
@ -233,6 +245,9 @@ void Renderer::init(){
|
||||||
void Renderer::reset(int w, int h, PlayerColor playerColor) {
|
void Renderer::reset(int w, int h, PlayerColor playerColor) {
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
|
width=w;
|
||||||
|
height=h;
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
glViewport(0, 0, w, h);
|
glViewport(0, 0, w, h);
|
||||||
glMatrixMode(GL_PROJECTION);
|
glMatrixMode(GL_PROJECTION);
|
||||||
|
@ -291,8 +306,7 @@ void Renderer::reset(int w, int h, PlayerColor playerColor){
|
||||||
|
|
||||||
void Renderer::renderGrid() {
|
void Renderer::renderGrid() {
|
||||||
if(grid) {
|
if(grid) {
|
||||||
|
float i=0;
|
||||||
float i;
|
|
||||||
|
|
||||||
assertGl();
|
assertGl();
|
||||||
|
|
||||||
|
@ -420,4 +434,17 @@ void Renderer::end() {
|
||||||
modelManager->end();
|
modelManager->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Renderer::saveScreen(const string &path) {
|
||||||
|
//const Metrics &sm= Metrics::getInstance();
|
||||||
|
|
||||||
|
//Pixmap2D pixmap(sm.getScreenW(), sm.getScreenH(), 3);
|
||||||
|
Pixmap2D *pixmapScreenShot = new Pixmap2D(width, height, 3);
|
||||||
|
glFinish();
|
||||||
|
glReadPixels(0, 0, pixmapScreenShot->getW(), pixmapScreenShot->getH(),
|
||||||
|
GL_RGB, GL_UNSIGNED_BYTE, pixmapScreenShot->getPixels());
|
||||||
|
|
||||||
|
pixmapScreenShot->save(path);
|
||||||
|
delete pixmapScreenShot;
|
||||||
|
}
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
|
@ -79,6 +79,9 @@ private:
|
||||||
bool normals;
|
bool normals;
|
||||||
bool grid;
|
bool grid;
|
||||||
|
|
||||||
|
int width;
|
||||||
|
int height;
|
||||||
|
|
||||||
ModelRenderer *modelRenderer;
|
ModelRenderer *modelRenderer;
|
||||||
TextureManager *textureManager;
|
TextureManager *textureManager;
|
||||||
ParticleRenderer *particleRenderer;
|
ParticleRenderer *particleRenderer;
|
||||||
|
@ -96,6 +99,11 @@ private:
|
||||||
Texture2D *customTextureMagenta;
|
Texture2D *customTextureMagenta;
|
||||||
MeshCallbackTeamColor meshCallbackTeamColor;
|
MeshCallbackTeamColor meshCallbackTeamColor;
|
||||||
|
|
||||||
|
float red;
|
||||||
|
float green;
|
||||||
|
float blue;
|
||||||
|
float alpha;
|
||||||
|
|
||||||
Renderer();
|
Renderer();
|
||||||
void checkGlCaps();
|
void checkGlCaps();
|
||||||
void checkExtension(const string &extension, const string &msg);
|
void checkExtension(const string &extension, const string &msg);
|
||||||
|
@ -135,6 +143,9 @@ public:
|
||||||
void initModelManager();
|
void initModelManager();
|
||||||
|
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
|
void setBackgroundColor(float red, float green, float blue, float alpha);
|
||||||
|
void saveScreen(const string &path);
|
||||||
};
|
};
|
||||||
|
|
||||||
}}//end namespace
|
}}//end namespace
|
||||||
|
|
Loading…
Reference in New Issue