Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <fstream>
00013
00014 #include "common/wave_ex.h"
00015 #include "perf/perf.h"
00016 #include "wave-glut/camera.h"
00017 #include "wave-glut/wave-glut.h"
00018
00019
00020 static const int s_defaultWidth = 800;
00021 static const int s_defaultHeight = 600;
00022
00023 static float s_dist = 10.0;
00024
00025
00026
00027
00028
00029
00030
00031
00032 class Drawer : public glut::Host {
00033 public:
00034 ~Drawer(void) throw() { }
00035
00036
00037 void init(void) {
00038
00039 glShadeModel(GL_SMOOTH);
00040
00041 glEnable(GL_LIGHT0);
00042
00043 glFrontFace(GL_CCW);
00044 glCullFace(GL_BACK);
00045 }
00046
00047 void display(IN int w, IN int h) {
00048 perf::time_t now = perf::getNow();
00049
00050 glEnable(GL_LIGHTING);
00051 glEnable(GL_DEPTH_TEST);
00052 glEnable(GL_TEXTURE_2D);
00053 glEnable(GL_CULL_FACE);
00054
00055
00056 glClearColor(0.5, 0.5, 0.5, 1.0);
00057 glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
00058
00059
00060 glut::camera_t camera;
00061 camera.setAspect(w, h);
00062 glut::Viewer viewer;
00063 viewer.setPosition(point3d_t(0, 0, -s_dist));
00064
00065
00066 glut::setOpenGLProjection(camera);
00067 glut::setOpenGLViewer(viewer);
00068
00069
00070 float lightAmbient[] = { 0.8, 0.8, 0.8, 1.0 };
00071 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lightAmbient);
00072
00073
00074 static float angle = 0.0;
00075 angle += 0.5;
00076 glRotatef(angle, 0.0, 1.0, 0.0);
00077
00078
00079 glutSolidSphere(4.0, 16, 16);
00080
00081 glDisable(GL_LIGHTING);
00082 glDisable(GL_DEPTH_TEST);
00083 glDisable(GL_TEXTURE_2D);
00084 glDisable(GL_CULL_FACE);
00085 }
00086
00087 eBehavior tick(void) {
00088 return eContinue;
00089 }
00090
00091 int shutdown(void) {
00092 perf::dumpTimingSummary(std::cout);
00093 return 0;
00094 }
00095
00096 eBehavior keyboard(IN int key, IN int mods) {
00097 if ('=' == key)
00098 s_dist += 1.0;
00099 if ('-' == key)
00100 s_dist -= 1.0;
00101
00102 if (s_dist < 1.0)
00103 s_dist = 1.0;
00104
00105 if ('l' == key)
00106 glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
00107
00108 if ('s' == key)
00109 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
00110
00111 if (27 == key)
00112 return eExit;
00113
00114 return eContinue;
00115 }
00116 };
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 int
00127 main
00128 (
00129 IN int argc,
00130 IN const char * argv[]
00131 )
00132 {
00133 try {
00134
00135 smart_ptr<glut::Host> host = new Drawer;
00136 ASSERT(host, "out of memory");
00137 glut::start(argc, argv,
00138 s_defaultWidth, s_defaultHeight,
00139 "wave-glut md3 model viewer",
00140 NULL,
00141 host);
00142
00143 } catch (std::exception& e) {
00144 DPRINTF("Exception: %s", e.what());
00145 }
00146
00147
00148 return 1;
00149 }
00150