Basic Image AlgorithmS Library  2.8.0
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
ExampleOpenGLCanvas.cpp
1 /** Simple example for BIAS::OpenGLCanvas(Base) usage.
2 @author: Jan Woetzel */
3 
4 #include <bias_config.h>
5 
6 //#include <Base/Common/LeakChecking.h>
7 
8 #include "ExampleOpenGLCanvas.hh"
9 
10 // BIAS
11 #include <Gui/ConsoleRedirectIO.hh>
12 #include <Gui/GeometryGL.hh>
13 
14 using namespace std;
15 
16 // required for wx RTTI dynamic construction:
17 IMPLEMENT_APP(ExampleOpenGLCanvasApp)
18 
19 // --------------------------------------------------------
20 #ifdef BIAS_HAVE_GLUT
21 # define GLUT_BUILDING_LIB
22 # ifdef __APPLE__
23 # include <GLUT/glut.h>
24 # else // __APPLE__
25 # include <GL/glut.h>
26 # endif // __APPLE__
27 #endif // BIAS_HAVE_GLUT
28 
29 
30 ///
31 /// your own implemnetation of the scenes GL calls:
32 ///
33 
34 MyGLCanvas::MyGLCanvas(wxFrame* parent)
35 :
36 BIAS::OpenGLCanvas( parent, -1,wxDefaultPosition, wxDefaultSize,0,wxT("GL"),(int*)(&attribsRGBASD) )
37 {}
38 
39 
40 
41 
42 void MyGLCanvas::DisplayCalls()
43 {
44  //CALLINFO;
45  CHECK_GL_ERROR;
46 
47  DisplayClear();
48  DisplayCameraView();
49  CHECK_GL_ERROR;
50  glClearColor(0.3,0.1,0.1,0);
51  glClear(GL_COLOR_BUFFER_BIT);
52  glMatrixMode(GL_MODELVIEW);
53 
54  // viewport
55  //glViewport(0,0, 512,512);
56 
57  /*
58  // simple vertex array
59  const float v[8][3] =
60  {
61  {-1,-1,-1}
62  ,{ 1,-1,-1}
63  ,{ 1, 1,-1}
64  ,{-1, 1,-1}
65  ,{-1,-1, 1}
66  ,{ 1,-1, 1}
67  ,{ 1, 1, 1}
68  ,{-1, 1, 1}
69  };
70  glColor4f(0,0,1,0.5);
71  glBegin(GL_QUADS);
72  glColor3f(0.6, 0, 0); //r
73  glVertex3fv( v[0] );
74  glVertex3fv( v[1] );
75  glVertex3fv( v[2] );
76  glVertex3fv( v[3] );
77  glColor3f(0, 0.6, 0); //g
78  glVertex3fv( v[4] );
79  glVertex3fv( v[5] );
80  glVertex3fv( v[6] );
81  glVertex3fv( v[7] );
82  glColor3f(0, 0, 0.6); //b
83  glVertex3fv( v[1] );
84  glVertex3fv( v[0] );
85  glVertex3fv( v[4] );
86  glVertex3fv( v[5] );
87  glEnd();
88 */
89 
90 #ifdef BIAS_HAVE_GLUT
91  glColor3f(0.8,0.0,0.8);
92  glutWireTeapot(0.5);
93 #endif // BIAS_HAVE_GLUT
94 
95  this->DisplayCoordCross();
96 
97  //// animated scene
98  //BIAS::GeometryGL::DisplayCallsSampleDisplayListScene(this->time);
99  //CHECK_GL_ERROR;
100 
101  this->GetViewController().GetExternals().DisplayViewAt();
102 
103  /*
104  glColor3f(0.5, 0.5, 0.5);
105  //glutSolidCube(0.1);
106  //glutSolidCube(1.0);
107 
108  glColor3f(0.5, 0, 0);
109  glPushAttrib(GL_POINT_BIT);
110  glPointSize(31);
111  glBegin(GL_POINTS);
112  glVertex3f(0,0,0);
113  glEnd();
114  glPopAttrib();
115 
116  glColor3f(0, 0.5, 0);
117  glPushAttrib(GL_POINT_BIT);
118  glPointSize(7);
119  glBegin(GL_POINTS);
120  glVertex3f(0,0,0);
121  glEnd();
122  glPopAttrib();
123  */
124 
125 }
126 
127 
128 // --------------------------------------------------------
129 
130 bool ExampleOpenGLCanvasApp::OnInit()
131 {
132  // utility: create a Redirection console for cout, cerr etc.
134  // testing output:
135  cout<<"Hello cout"<<endl;
136  cout<<"Hello cerr"<<endl;
137 
138  MyFrame *frame = new MyFrame( wxT("ExampleOpenGLCanvas"), wxPoint(0,0), wxSize(640,480) );
139  frame->Show(TRUE);
140  SetTopWindow(frame);
141 
142  return TRUE;
143 }
144 
145 
146 // --------------------------------------------------------
147 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
148 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
149 EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
150 EVT_MENU(ID_TESTSHOT, MyFrame::OnTestShot)
151 END_EVENT_TABLE()
152 // --------------------------------------------------------
153 
154 
155 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
156 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
157 ,p_canvas(NULL)
158 {
159  // Create a simple top Menu
160  wxMenu *menuFile = new wxMenu;
161  menuFile->Append( ID_ABOUT, wxT("&About...") );
162  menuFile->AppendSeparator();
163  menuFile->Append( ID_TESTSHOT, wxT("&Shot...\tCtrl-S") );
164  menuFile->AppendSeparator();
165  menuFile->Append( ID_QUIT, wxT("E&xit") );
166 
167  wxMenuBar *menuBar = new wxMenuBar;
168  menuBar->Append(menuFile, wxT("&File"));
169  SetMenuBar(menuBar);
170 
171  // Create a simple bottom status bar
172  CreateStatusBar(3);
173 
174  // Canvas to test:
175  //p_canvas=new BIAS::OpenGLCanvas(this, -1);
176  p_canvas=new MyGLCanvas(this);
177 
178  //p_2nd_canvas = new MyGLCanvas(this);
179 }
180 
181 
182 void MyFrame::OnTestShot(wxCommandEvent& /*event*/)
183 {
184  p_canvas->ScreenShot("out_RGB.jpg", true, GL_RGB);
185 
186  p_canvas->ScreenShot("out_RGB.mip", true, GL_RGB);
187  p_canvas->ScreenShot("out_RGBA.mip", true, GL_RGBA);
188  p_canvas->ScreenShot("out_DEPTH.mip", true, GL_DEPTH_COMPONENT);
189  p_canvas->ScreenShot("out_DEPTH.jpg", true, GL_DEPTH_COMPONENT);
190  p_canvas->ScreenShot("out_ALPHA.mip", true, GL_ALPHA);
191  p_canvas->ScreenShot("out_ALPHA.jpg", true, GL_ALPHA);
192  p_canvas->ScreenShot("out_LUMINANCE.mip", true, GL_LUMINANCE);
193  p_canvas->ScreenShot("out_STENCIL.mip", true, GL_STENCIL_INDEX);
194 }
195 
196 
197 void MyFrame::OnQuit(wxCommandEvent& ){
198  Close(TRUE);
199 }
200 
201 
202 void MyFrame::OnAbout(wxCommandEvent& )
203 {
204  wxString title(wxT("About"));
205  wxString msg; // message
206  msg<<wxT("About - ")<<AsciiToWx(FUNCNAME)<<wxT("\n");
207  msg<<wxT("author: Jan Woetzel (c) 2003-2005\n");
208  msg<<wxT("build: ")<<AsciiToWx(__DATE__)<<wxT(" ")<<AsciiToWx(__TIME__)<<wxT("\n");
209  msg<<wxT("from ")<<AsciiToWx(__FILE__)<<wxT("\n");
210  msg<<wxT("GUI using: ")<<wxVERSION_STRING<<wxT("\n");
211  msg<<wxT("\n");
212  COUT(msg);
213  wxMessageBox(msg, title, wxICON_INFORMATION | wxOK );
214 }
215 
void BIASGui_EXPORT ConsoleRedirectIO(std::string name=std::string(""))
Extra Console for WIN32 WinMain gui applications.
wxString AsciiToWx(const char *thestring)
Converts a C string to a wxString.
Definition: StringConv.hh:32
OpenGL canvases with additinal event handling (JW)
Definition: OpenGLCanvas.hh:68
const int attribsRGBASD[]
helper to simplify setting up format &quot;red,green,blue,alpha,stencil,depth&quot; JW to be used as (int*)...