コード例 #1
0
void DrawBlur(int times, float inc)								/* Draw The Blurred Image */
{
	unsigned int width,height;
	int num;
	float spost = 0.0f;											/* Starting Texture Coordinate Offset */
	float alphainc = 0.9f / times;								/* Fade Speed For Alpha Blending */
	float alpha = 0.2f;											/* Starting Alpha Value */

	getScreenSize(&width,&height);								/* Get actual screen size */
	/* Disable AutoTexture Coordinates */
	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

	glEnable(GL_TEXTURE_2D);									/* Enable 2D Texture Mapping */
	glDisable(GL_DEPTH_TEST);									/* Disable Depth Testing */
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);							/* Set Blending Mode */
	glEnable(GL_BLEND);											/* Enable Blending */
	glBindTexture(GL_TEXTURE_2D,BlurTexture);					/* Bind To The Blur Texture */
	ViewOrtho();												/* Switch To An Ortho View */

	alphainc = alpha / times;									/* alphainc=0.2f / Times To Render Blur */

	glBegin(GL_QUADS);											/* Begin Drawing Quads */
	for (num = 0;num < times;num++)								/* Number Of Times To Render Blur */
	{
		glColor4f(1.0f, 1.0f, 1.0f, alpha);						/* Set The Alpha Value (Starts At 0.2) */
		glTexCoord2f(0+spost,1-spost);							/* Texture Coordinate	( 0, 1 ) */
		glVertex2f(0,0);										/* First Vertex		(   0,   0 ) */

		glTexCoord2f(0+spost,0+spost);							/* Texture Coordinate	( 0, 0 ) */
		glVertex2f(0,height);									/* Second Vertex	(   0, height ) */

		glTexCoord2f(1-spost,0+spost);							/* Texture Coordinate	( 1, 0 ) */
		glVertex2f(width,height);								/* Third Vertex		( width, height ) */

		glTexCoord2f(1-spost,1-spost);							/* Texture Coordinate	( 1, 1 ) */
		glVertex2f(width,0);									/* Fourth Vertex	( width,   0 ) */

		spost += inc;											/* Gradually Increase spost (Zooming Closer To Texture Center) */
		alpha = alpha - alphainc;								/* Gradually Decrease alpha (Gradually Fading Image Out) */
	}
	glEnd();													/* Done Drawing Quads */

	ViewPerspective();											/* Switch To A Perspective View */

	glEnable(GL_DEPTH_TEST);									/* Enable Depth Testing */
	glDisable(GL_TEXTURE_2D);									/* Disable 2D Texture Mapping */
	glDisable(GL_BLEND);										/* Disable Blending */
	glBindTexture(GL_TEXTURE_2D,0);								/* Unbind The Blur Texture */
}
コード例 #2
0
ファイル: AboutWindow.cpp プロジェクト: ldematte/beppe
//
// Idle processing: ovvero cosa fare quando non hai nient'altro
// da fare
//
long AboutWindow::onIdle(FXObject* , FXSelector, void* )
{
  IdleHandle = NULL;

  int w = OGLCanvas->getWidth();
	int h = OGLCanvas->getHeight();

	if (!GLInitialized)
	{
		if(onOGLConfigure(NULL, 0, NULL))
			GLInitialized = true;
		else
			return 0;
	}

	if (!OGLCanvas->makeCurrent())
		return 0;	
	
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  
  if (delta > 3100.0f)
  {
    startTime = getTime();
    ++nShow;                                                                                                                                                    
    if (nShow > 3) nShow = 0;                                                                                                                                         if (nShow == 3 && hehe) nShow = 99;
  }
  delta = ((getTime() - startTime) / 4.0f);
  ViewPerspective(w, h);

  glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);


  glColor3f(1.0f, 1.0f, 1.0f);
  RenderToTexture(w, h);	
  DrawBlur(10, 0.03f, w, h);
  
  glColor3ub(255, 240, 32);
  glEnable(GL_TEXTURE_2D);
  DrawWorld();

  
  glFlush();
	OGLCanvas->swapBuffers();
	OGLCanvas->makeNonCurrent();

  IdleHandle = getApp()->addChore(this, ID_IDLE);
	return 1;
}
コード例 #3
0
ファイル: AboutWindow.cpp プロジェクト: ldematte/beppe
//
// Inizilizza i parametri OpenGL
//
long AboutWindow::onOGLConfigure (FXObject* , FXSelector, void* )
{
	if (!OGLCanvas->makeCurrent())
		return 0;

	int w = OGLCanvas->getWidth();
	int h = OGLCanvas->getHeight();
	glViewport(0, 0, w, h);

  glShadeModel(GL_SMOOTH);		
  glEnable(GL_TEXTURE_2D);
	glDisable(GL_DEPTH_TEST);

  if (font)
    delete font;

  font = new FTGLTextureFont;//FTGLPixmapFont;//FTGLTextureFont;//FTGLPolygonFont;
  bool fontInit = false;

  if(!font->Open(fontfile, false))
    Logger::getInstance()->addf("Editor :: Failed to open font %s", fontfile);
  else
  {
    if(!font->FaceSize(144))
      Logger::getInstance()->add("Editor :: Failed to set size");
    
    else
    {
      font->Depth(20);
	    font->CharMap(ft_encoding_unicode);
      fontInit = true;
    }
  }

  if (!fontInit)
  {
    delete font;
    font = NULL;
  }

  if (BlurTexture == 0)
    BlurTexture = TextureMgr::getInstance()->EmptyTexture(128);

  ViewPerspective(w, h);

	OGLCanvas->makeNonCurrent();

	return 1;
}
コード例 #4
0
ファイル: AboutWindow.cpp プロジェクト: ldematte/beppe
//
// Renderizza la scena sfumata 
// Parametri: times: numero di volte in cui renderizzare la texture
//                   della scena; piu' volte, piu' lento ma piu' bello!
//                   se avete un pc decente, provate qualcosa come 25
//            inc: l'incremento del canale alpha (diminuizione trasparenza)
//                 ad ogni giro del disegno
//            w, h: larghezza e altezza della finestra
//
inline void AboutWindow::DrawBlur(int times, float inc, int w, int h)
{
	float spost = 0.0f;               // Starting Texture Coordinate Offset
	float alphainc = 0.9f / times;    // Fade Speed For Alpha Blending
	float alpha = 0.3f;              // Starting Alpha Value

	// Disable AutoTexture Coordinates
	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

	glEnable(GL_TEXTURE_2D);                  
	glDisable(GL_DEPTH_TEST);									
  glBlendFunc(GL_SRC_ALPHA, GL_ONE);					
	glEnable(GL_BLEND);											  
	glBindTexture(GL_TEXTURE_2D, BlurTexture);

	ViewOrtho(w, h);												      

	alphainc = alpha / times;									

	glBegin(GL_QUADS);											  
		for (int num = 0; num < times; ++num) 
		{
			glColor4f(1.0f, 1.0f, 1.0f, alpha);					
			glTexCoord2f(spost, 1 - spost);						
			glVertex2f(0, 0);									

			glTexCoord2f(spost, spost);						
			glVertex2f(0, h);								

			glTexCoord2f(1 - spost, spost);
			glVertex2f(w, h);								

			glTexCoord2f(1 - spost, 1 - spost);			
			glVertex2f(w, 0);									

			spost += inc;										
			alpha = alpha - alphainc;			
		}
	glEnd();				

  ViewPerspective(w, h);	
	

	glEnable(GL_DEPTH_TEST);								
	glDisable(GL_TEXTURE_2D);								
	glDisable(GL_BLEND);									
	glBindTexture(GL_TEXTURE_2D, 0);							
}
コード例 #5
0
void DrawBlur(int times, float inc)								// Draw The Blurred Image
{
	float spost = 0.0f;											// Starting Texture Coordinate Offset
	float alphainc = 0.3f / times;								// Fade Speed For Alpha Blending
	float alpha = 0.1f;											// Starting Alpha Value
    int num = 0;

	// Disable AutoTexture Coordinates
	glDisable(GL_TEXTURE_GEN_S);
	glDisable(GL_TEXTURE_GEN_T);

	glEnable(GL_TEXTURE_2D);									// Enable 2D Texture Mapping
	glDisable(GL_DEPTH_TEST);									// Disable Depth Testing
	glBlendFunc(GL_SRC_ALPHA,GL_ONE);							// Set Blending Mode
	//glBlendFunc(GL_ONE,GL_ONE);							// Set Blending Mode
	glEnable(GL_BLEND);											// Enable Blending
	glBindTexture(GL_TEXTURE_2D,BlurTexture);					// Bind To The Blur Texture
	ViewOrtho();												// Switch To An Ortho View

	alphainc = alpha / times;									// alphainc=0.2f / Times To Render Blur

	glBegin(GL_QUADS);											// Begin Drawing Quads
		for (num = 0;num < times;num++)						// Number Of Times To Render Blur
		{
			glColor4f(1.0f, 1.0f, 1.0f, alpha);					// Set The Alpha Value (Starts At 0.2)
			glTexCoord2f(0+spost,1-spost);						// Texture Coordinate	( 0, 1 )
			glVertex2f(0,0);									// First Vertex		(   0,   0 )

			glTexCoord2f(0+spost,0+spost);						// Texture Coordinate	( 0, 0 )
			glVertex2f(0,480);									// Second Vertex	(   0, 480 )

			glTexCoord2f(1-spost,0+spost);						// Texture Coordinate	( 1, 0 )
			glVertex2f(640,480);								// Third Vertex		( 640, 480 )

			glTexCoord2f(1-spost,1-spost);						// Texture Coordinate	( 1, 1 )
			glVertex2f(640,0);									// Fourth Vertex	( 640,   0 )

			spost += inc;										// Gradually Increase spost (Zooming Closer To Texture Center)
			alpha = alpha - alphainc;							// Gradually Decrease alpha (Gradually Fading Image Out)
		}
	glEnd();													// Done Drawing Quads

	ViewPerspective();											// Switch To A Perspective View

	glEnable(GL_DEPTH_TEST);									// Enable Depth Testing
	glDisable(GL_TEXTURE_2D);									// Disable 2D Texture Mapping
	glDisable(GL_BLEND);										// Disable Blending
	glBindTexture(GL_TEXTURE_2D,0);								// Unbind The Blur Texture
}
コード例 #6
0
ファイル: gui.cpp プロジェクト: HellSinker/nwncx
void DrawOverlay(void)
{
	glDisable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	glColor3f(1.0f,1.0f,1.0f);
	ViewOrtho(500, 500);
	glBegin(GL_QUADS);
	glVertex2f(0, 0);
	glVertex2f(0, 100);
	glVertex2f(100, 100);
	glVertex2f(100, 0);
	glEnd();
	ViewPerspective();
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_TRUE);
}
コード例 #7
0
ファイル: dcLevel.cpp プロジェクト: dreamycactus/archived
void drawBlur(int times, float inc)
{
    float spost = 0.0f;             // Starting texture coordinates
    float alphainc = 0.9f / times;  // Fade speed for blending
    float alpha = 0.2f;             // Starting alpha

    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);

    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE);
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D, blur_texture);

    ViewOrtho();

    alphainc = alpha / times;
    glBegin(GL_QUADS);
        for (uint i=0; i<times; ++i)
        {
            glColor4f(1.0f, 1.0f, 1.0f, alpha);
            glTexCoord2f(0+spost, 1-spost);
            glVertex2f(0,0);

            glTexCoord2f(0+spost, 0+spost);
            glVertex2f(0, HEIGHT);

            glTexCoord2f(1-spost, 0+spost);
            glVertex2f(WIDTH, HEIGHT);

            glTexCoord2f(1-spost, 1-spost);
            glVertex2f(WIDTH, 0);

            spost += inc;
            alpha -= alphainc;
        }
    glEnd();

    ViewPerspective();

    glEnable(GL_DEPTH_TEST);                    // Enable Depth Testing
    glDisable(GL_TEXTURE_2D);                   // Disable 2D Texture Mapping
    glDisable(GL_BLEND);                        // Disable Blending
    glBindTexture(GL_TEXTURE_2D,0);                 // Unbind The Blur Texture
}
コード例 #8
0
void NEHE36::DrawBlur(int times, float inc){
    float spost = 0.0f;
    float alphainc = 0.9f / times;
    float alpha = 0.2f;
	
    // Disable AutoTexture Coordinates
    glDisable(GL_TEXTURE_GEN_S);
    glDisable(GL_TEXTURE_GEN_T);
	
    glEnable(GL_TEXTURE_2D);
    glDisable(GL_DEPTH_TEST);
    glBlendFunc(GL_SRC_ALPHA,GL_ONE);
    glEnable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D,BlurTexture);
    ViewOrtho();
	
    alphainc = alpha / times;
	glBegin(GL_QUADS);
	for (int num = 0;num < times;num++){
		glColor4f(1.0f, 1.0f, 1.0f, alpha);
		glTexCoord2f(0+spost,1-spost);
		glVertex2f(0,0);
		
		glTexCoord2f(0+spost,0+spost);
		glVertex2f(0,480);
		
		glTexCoord2f(1-spost,0+spost);
		glVertex2f(640,480);
		
		glTexCoord2f(1-spost,1-spost);
		glVertex2f(640,0);
		
		spost += inc;
		alpha = alpha - alphainc;
	}
    glEnd();
	
    ViewPerspective();
	
    glEnable(GL_DEPTH_TEST);
    glDisable(GL_TEXTURE_2D);
    glDisable(GL_BLEND);
    glBindTexture(GL_TEXTURE_2D,0);
}
コード例 #9
0
void VoxCad::EnterVMMode(AppViewMode NewMode, bool Force) //switch between viewing modes!
{
	//check to see if we want to abandom analysis!
	if (CurViewMode == NewMode) return;

	//handle any de-initialization of the old mode
	switch (CurViewMode){
	case VM_3DVIEW:
		break;
	case VM_EDITLAYER:
		ViewRef3DWindow(false);
		SetSectionView(false);

		ui.actionEdit_Voxels->setChecked(false);
		ui.actionPerspective->setEnabled(true);
		ui.actionSection_View->setEnabled(true);

		ui.actionPencil->setEnabled(false);
		ui.actionRectangle->setEnabled(false);
		ui.actionCircle->setEnabled(false);

		break;
	case VM_EDITBCS:
		ViewBCsWindow(false);
		ui.actionBCs->setChecked(false);
		break;
	case VM_FEA:
		//if we don't want to abandon the results, intervene here
		if (!Force && QMessageBox::question(NULL, "Exiting simulation", "Do you want to exit the simulation and discard results?", QMessageBox::Ok | QMessageBox::Cancel)==QMessageBox::Cancel){
			ui.actionSolve->setChecked(true); //reset the button
			ViewFEAInfoWindow(true); 
			return;
		}

		ViewFEAInfoWindow(false);
		ui.actionSolve->setChecked(false); //reset the button
		WorkspaceDlg->setEnabled(true);
		PaletteDlg->setEnabled(true);
		MainFEA.ResetFEA();

		break;
	case VM_PHYSICS:
		//stop the simulation if it hasn't been alraedy...
		MainSim.EndSim();

		ViewPhysicsWindow(false);
		WorkspaceDlg->setEnabled(true);
		ui.actionPhysics->setChecked(false);


		break;
	}
	
	//enter the new mode!
	switch (NewMode){
	case VM_3DVIEW:
		CurViewMode = VM_3DVIEW;
		ViewPerspective(false);
		break;
	case VM_EDITLAYER:
		CurViewMode = VM_EDITLAYER;
		ViewTop(false);
		ui.actionEdit_Voxels->setChecked(true);

		ui.actionPerspective->setEnabled(false);
		ui.actionSection_View->setEnabled(false);
		SetSectionView(true);

		ui.actionPencil->setEnabled(true);
		ui.actionRectangle->setEnabled(true);
		ui.actionCircle->setEnabled(true);

		//open the correct windowa:
		ViewPaletteWindow(true);
		ViewRef3DWindow(true);

		break;
	case VM_EDITBCS:
		CurViewMode = VM_EDITBCS;
		ViewPerspective(false);
		
		ui.actionBCs->setChecked(true);

		ViewBCsWindow(true);

		break;
	case VM_FEA:
		CurViewMode = VM_FEA;
		ViewPerspective(false);
		
		ui.actionSolve->setChecked(true);

		FEAInfoDlg->UpdateUI();
		WorkspaceDlg->setEnabled(false);
		PaletteDlg->setEnabled(false);
		ViewFEAInfoWindow(true);
		FEAInfoDlg->UpdateUI();

		break;
	case VM_PHYSICS:
		CurViewMode = VM_PHYSICS;
		ViewPerspective(false);
		ui.actionPhysics->setChecked(true);

		//update ui of dialog I think...

		WorkspaceDlg->setEnabled(false);


		PhysicsDlg->UpdateUI();
		ViewPhysicsWindow(true);
		MainSim.RequestBeginSim();


		break;
	}

	//Things to do regardless
	SetGLSelected(); //reset selection
	ZoomExtAll();
}
コード例 #10
0
VoxCad::VoxCad(QWidget *parent, Qt::WFlags flags)
	: QMainWindow(parent, flags)
{
	//setup main object and FEA
	MainEnv.pObj = &MainObj; //connect environment to object
	MainFEA.pEnv = &MainEnv; //connect FEA to envirnment
	MainSim.pEnv = &MainEnv; //connect Simulation to envirnment
	connect(&MainObj, SIGNAL(UpdateGLWindows()), this, SLOT(ReqGLUpdateAll()));
	connect(&MainObj, SIGNAL(GetCurGLSelected(int*)), this, SLOT(GetCurGLSelected(int*)));
	connect(&MainFEA, SIGNAL(GetCurGLSelected(int*)), this, SLOT(GetCurGLSelected(int*)));
	connect(&MainFEA, SIGNAL(SolveResult(bool)), this, SLOT(FEAMode(bool))); //allows FEA solve to call back, decide whether to enter mode or not

	CurGLSelected = -1;

	ui.setupUi(this);
	SetupGLWindow();
	SetupVoxInfoWindow();
	SetupPaletteWindow();
	SetupWorkspaceWindow();
	SetupBCWindow();
	SetupFEAInfoWindow();
	SetupRef3DWindow();
	SetupPhysicsWindow();

	//set up initial application toolbox configuration
	tabifyDockWidget(PhysicsDockWidget, FEAInfoDockWidget);
	tabifyDockWidget(FEAInfoDockWidget, BCDockWidget);
	tabifyDockWidget(BCDockWidget, WorkspaceDockWidget);
	tabifyDockWidget(WorkspaceDockWidget, PaletteDockWidget);

	//Connect Menus:
	//File
	connect(ui.actionNew, SIGNAL(triggered()), this, SLOT(New()));
	connect(ui.actionOpen, SIGNAL(triggered()), this, SLOT(OpenVXC()));
	connect(ui.actionSave, SIGNAL(triggered()), &MainObj, SLOT(SaveZLib()));
	connect(ui.actionSave_As, SIGNAL(triggered()), &MainObj, SLOT(SaveAsZLib()));
	//..Import
	connect(ui.actionVXA_IN, SIGNAL(triggered()), this, SLOT(ImportVXA()));
	//..Export
	connect(ui.actionVXA_OUT, SIGNAL(triggered()), &MainSim, SLOT(SaveVXA()));
	#ifdef DMU_ENABLED
	connect(ui.actionDMU_Out, SIGNAL(triggered()), this, SLOT(ExportDMU()));
	#endif
	//....Mesh
	connect(ui.actionSTL, SIGNAL(triggered()), &MainObj, SLOT(ExportSTL()));
	//....Alternate VXC
	connect(ui.actionASCII_VXC, SIGNAL(triggered()), &MainObj, SLOT(SaveAsAsciiReadable()));
	connect(ui.actionBASE64_VXC, SIGNAL(triggered()), &MainObj, SLOT(SaveAsBase64()));

	//Edit
	connect(ui.actionCopy, SIGNAL(triggered()), this, SLOT(Copy()));
	connect(ui.actionCut, SIGNAL(triggered()), this, SLOT(Cut()));
	connect(ui.actionPaste, SIGNAL(triggered()), this, SLOT(Paste()));
	connect(ui.actionWorkspace, SIGNAL(toggled(bool)), this, SLOT(ViewWorkspaceWindow(bool)));
	connect(ui.actionPalette, SIGNAL(toggled(bool)), this, SLOT(ViewPaletteWindow(bool)));

	//View
	connect(ui.actionCenter_View, SIGNAL(triggered()), GLWindow, SLOT(ZoomExtents()));
	connect(ui.actionLarge_Mode, SIGNAL(triggered(bool)), GLWindow, SLOT(EnterFastMode(bool)));
	//..Standard Views
	connect(ui.actionPerspective, SIGNAL(triggered()), this, SLOT(ViewPerspective()));
	connect(ui.actionTop, SIGNAL(triggered()), this, SLOT(ViewTop()));
	connect(ui.actionBottom, SIGNAL(triggered()), this, SLOT(ViewBottom()));
	connect(ui.actionLeft, SIGNAL(triggered()), this, SLOT(ViewLeft()));
	connect(ui.actionRight, SIGNAL(triggered()), this, SLOT(ViewRight()));
	connect(ui.actionFront, SIGNAL(triggered()), this, SLOT(ViewFront()));
	connect(ui.actionBack, SIGNAL(triggered()), this, SLOT(ViewBack()));
	//..Section View
	connect(ui.actionSection_View, SIGNAL(toggled(bool)), this, SLOT(SetSectionView(bool)));
	connect(ui.actionLayer_Back, SIGNAL(triggered()), &MainObj, SLOT(LayerBack()));
	connect(ui.actionLayer_Forward, SIGNAL(triggered()), &MainObj, SLOT(LayerForward()));
	//--
	connect(ui.actionReference_View, SIGNAL(toggled(bool)), this, SLOT(ViewRef3DWindow(bool)));
	connect(ui.actionInfo, SIGNAL(toggled(bool)), this, SLOT(ViewVoxInfoWindow(bool)));
	
	//Tools
	connect(ui.actionEdit_Voxels, SIGNAL(toggled(bool)), this, SLOT(EditMode(bool)));
	//..Drawing
	connect(ui.actionPencil, SIGNAL(triggered()), &MainObj, SLOT(SetDrawPencil()));
	connect(ui.actionRectangle, SIGNAL(triggered()), &MainObj, SLOT(SetDrawRectangle()));
	connect(ui.actionCircle, SIGNAL(triggered()), &MainObj, SLOT(SetDrawCircle()));

	//Analyze
	connect(ui.actionBCs, SIGNAL(triggered(bool)), this, SLOT(BCsMode(bool))); //triggered (vs toggled) avoids getting called when setcheck is called.
	connect(ui.actionSolve, SIGNAL(triggered(bool)), this, SLOT(RequestFEAMode(bool))); //triggered (vs toggled) avoids getting called when setcheck is called.
	connect(ui.actionPhysics, SIGNAL(triggered(bool)), this, SLOT(PhysicsMode(bool))); //triggered (vs toggled) avoids getting called when setcheck is called.

	//Menu groups:
	DrawGroup = new QActionGroup(this);
	DrawGroup->addAction(ui.actionPencil);
	DrawGroup->addAction(ui.actionRectangle);
	DrawGroup->addAction(ui.actionCircle);
	ui.actionPencil->setChecked(true);


	//initialize other random stuff
	SetSectionView(false);
	New(); //creates new object to start with

	CurViewMode = VM_NONE; //so 3DView will be a new mode!
	EnterVMMode(VM_3DVIEW);


	//redirect cout:
	//	http://www.qtcentre.org/threads/17880-Display-content-wirtten-to-STL-ostream-dynamically
	//std::ostream myWidget(;
	//std::streambuf *oldbuf = std::cout.rdbuf(myWidget.rdbuf());
}
コード例 #11
0
void VoxCad::EnterVMMode(AppViewMode NewMode, bool Force) //switch between viewing modes!
{
	//check to see if we want to abandom analysis!
	if (CurViewMode == NewMode) return;

	//handle any de-initialization of the old mode
	switch (CurViewMode){
	case VM_3DVIEW:
		break;
	case VM_EDITLAYER:
		ViewRef3DWindow(false);
		SetSectionView(false);

		ui.actionEdit_Voxels->setChecked(false);
		ui.actionPerspective->setEnabled(true);
		ui.actionSection_View->setEnabled(true);

		ui.actionPencil->setEnabled(false);
		ui.actionRectangle->setEnabled(false);
		ui.actionCircle->setEnabled(false);

		break;
	case VM_EDITBCS:
		ViewBCsWindow(false);
		ui.actionBCs->setChecked(false);
		break;
	case VM_FEA:
		//if we don't want to abandon the results, intervene here
		if (!Force && QMessageBox::question(NULL, "Exiting simulation", "Do you want to exit the simulation and discard results?", QMessageBox::Ok | QMessageBox::Cancel)==QMessageBox::Cancel){
			ui.actionSolve->setChecked(true); //reset the button
			ViewFEAInfoWindow(true); 
			return;
		}

		ViewFEAInfoWindow(false);
		ui.actionSolve->setChecked(false); //reset the button
		WorkspaceDlg->setEnabled(true);
		PaletteDlg->setEnabled(true);
		MainFEA.ResetFEA();

		break;
	case VM_PHYSICS:
		//stop the simulation if it hasn't been alraedy...
		MainSim.EndSim();

		ViewPhysicsWindow(false);
		WorkspaceDlg->setEnabled(true);
		ui.actionPhysics->setChecked(false);

		GLWindow->bDrawBounds = true;

		break;

	case VM_TENSILE:
		WorkspaceDlg->setEnabled(true);
		PaletteDlg->setEnabled(true);

		ViewTensileWindow(false);
		TensileDlg->setEnabled(true);
		ui.actionTensile->setChecked(false);

		break;
	case VM_3DBRUSH:
		ViewBrushWindow(false);
		ui.action3D_Brush->setChecked(false);
		break;
	}
	
	//enter the new mode!
	switch (NewMode){
	case VM_3DVIEW:
		CurViewMode = VM_3DVIEW;
		ViewPerspective(false);
		break;
	case VM_EDITLAYER:
		CurViewMode = VM_EDITLAYER;
		ViewTop(false);
		ui.actionEdit_Voxels->setChecked(true);

///		ui.actionPerspective->setEnabled(false);
		ui.actionSection_View->setEnabled(false);
		SetSectionView(true);

		ui.actionPencil->setEnabled(true);
		ui.actionRectangle->setEnabled(true);
		ui.actionCircle->setEnabled(true);

		//open the correct windowa:
		ViewPaletteWindow(true);
		ViewRef3DWindow(true);

		break;
	case VM_EDITBCS:
		CurViewMode = VM_EDITBCS;
		ViewPerspective(false);
		
		ui.actionBCs->setChecked(true);

		ViewBCsWindow(true);

		break;
	case VM_FEA:
		CurViewMode = VM_FEA;
		ViewPerspective(false);
		
		ui.actionSolve->setChecked(true);

		FEAInfoDlg->UpdateUI();
		WorkspaceDlg->setEnabled(false);
		PaletteDlg->setEnabled(false);
		ViewFEAInfoWindow(true);
		FEAInfoDlg->UpdateUI();

		break;
	case VM_PHYSICS:
		CurViewMode = VM_PHYSICS;
		ViewPerspective(false);
		ui.actionPhysics->setChecked(true);

		//update ui of dialog?
		GLWindow->bDrawBounds = false;

		WorkspaceDlg->setEnabled(false);

		PhysicsDlg->DeletePlotPoints();
		PhysicsDlg->UpdateUI();
		PhysicsDlg->SetStatusButtonText(true); //A little hacky, but otherwise we'd need to call UpdateUI after we _know_ the thread has started.
		ViewPhysicsWindow(true);
		MainSim.RequestBeginSim();

		break;
	case VM_TENSILE:
		CurViewMode = VM_TENSILE;
		ViewPerspective(false);
		ui.actionTensile->setChecked(true);

		WorkspaceDlg->setEnabled(false);
		PaletteDlg->setEnabled(false);

//		TensileDlg->UpdateUI();
		ViewTensileWindow(true);

		break;
	case VM_3DBRUSH:
		CurViewMode = VM_3DBRUSH;
		ViewPerspective(false);
		
		ui.action3D_Brush->setChecked(true);
		Brush3DDlg->UpdateUI();
		ViewBrushWindow(true);

		break;
	}

	//Things to do regardless
	SetGLSelected(); //reset selection
	ZoomExtAll();
}