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


blort
Author(s): Michael Zillich, Thomas Mörwald, Johann Prankl, Andreas Richtsfeld, Bence Magyar (ROS version)
autogenerated on Thu Jan 2 2014 11:38:26