Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012
00013 #include "glut-demo/glut-demo.h"
00014 #include "nstream/nstream.h"
00015 #include "opengl-effects/opengl-effects.h"
00016 #include "perf/perf.h"
00017 #include "util/file.h"
00018 #include "wave-glut/texture.h"
00019
00020
00021
00022
00023
00024
00025
00026
00027 class TestHost : public glut::DemoHost {
00028 public:
00029
00030 TestHost(IN const char * texfile) {
00031 ASSERT(texfile, "NULL");
00032 m_texfile = texfile;
00033 }
00034 ~TestHost(void) throw() { }
00035
00036
00037 void onInit(void) {
00038
00039 std::string parentDir;
00040 GetParentDirectory(m_texfile.c_str(), parentDir);
00041 const char * file = GetFilename(m_texfile.c_str());
00042
00043
00044 smart_ptr<nstream::Manager> mgr =
00045 nstream::getFilesystemManager(parentDir.c_str());
00046 ASSERT(mgr, "failed to create filesystem manager");
00047
00048
00049 media::image_t img;
00050 ASSERT_THROW(media::loadImage(mgr, file, img),
00051 "Failed to load texture image: " << m_texfile);
00052
00053 img.dump("Texture Image");
00054
00055
00056 glut::tex_sphere_t ts;
00057 ts.radius = 3.0;
00058 ts.textureId = glut::createTextureFromImage(img);
00059 DPRINTF("Created texture: %d", ts.textureId);
00060
00061 m_sphere = glut::createMappedSphere(ts);
00062 ASSERT(m_sphere, "null");
00063
00064
00065 m_angle = 0.0;
00066 }
00067
00068 void display3D(IN const glut::render_context_t& rc,
00069 IN glut::RenderQueue * rq) {
00070 ASSERT(m_sphere, "null");
00071
00072 m_angle += 0.5;
00073
00074 glMatrixMode(GL_MODELVIEW);
00075 glPushMatrix();
00076
00077
00078 glRotatef(m_angle, 0, 1, 0);
00079
00080 m_sphere->render(rc, rq);
00081
00082 glPopMatrix();
00083 }
00084
00085 private:
00086
00087 smart_ptr<glut::Renderable> m_sphere;
00088 std::string m_texfile;
00089 float m_angle;
00090 };
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100 int
00101 main
00102 (
00103 IN int argc,
00104 IN const char * argv[]
00105 )
00106 {
00107 ASSERT(2 == argc,
00108 "usage: test-tex-sphere <texture-file>");
00109
00110 const char * texfile = argv[1];
00111 DPRINTF("Using texture file: '%s'", texfile);
00112
00113 int retval = 0;
00114 try {
00115 perf::Timer timer("overall timer");
00116
00117 std::string title = "Texture Mapped Sphere: ";
00118 title += texfile;
00119
00120
00121 TestHost host(texfile);
00122
00123
00124 glut::startDemo(argc, argv, title.c_str(), &host);
00125
00126 } catch (std::exception& e) {
00127 DPRINTF("EXCEPTION: %s", e.what());
00128 retval = 1;
00129 }
00130
00131 perf::dumpTimingSummary(std::cerr);
00132
00133 return retval;
00134 }
00135