22 #include <bias_config.h>
25 #include "ExampleGLShared.hh"
28 #include <Gui/ConsoleRedirectIO.hh>
29 #include <Gui/GeometryGL.hh>
34 IMPLEMENT_APP(ExampleGLSharedApp)
38 # define GLUT_BUILDING_LIB
40 #endif // BIAS_HAVE_GLUT
47 MyGLCanvas::MyGLCanvas(wxFrame* parent)
54 void MyGLCanvas::InitGeometry()
57 static bool initDone=
false;
63 dplist = glGenLists(1);
64 glNewList(dplist, GL_COMPILE );
68 GLfloat light_position0[] = {10.0f, 10.0, 10.0f, 0.0f};
69 GLfloat light_maincolor0[] = {1.0f, 1.0, 1.0f, 1.0f};
70 GLfloat light_ambientcolor0[] = {0.4f, 0.2f, 0.2f, 1.0f};
73 glLightfv(GL_LIGHT0, GL_POSITION, light_position0);
74 glLightfv(GL_LIGHT0, GL_DIFFUSE, light_maincolor0);
75 glLightfv(GL_LIGHT0, GL_SPECULAR, light_maincolor0);
76 glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambientcolor0);
79 glEnable(GL_LIGHTING);
80 glEnable(GL_DEPTH_TEST);
83 GLfloat paintcolor0[] = { 0.9f, 0.2f, 0.5f, 1.0f};
84 GLfloat specularcolor0[] = { 1.0f, 1.0f, 1.0f, 1.0f};
85 GLfloat shininess0[] = { 70.0f };
87 GLfloat paintcolor1[] = { 0.3f, 0.9f, 0.4f, 1.0f};
88 GLfloat paintcolor2[] = { 0.1f, 0.2f, 0.9f, 1.0f};
90 glMatrixMode(GL_MODELVIEW);
94 glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specularcolor0);
95 glMaterialfv( GL_FRONT_AND_BACK, GL_SHININESS, shininess0);
96 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
106 glTranslatef( dtea[0], dtea[1], dtea[2] );
109 #ifdef BIAS_HAVE_GLUT
110 glutSolidTeapot(0.6);
111 #endif //BIAS_HAVE_GLUT
114 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE,
121 glTranslatef( -2*dtea[0], -2*dtea[1], -2*dtea[2] );
123 #ifdef BIAS_HAVE_GLUT
124 glutSolidTeapot(0.3);
125 #endif // BIAS_HAVE_GLUT
127 glTranslatef( dtea[0], dtea[1], dtea[2] );
131 glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, paintcolor2);
132 glColor3f(paintcolor2[0], paintcolor2[1], paintcolor2[2]);
134 #ifdef BIAS_HAVE_GLUT
135 glTranslatef(0,0,-2);
136 glutSolidSphere(0.8, 30, 60);
137 glTranslatef(0,0, 2);
139 glTranslatef( 1,0,-3);
140 glutSolidSphere(0.5, 50, 100);
141 glTranslatef(-1,0, 3);
145 glTranslatef(0,-2,0);
147 glTranslatef(0,-1,0);
148 glutSolidIcosahedron();
149 glTranslatef(0, 1,0);
151 glTranslatef(0,-2.2,0);
152 glutSolidTetrahedron();
153 glTranslatef(0, 2.2,0);
154 #endif // BIAS_HAVE_GLUT
160 #ifdef BIAS_HAVE_FONTGL
163 font.InitFont( GetDC(HWND(GetHandle())),
"Arial" );
165 font.InitFont( GetHandle(),
"Arial" );
168 #endif // BIAS_HAVE_FONTGL
176 void MyGLCanvas::DisplayCalls()
191 glColor3d(1.0, 0.5, 0.2);
196 const float cycletime=10.0;
199 glRotatef( angleM, 0.0, 1.0, 0.0 );
201 glRotatef( angleM-360.0, 1.0, 0.0, 0.0 );
206 if(glIsList(dplist) == GL_TRUE)
210 BIASERR(
"invalid display list dplist="<<dplist);
217 #ifdef BIAS_HAVE_FONTGL
218 if (font.IsInitialized())
220 glColor3f(1.0f, 1.0f, 0.5f);
221 font.PrintWinCoords(
"a0", 0, 0 );
222 font.PrintWinCoords(
"a100x0y", 100, 0 );
223 font.PrintWinCoords(
"a100x50y", 100, 50 );
225 glColor3f(1.0f, 0.5f, 1.0f);
226 font.DrawTextGL::PrintNormCoords(
"n0", 0.0, 0.0);
227 font.DrawTextGL::PrintNormCoords(
"n0.5x0y", 0.5, 0.0);
228 font.DrawTextGL::PrintNormCoords(
"n0.5x0.25y", 0.5, 0.25);
232 #endif // BIAS_HAVE_FONTGL
240 MyGLCanvas2::MyGLCanvas2(wxFrame* parent)
248 MyGLCanvas2::MyGLCanvas2(wxFrame* parent
249 ,wxGLContext* sharedContext
254 ,
const wxString& name
256 ,
const wxPalette& palette )
258 BIAS::
OpenGLCanvas(parent,sharedContext, id,pos,size,style,name,attribList,palette)
262 void MyGLCanvas2::DisplayCalls()
269 if(glIsList(dplist) == GL_TRUE)
272 const float cycletime=3.0;
275 glRotatef( -angleM, 0.0, 1.0, 0.0 );
277 glRotatef( -(angleM-360.0), 1.0, 0.0, 0.0 );
283 BIASERR(
"dplist invalid");
295 bool ExampleGLSharedApp::OnInit()
300 cout<<
"Hello cout"<<endl;
301 cout<<
"Hello cerr"<<endl;
303 MyFrame *frame =
new MyFrame( wxT(
"ExampleOpenGLCanvas"), wxPoint(0,0), wxSize(640,480) );
312 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
313 EVT_MENU(ID_QUIT, MyFrame::OnQuit)
314 EVT_MENU(ID_ABOUT, MyFrame::OnAbout)
319 MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
320 : wxFrame((wxFrame *)NULL, -1, title, pos, size)
325 wxMenu *menuFile =
new wxMenu;
326 menuFile->Append( ID_ABOUT, wxT(
"&About...") );
327 menuFile->AppendSeparator();
328 menuFile->Append( ID_QUIT, wxT(
"E&xit") );
329 wxMenuBar *menuBar =
new wxMenuBar;
330 menuBar->Append(menuFile, wxT(
"&File"));
337 p_canvas=
new MyGLCanvas(
this);
340 if ( p_canvas->GetContext() == NULL)
342 BIASERR(
"context of p_canvas is NULL."<<endl
343 <<
"This means sharing OpenGL contexts may not be supported."<<endl
344 <<
"Could not share context. aborting");
348 p_2nd_canvas =
new MyGLCanvas2(
this, p_canvas->GetContext(), -1);
350 p_2nd_canvas->dplist = 1;
354 wxBoxSizer * sizer =
new wxBoxSizer(wxHORIZONTAL);
355 sizer->Add( p_canvas ,1,wxEXPAND|wxALL);
356 #if wxCHECK_VERSION(2, 6, 2)
359 sizer->Add( p_2nd_canvas ,1,wxEXPAND|wxALL);
362 sizer->SetItemMinSize(p_canvas, 500,400);
363 sizer->SetItemMinSize(p_2nd_canvas, 300,200);
364 sizer->SetSizeHints(
this);
367 SetSizerAndFit(sizer);
371 void MyFrame::OnQuit(wxCommandEvent& ){
376 void MyFrame::OnAbout(wxCommandEvent& )
378 wxString title(wxT(
"About"));
380 msg<<wxT(
"About - ")<<
AsciiToWx(FUNCNAME)<<wxT(
"\n");
381 msg<<wxT(
"author: Jan Woetzel (c) 2003-2005\n");
383 msg<<wxT(
"from ")<<
AsciiToWx(__FILE__)<<wxT(
"\n");
384 msg<<wxT(
"GUI using: ")<<wxVERSION_STRING<<wxT(
"\n");
387 wxMessageBox(msg, title, wxICON_INFORMATION | wxOK );
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.
static void DisplayCoordCross(const float &size=1.0f, const float &linewidth=1.0f)
draw a coord cross as three lines in r,g,b
OpenGL canvases with additinal event handling (JW)
static void DisplayCoordCrossAxesLabel(const float &size, const BIAS::DrawTextGL &font, const std::string &LabelX=std::string("x"), const std::string &LabelY=std::string("y"), const std::string &LabelZ=std::string("z"))
draw only the axes labels for a coord cross as text in r,g,b JW