md3-model/test/test.cpp

Go to the documentation of this file.
00001 /*
00002  * test.cpp
00003  *
00004  * Copyright (C) 2009,2010  Thomas A. Vaughan
00005  * All rights reserved.
00006  *
00007  * Program to test the md3-model library.
00008  */
00009 
00010 // includes --------------------------------------------------------------------
00011 #include <iostream>
00012 #include <fstream>
00013 
00014 #include "md3-model/md3-model.h"
00015 
00016 #include "glut-demo/glut-demo.h"
00017 #include "perf/perf.h"
00018 
00019 
00020 
00021 ////////////////////////////////////////////////////////////////////////////////
00022 //
00023 //      static helper methods
00024 //
00025 ////////////////////////////////////////////////////////////////////////////////
00026 
00027 class Drawer : public glut::DemoHost {
00028 public:
00029         Drawer(IN const char * dir) {
00030                         m_modelDir = dir;
00031                 }
00032         ~Drawer(void) throw() { }
00033 
00034         // glut::Host class interface methods ----------------------------------
00035         void onInit(void) {
00036                         // load model!
00037                         m_model = md3::loadMd3Player(m_modelDir.c_str());
00038                         THROW(m_model, "Failed to load model: " << m_modelDir);
00039                 }
00040 
00041         void display3D(IN const glut::render_context_t& rc,
00042                                 IN glut::RenderQueue * rq) {
00043                         ASSERT(rq, "null");
00044 
00045                         // draw object
00046                         m_model->render(rc, rq);
00047                 }
00048 
00049 private:
00050         std::string                     m_modelDir;
00051         smart_ptr<glut::Renderable>     m_model;
00052 };
00053 
00054 
00055 
00056 ////////////////////////////////////////////////////////////////////////////////
00057 //
00058 //      entry point
00059 //
00060 ////////////////////////////////////////////////////////////////////////////////
00061 
00062 int
00063 main
00064 (
00065 IN int argc,
00066 IN const char * argv[]
00067 )
00068 {
00069         ASSERT(2 == argc, "Usage: md3-model-test <md3-model-path>");
00070         const char * model_path = argv[1];
00071 
00072         try {
00073                 // title
00074                 std::string title = "MD3 model viewer: ";
00075                 title += model_path;
00076 
00077                 // main loop
00078                 smart_ptr<glut::DemoHost> host = new Drawer(model_path);
00079                 ASSERT(host, "out of memory");
00080                 glut::startDemo(argc, argv, title.c_str(), host);
00081 
00082         } catch (std::exception& e) {
00083                 DPRINTF("Exception: %s", e.what());
00084         }
00085 
00086         // only reach here on error
00087         return -1;
00088 }
00089