- 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(miFileLoadSplashParticleXML, wxT("Load &Splash Particle XML"), wxT("Press ctrl before menu for keeping current splash particles"));
|
||||
menuFile->Append(miFileClearAll, wxT("&Clear All"));
|
||||
menuFile->Append(miFileSaveScreenshot, wxT("Sa&ve a Screenshot"));
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(wxID_EXIT);
|
||||
menu->Append(menuFile, wxT("&File"));
|
||||
|
@ -103,6 +104,7 @@ MainWindow::MainWindow(const string &modelPath)
|
|||
|
||||
//custom color
|
||||
menuCustomColor= new wxMenu();
|
||||
menuCustomColor->AppendCheckItem(miChangeBackgroundColor, wxT("Change Background Color"));
|
||||
menuCustomColor->AppendCheckItem(miColorRed, wxT("&Red\t0"));
|
||||
menuCustomColor->AppendCheckItem(miColorBlue, wxT("&Blue\t1"));
|
||||
menuCustomColor->AppendCheckItem(miColorGreen, wxT("&Green\t2"));
|
||||
|
@ -257,6 +259,30 @@ void MainWindow::onMouseMove(wxMouseEvent &event){
|
|||
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){
|
||||
string fileName;
|
||||
|
||||
|
@ -326,7 +352,29 @@ void MainWindow::onMenuFileLoadSplashParticleXML(wxCommandEvent &event){
|
|||
} // is it possible to join loadParticle(), loadProjectileParticle() and loadSplashParticle() to one method?
|
||||
|
||||
|
||||
void MainWindow::onMenuFileClearAll(wxCommandEvent &event){
|
||||
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) {
|
||||
modelPathList.clear();
|
||||
particlePathList.clear();
|
||||
particleProjectilePathList.clear();
|
||||
|
@ -927,6 +975,7 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
|||
EVT_MENU(miFileLoadProjectileParticleXML, MainWindow::onMenuFileLoadProjectileParticleXML)
|
||||
EVT_MENU(miFileLoadSplashParticleXML, MainWindow::onMenuFileLoadSplashParticleXML)
|
||||
EVT_MENU(miFileClearAll, MainWindow::onMenuFileClearAll)
|
||||
EVT_MENU(miFileSaveScreenshot, MainWindow::onMenuFileSaveScreenshot)
|
||||
EVT_MENU(wxID_EXIT, MainWindow::onMenuFileExit)
|
||||
|
||||
EVT_MENU(miModeWireframe, MainWindow::onMenuModeWireframe)
|
||||
|
@ -945,6 +994,8 @@ BEGIN_EVENT_TABLE(MainWindow, wxFrame)
|
|||
EVT_MENU(miColorCyan, MainWindow::onMenuColorCyan)
|
||||
EVT_MENU(miColorOrange, MainWindow::onMenuColorOrange)
|
||||
EVT_MENU(miColorMagenta, MainWindow::onMenuColorMagenta)
|
||||
|
||||
EVT_MENU(miChangeBackgroundColor, MainWindow::OnChangeColor)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
// =====================================================
|
||||
|
|
|
@ -5,6 +5,8 @@
|
|||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/glcanvas.h>
|
||||
//#include <wx/clrpicker.h>
|
||||
#include <wx/colordlg.h>
|
||||
|
||||
#include "renderer.h"
|
||||
#include "util.h"
|
||||
|
@ -36,12 +38,14 @@ public:
|
|||
miFileLoadProjectileParticleXML,
|
||||
miFileLoadSplashParticleXML,
|
||||
miFileClearAll,
|
||||
miFileSaveScreenshot,
|
||||
miModeWireframe,
|
||||
miModeNormals,
|
||||
miModeGrid,
|
||||
miSpeedSlower,
|
||||
miSpeedFaster,
|
||||
miRestart,
|
||||
miChangeBackgroundColor,
|
||||
miColorRed,
|
||||
miColorBlue,
|
||||
miColorGreen,
|
||||
|
@ -65,6 +69,8 @@ private:
|
|||
wxMenu *menuCustomColor;
|
||||
wxFileDialog *fileDialog;
|
||||
|
||||
wxColourDialog *colorPicker;
|
||||
|
||||
Model *model;
|
||||
|
||||
std::vector<string> modelPathList;
|
||||
|
@ -108,6 +114,7 @@ public:
|
|||
void onMenuFileLoadProjectileParticleXML(wxCommandEvent &event);
|
||||
void onMenuFileLoadSplashParticleXML(wxCommandEvent &event);
|
||||
void onMenuFileClearAll(wxCommandEvent &event);
|
||||
void onMenuFileSaveScreenshot(wxCommandEvent &event);
|
||||
void onMenuFileExit(wxCommandEvent &event);
|
||||
void onMenuModeNormals(wxCommandEvent &event);
|
||||
void onMenuModeWireframe(wxCommandEvent &event);
|
||||
|
@ -115,6 +122,7 @@ public:
|
|||
void onMenuSpeedSlower(wxCommandEvent &event);
|
||||
void onMenuSpeedFaster(wxCommandEvent &event);
|
||||
void onMenuRestart(wxCommandEvent &event);
|
||||
void OnChangeColor(wxCommandEvent &event);
|
||||
void onMenuColorRed(wxCommandEvent &event);
|
||||
void onMenuColorBlue(wxCommandEvent &event);
|
||||
void onMenuColorGreen(wxCommandEvent &event);
|
||||
|
|
|
@ -71,7 +71,7 @@ void MeshCallbackTeamColor::execute(const Mesh *mesh){
|
|||
// class Renderer
|
||||
// ===============================================
|
||||
|
||||
Renderer::Renderer(){
|
||||
Renderer::Renderer() {
|
||||
normals= false;
|
||||
wireframe= false;
|
||||
grid= true;
|
||||
|
@ -79,9 +79,15 @@ Renderer::Renderer(){
|
|||
textureManager = NULL;
|
||||
particleRenderer = NULL;
|
||||
modelManager = NULL;
|
||||
width=0;
|
||||
height=0;
|
||||
red = 0.3f;
|
||||
green = 0.3f;
|
||||
blue = 0.3f;
|
||||
alpha = 1.0f;
|
||||
}
|
||||
|
||||
Renderer::~Renderer(){
|
||||
Renderer::~Renderer() {
|
||||
delete modelRenderer;
|
||||
delete textureManager;
|
||||
delete particleRenderer;
|
||||
|
@ -91,12 +97,12 @@ Renderer::~Renderer(){
|
|||
delete modelManager;
|
||||
}
|
||||
|
||||
Renderer * Renderer::getInstance(){
|
||||
Renderer * Renderer::getInstance() {
|
||||
static Renderer * renderer = new Renderer();
|
||||
return renderer;
|
||||
}
|
||||
|
||||
void Renderer::transform(float rotX, float rotY, float zoom){
|
||||
void Renderer::transform(float rotX, float rotY, float zoom) {
|
||||
assertGl();
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
@ -109,11 +115,9 @@ void Renderer::transform(float rotX, float rotY, float zoom){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::checkGlCaps(){
|
||||
|
||||
void Renderer::checkGlCaps() {
|
||||
//opengl 1.3
|
||||
if(!isGlVersionSupported(1, 3, 0)){
|
||||
|
||||
if(!isGlVersionSupported(1, 3, 0)) {
|
||||
string message;
|
||||
|
||||
message += "Your system supports OpenGL version \"";
|
||||
|
@ -125,13 +129,13 @@ void Renderer::checkGlCaps(){
|
|||
}
|
||||
|
||||
//opengl 1.4 or extension
|
||||
if(!isGlVersionSupported(1, 4, 0)){
|
||||
if(isGlVersionSupported(1, 4, 0) == false) {
|
||||
checkExtension("GL_ARB_texture_env_crossbar", "MegaGlest");
|
||||
}
|
||||
}
|
||||
|
||||
void Renderer::checkExtension(const string &extension, const string &msg){
|
||||
if(!isGlExtensionSupported(extension.c_str())){
|
||||
void Renderer::checkExtension(const string &extension, const string &msg) {
|
||||
if(isGlExtensionSupported(extension.c_str()) == false) {
|
||||
string str= "OpenGL extension not supported: " + extension + ", required for " + msg;
|
||||
throw runtime_error(str);
|
||||
}
|
||||
|
@ -147,11 +151,19 @@ Model * Renderer::getNewModel() {
|
|||
return newModel;
|
||||
}
|
||||
|
||||
void Renderer::init(){
|
||||
assertGl();
|
||||
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();
|
||||
}
|
||||
|
||||
//!!!glInitNames();
|
||||
//!!!checkGlCaps();
|
||||
void Renderer::init() {
|
||||
assertGl();
|
||||
|
||||
GraphicsFactory *gf= new GraphicsFactoryGl();
|
||||
GraphicsInterface::getInstance().setFactory(gf);
|
||||
|
@ -206,7 +218,7 @@ void Renderer::init(){
|
|||
customTextureMagenta->getPixmap()->init(1, 1, 3);
|
||||
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);
|
||||
glFrontFace(GL_CW);
|
||||
glEnable(GL_CULL_FACE);
|
||||
|
@ -230,9 +242,12 @@ void Renderer::init(){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::reset(int w, int h, PlayerColor playerColor){
|
||||
void Renderer::reset(int w, int h, PlayerColor playerColor) {
|
||||
assertGl();
|
||||
|
||||
width=w;
|
||||
height=h;
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glViewport(0, 0, w, h);
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
@ -243,7 +258,7 @@ void Renderer::reset(int w, int h, PlayerColor playerColor){
|
|||
glTranslatef(0, -1.5, -5);
|
||||
|
||||
Texture2D *customTexture;
|
||||
switch(playerColor){
|
||||
switch(playerColor) {
|
||||
case pcRed:
|
||||
customTexture= customTextureRed;
|
||||
break;
|
||||
|
@ -273,13 +288,13 @@ void Renderer::reset(int w, int h, PlayerColor playerColor){
|
|||
}
|
||||
meshCallbackTeamColor.setTeamTexture(customTexture);
|
||||
|
||||
if(wireframe){
|
||||
if(wireframe) {
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_LIGHT0);
|
||||
}
|
||||
else{
|
||||
else {
|
||||
glEnable(GL_TEXTURE_2D);
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
|
@ -289,10 +304,9 @@ void Renderer::reset(int w, int h, PlayerColor playerColor){
|
|||
assertGl();
|
||||
}
|
||||
|
||||
void Renderer::renderGrid(){
|
||||
if(grid){
|
||||
|
||||
float i;
|
||||
void Renderer::renderGrid() {
|
||||
if(grid) {
|
||||
float i=0;
|
||||
|
||||
assertGl();
|
||||
|
||||
|
@ -302,11 +316,11 @@ void Renderer::renderGrid(){
|
|||
|
||||
glBegin(GL_LINES);
|
||||
glColor3f(1.0f, 1.0f, 1.0f); // gridcolor constant
|
||||
for(i=-10.0f; i<=10.0f; i+=1.0f){
|
||||
for(i=-10.0f; i<=10.0f; i+=1.0f) {
|
||||
glVertex3f(i, 0.0f, 10.0f);
|
||||
glVertex3f(i, 0.0f, -10.0f);
|
||||
}
|
||||
for(i=-10.0f; i<=10.0f; i+=1.0f){
|
||||
for(i=-10.0f; i<=10.0f; i+=1.0f) {
|
||||
glVertex3f(10.f, 0.0f, i);
|
||||
glVertex3f(-10.f, 0.0f, i);
|
||||
}
|
||||
|
@ -318,32 +332,32 @@ void Renderer::renderGrid(){
|
|||
}
|
||||
}
|
||||
|
||||
void Renderer::toggleNormals(){
|
||||
void Renderer::toggleNormals() {
|
||||
normals= normals? false: true;
|
||||
}
|
||||
|
||||
void Renderer::toggleWireframe(){
|
||||
void Renderer::toggleWireframe() {
|
||||
wireframe= wireframe? false: true;
|
||||
}
|
||||
|
||||
void Renderer::toggleGrid(){
|
||||
void Renderer::toggleGrid() {
|
||||
grid= grid? false: true;
|
||||
}
|
||||
|
||||
void Renderer::loadTheModel(Model *model, string file){
|
||||
void Renderer::loadTheModel(Model *model, string file) {
|
||||
model->setTextureManager(textureManager);
|
||||
model->loadG3d(file);
|
||||
textureManager->init();
|
||||
modelManager->init();
|
||||
}
|
||||
|
||||
void Renderer::renderTheModel(Model *model, float f){
|
||||
void Renderer::renderTheModel(Model *model, float f) {
|
||||
if(model != NULL){
|
||||
modelRenderer->begin(true, true, !wireframe, &meshCallbackTeamColor);
|
||||
model->updateInterpolationData(f, true);
|
||||
modelRenderer->render(model);
|
||||
|
||||
if(normals){
|
||||
if(normals) {
|
||||
glPushAttrib(GL_ENABLE_BIT);
|
||||
glDisable(GL_LIGHTING);
|
||||
glDisable(GL_TEXTURE_2D);
|
||||
|
@ -356,15 +370,15 @@ void Renderer::renderTheModel(Model *model, float f){
|
|||
}
|
||||
}
|
||||
|
||||
void Renderer::manageParticleSystem(ParticleSystem *particleSystem){
|
||||
void Renderer::manageParticleSystem(ParticleSystem *particleSystem) {
|
||||
particleManager->manage(particleSystem);
|
||||
}
|
||||
|
||||
void Renderer::updateParticleManager(){
|
||||
void Renderer::updateParticleManager() {
|
||||
particleManager->update();
|
||||
}
|
||||
|
||||
void Renderer::renderParticleManager(){
|
||||
void Renderer::renderParticleManager() {
|
||||
glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
|
||||
glDepthFunc(GL_LESS);
|
||||
particleRenderer->renderManager(particleManager, modelRenderer);
|
||||
|
@ -420,4 +434,17 @@ void Renderer::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
|
||||
|
|
|
@ -79,6 +79,9 @@ private:
|
|||
bool normals;
|
||||
bool grid;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
|
||||
ModelRenderer *modelRenderer;
|
||||
TextureManager *textureManager;
|
||||
ParticleRenderer *particleRenderer;
|
||||
|
@ -96,6 +99,11 @@ private:
|
|||
Texture2D *customTextureMagenta;
|
||||
MeshCallbackTeamColor meshCallbackTeamColor;
|
||||
|
||||
float red;
|
||||
float green;
|
||||
float blue;
|
||||
float alpha;
|
||||
|
||||
Renderer();
|
||||
void checkGlCaps();
|
||||
void checkExtension(const string &extension, const string &msg);
|
||||
|
@ -135,6 +143,9 @@ public:
|
|||
void initModelManager();
|
||||
|
||||
void end();
|
||||
|
||||
void setBackgroundColor(float red, float green, float blue, float alpha);
|
||||
void saveScreen(const string &path);
|
||||
};
|
||||
|
||||
}}//end namespace
|
||||
|
|
Loading…
Reference in New Issue