tgGUI.cpp
Go to the documentation of this file.
00001 
00002 
00003 #include <blort/TomGine/tgGUI.h>
00004 #include <blort/TomGine/tgPlot2D.h>
00005 #include <stdio.h>
00006 #include <GL/gl.h>
00007 
00008 using namespace blortGLWindow;
00009 using namespace TomGine;
00010 
00011 tgGUI::tgGUI(unsigned width, unsigned height)
00012 {
00013         m_width = width;
00014         m_height = height;
00015         
00016         m_window = new GLWindow(width, height, "GUI");
00017 
00018         // Set camera
00019         glMatrixMode(GL_PROJECTION);
00020         glOrtho(0.0, width, 0.0, height, 0.01, 1.0);
00021         float ft[16] = {        1.0f, 0.0f, 0.0f, 0.0f,
00022                                                 0.0f, 1.0f, 0.0f, 0.0f,
00023                                                 0.0f, 0.0f, 1.0f, 0.0f,
00024                                                 0.0f, 0.0f,-1.0f, 1.0};
00025         
00026         glMatrixMode(GL_MODELVIEW);
00027         glLoadMatrixf(ft);
00028 }
00029 
00030 tgGUI::~tgGUI()
00031 {
00032         if(m_window)
00033                 delete(m_window);
00034 }
00035 
00036 bool tgGUI::InputControl(Event &event)
00037 {
00038         switch(event.type){
00039                 
00040                 case TMGL_Press:
00041 //                      printf("event.key.keysym: %x\n", event.key.keysym);
00042                         switch(event.input){
00043                                 case TMGL_Escape:
00044                                         return false;
00045                                         break;
00046                                 default:
00047                                         break;
00048                         }
00049                         break;
00050                         
00051                 case TMGL_Release:
00052 
00053                         break;
00054                         
00055                 case TMGL_Motion:
00056 
00057                         break;
00058                 default:
00059                         break;
00060         } // switch(event.type)
00061 return true;
00062 }
00063 
00064 bool tgGUI::Update()
00065 {
00066         bool quit = true;
00067         Event event;
00068         while(m_window->GetEvent(event)){
00069                 quit = InputControl(event);
00070                 if(quit==false)
00071                         return false;
00072         }
00073         
00074         //for(unsigned i=0; i<m_elements.size(); i++){
00075         //      m_elements[i]->draw();
00076         //}
00077         
00078         m_window->Update();
00079         
00080         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
00081         
00082         return true;
00083 }
00084 
00085 void tgGUI::Screenshot(const char *filename) const
00086 {
00087         char* data = (char*)malloc(3*m_width*m_height);
00088         
00089         glGetTexImage(GL_TEXTURE_2D, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
00090         
00091         FILE *ppm;
00092         ppm = fopen(filename,"w");
00093         fprintf(ppm,"P6\n%u %u\n255\n",m_width,m_height);
00094         fwrite(&data, 1, 3*m_width*m_height, ppm);
00095         fclose(ppm);
00096 }


blort
Author(s): Thomas Mörwald , Michael Zillich , Andreas Richtsfeld , Johann Prankl , Markus Vincze , Bence Magyar
autogenerated on Wed Aug 26 2015 15:24:12