diff options
Diffstat (limited to 'debian/fireflies/fireflies-2.08/libgfx/tests')
8 files changed, 654 insertions, 0 deletions
diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/Makefile b/debian/fireflies/fireflies-2.08/libgfx/tests/Makefile new file mode 100644 index 00000000..f3386fab --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/Makefile @@ -0,0 +1,42 @@ +# Include the 'gfx-config' file to get all the correct build settings +include ../gfx-config + +SRCS = t-vec.cxx t-img.cxx t-gui.cxx t-glimg.cxx t-script.cxx t-glext.cxx +ALL = $(SRCS:.cxx=) + +all: $(ALL) + +t-vec: t-vec.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx -lm + +t-script: t-script.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx -lm + +t-img: t-img.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx $(IMG_LIBS) -lm + +# +# GUI programs should make the appropriate post-build call to +# $(FLTKCONFIG). On most platforms, this does nothing, but under +# Mac OS X, it is essential to make GUI programs launch correctly. +# + +t-gui: t-gui.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx $(GUI_LIBS) -lm + $(FLTKCONFIG) --post $@ + +t-glext: t-glext.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx $(GUI_LIBS) -lm + $(FLTKCONFIG) --post $@ + +t-glimg: t-glimg.cxx + $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) -lgfx $(GUI_LIBS) -lm + $(FLTKCONFIG) --post $@ + +# This is just a standard mechanism to correctly track the dependencies +# of the source files. +# +depend: + $(CXX_DEPEND) $(SRCS) > Makefile.dep + +-include Makefile.dep diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-glext.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-glext.cxx new file mode 100644 index 00000000..82b40000 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-glext.cxx @@ -0,0 +1,82 @@ +/************************************************************************ + + Test the availability of various OpenGL extensions + + by Michael Garland, 2001. + + $Id: t-glext.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gui.h> +#include <gfx/glext.h> +#include <string> +#include <fstream> + +using namespace std; + +class GUI : public MxGUI +{ +public: + + virtual void setup_for_drawing(); +}; + +GUI gui; + +static void dump_string(ostream &out, const string& str) +{ + const char *ws = " \t\n\r"; + string::size_type start, end; + + start = 0; + end = str.find_first_of(ws, start); + + while( end!=string::npos ) + { + out << " " << str.substr(start, end-start) << endl; + start = str.find_first_not_of(ws, end); + end = str.find_first_of(ws, start); + } +} + +void GUI::setup_for_drawing() +{ + ofstream log("glext.txt"); + + string gl_extensions = (char *)glGetString(GL_EXTENSIONS); + + log << "OpenGL extensions" << endl + << "-----------------" << endl; + dump_string(log, gl_extensions); + log << endl << endl; + + +#ifdef HAVE_GL_WGLEXT_H + PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = + (PFNWGLGETEXTENSIONSSTRINGARBPROC) + wglGetProcAddress("wglGetExtensionsStringARB"); + + if( !wglGetExtensionsStringARB ) + { + log << "Couldn't find wglGetExtensionsStringARB." << endl; + exit(-1); + } + else + { + string wgl_extensions = wglGetExtensionsStringARB(wglGetCurrentDC()); + + log << "WGL extensions" << endl + << "--------------" << endl; + dump_string(log, wgl_extensions); + } +#endif + + exit(0); +} + +int main(int argc, char **argv) +{ + gui.initialize(argc, argv); + return gui.run(); +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-glimg.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-glimg.cxx new file mode 100644 index 00000000..706441c2 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-glimg.cxx @@ -0,0 +1,149 @@ +/************************************************************************ + + This is a very simplistic image viewer. It uses libgfx routines to + read a set of image files specified on the command line. These images + are then displayed in a window using OpenGL image operations. + + by Michael Garland, 2000. + + $Id: t-glimg.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> +#include <gfx/gui.h> +#include <gfx/raster.h> + +#include <string> +#include <vector> +#include <FL/filename.H> + +class GUI : public MxGUI +{ +public: + std::vector<ByteRaster *> images; + std::vector<std::string> image_names; + int current_image; + + virtual ~GUI(); + + virtual void update_animation(); + virtual void cmdline_file(const char *file); + virtual void setup_for_drawing(); + virtual void draw_contents(); + + void set_image(int i); +}; + +GUI gui; + +GUI::~GUI() +{ + for(int i=0; i<images.size(); i++) + if( images[i] ) + delete images[i]; +} + +static void cb_image(Fl_Widget *, long i) + { gui.set_image(i); gui.canvas->redraw(); } + +void GUI::set_image(int i) +{ + current_image = i; + + if(current_image<0 || current_image>=images.size()) return; + ByteRaster *img = images[current_image]; + + int width = img->width(); + int height = img->height(); + + gui.status(image_names[current_image].c_str()); + + if( width!=canvas->w() || height!=canvas->h() ) + { + unlock_size(); + resize_canvas(width, height); + lock_size(); + } +} + +void GUI::cmdline_file(const char *namestring) +{ + if(!namestring) return; // Don't support reading from stdin + + static std::string img_menu("&Images/"); + std::string filename(fl_filename_name(namestring)); // Strip directories + + ByteRaster *img = read_image(namestring); + if( img ) + { + int id = images.size(); + images.push_back(img); + image_names.push_back(namestring); + + int key = id<9 ? FL_CTRL+'1'+id : 0; + + + gui.menu_bar->add((img_menu+filename).c_str(), key, + (Fl_Callback *)cb_image, (void *)id, FL_MENU_RADIO); + } +} + +void GUI::update_animation() +{ + set_image((current_image+1) % images.size()); +} + +void GUI::setup_for_drawing() +{ + glClearColor(0.9f, 0.0f, 0.0f, 0.0f); + glDisable(GL_DEPTH_TEST); + glDisable(GL_LIGHTING); + glPixelZoom(1.0f, -1.0f); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +static void draw_image(const ByteRaster *img) +{ + GLenum format; + if(img->channels()==1) format = GL_LUMINANCE; + else if(img->channels()==3) format = GL_RGB; + else if(img->channels()==4) format = GL_RGBA; + else return; // Don't draw unsupported formats + + glPushAttrib(GL_PIXEL_MODE_BIT); + glRasterPos2f(0, img->height()); + glDrawPixels(img->width(), img->height(), + format, GL_UNSIGNED_BYTE, img->head()); + glPopAttrib(); + +} + +void GUI::draw_contents() +{ + glClear(GL_COLOR_BUFFER_BIT); + + if(current_image<0 || current_image>=images.size()) return; + ByteRaster *img = images[current_image]; + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + gluOrtho2D(0, img->width(), 0, img->height()); + + draw_image(img); +} + +int main(int argc, char **argv) +{ + gui.initialize(argc, argv); + if(gui.images.size() == 0) return 0; // Exit if no images read + + gui.title("OpenGL Image Viewer"); + + gui.default_fps = 1.0f; + gui.set_image(0); + + return gui.run(); +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-gui.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-gui.cxx new file mode 100644 index 00000000..296fe3b2 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-gui.cxx @@ -0,0 +1,130 @@ +/************************************************************************ + + This is a simple program which demonstrates the use of the MxGUI + minimalist GUI framework. The application presents a window with a + rotating square that can be moved around with the mouse. + + by Michael Garland, 1999. + + $Id: t-gui.cxx 400 2004-02-16 16:31:35Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> +#include <gfx/gui.h> +#include <gfx/gltools.h> + +class GUI : public MxGUI +{ +public: + float angle, opt_theta, center[2]; + bool dragging; + +public: + virtual void setup_for_drawing(); + virtual void draw_contents(); + virtual void update_animation(); + + virtual bool mouse_down(int *where, int which); + virtual bool mouse_up(int *where, int which); + virtual bool mouse_drag(int *where, int *last, int which); +}; + +GUI gui; + +void GUI::setup_for_drawing() +{ + glClearColor(0.65f, 0.65f, 0.65f, 0.0f); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + + glMatrixMode(GL_PROJECTION); + gluOrtho2D(-1.0, 1.0, -1.0, 1.0); +} + +void GUI::draw_contents() +{ + glClear(GL_COLOR_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + glLoadIdentity(); + + glColor3f(0.0, 0.0, 0.0); + glBegin(GL_LINES); + glVertex2f(-1.0, 0.0); + glVertex2f(1.0, 0.0); + glVertex2f(0.0, -1.0); + glVertex2f(0.0, 1.0); + glEnd(); + + glTranslatef(center[0], center[1], 0); + glRotatef(angle, 0, 0, 1); + + glEnable(GL_BLEND); + glColor4d(0.8, 0.15, 0.15, 0.85); + glBegin(dragging?GL_LINE_LOOP:GL_POLYGON); + glBegin(GL_POLYGON); + glVertex2f(-0.5, -0.5); + glVertex2f(-0.5, 0.5); + glVertex2f(0.5, 0.5); + glVertex2f(0.5, -0.5); + glEnd(); + glDisable(GL_BLEND); + + glPopMatrix(); +} + +void GUI::update_animation() +{ + angle += opt_theta; +} + +static +bool center_on_click(float *ctr, int *where) +{ + double world[3]; + + unproject_pixel(where, world); + ctr[0] = (float)world[0]; + ctr[1] = (float)world[1]; + + return true; +} + +bool GUI::mouse_down(int *where, int which) +{ + status("Clicked mouse %d at %d,%d", which, where[0], where[1]); + if( which==1 ) + { + dragging = true; + return center_on_click(center, where); + } + else return false; +} + +bool GUI::mouse_up(int *where, int which) +{ + status("Released mouse %d at %d,%d", which, where[0], where[1]); + dragging = false; + return (which==1); +} + +bool GUI::mouse_drag(int *where, int *last, int which) +{ + if( which==1 ) + return center_on_click(center, where); + else + return false; +} + +int main(int argc, char **argv) +{ + gui.opt_theta = 10.0f; + gui.angle = 0.0f; + gui.dragging = false; + gui.center[0] = gui.center[1] = 0.0f; + + gui.initialize(argc, argv); + gui.toplevel->label("Simple GUI Example"); + return gui.run(); +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-img.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-img.cxx new file mode 100644 index 00000000..113cea8c --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-img.cxx @@ -0,0 +1,82 @@ +/************************************************************************ + + The images produced by this test are checkboard gradients. They + ramp from black in the upper left corner to full color in the lower + right corner. + + by Michael Garland, 1999. + + $Id: t-img.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> +#include <gfx/raster.h> + +static +void grayscale_test() +{ + ByteRaster img(256, 256, 1); + + int i, j, c; + + for(i=0; i<img.height(); i++) for(j=0; j<img.width(); j++) + { + c = ((((i&0x8)==0)^((j&0x8))==0))*(i+j)/2; + img.pixel(j,i)[0] = c; + } + + write_pnm_image("chex1.pgm", img); + write_tiff_image("chex1.tif", img); + write_png_image("chex1.png", img); + write_jpeg_image("chex1.jpg", img); + + ByteRaster *pgm = read_pnm_image("chex1.pgm"); + ByteRaster *tif = read_tiff_image("chex1.tif"); + ByteRaster *png = read_png_image("chex1.png"); + ByteRaster *jpg = read_jpeg_image("chex1.jpg"); + + if( pgm ) write_pnm_image("chex1-dup.pgm", *pgm); + if( tif ) write_tiff_image("chex1-dup.tif", *tif); + if( png ) write_png_image("chex1-dup.png", *png); + if( jpg ) write_jpeg_image("chex1-dup.jpg", *jpg); +} + +static +void rgb_test() +{ + ByteRaster img(256, 256, 3); + + int i, j, c; + + for(i=0; i<img.height(); i++) for(j=0; j<img.width(); j++) + { + c = ((((i&0x8)==0)^((j&0x8))==0))*(i+j)/2; + img.pixel(j,i)[0] = c; + img.pixel(j,i)[1] = c/2; + img.pixel(j,i)[2] = c/4; + } + + write_pnm_image("chex3.ppm", img); + write_tiff_image("chex3.tif", img); + write_png_image("chex3.png", img); + write_jpeg_image("chex3.jpg", img); + + ByteRaster *ppm = read_pnm_image("chex3.ppm"); + ByteRaster *tif = read_tiff_image("chex3.tif"); + ByteRaster *png = read_png_image("chex3.png"); + ByteRaster *jpg = read_jpeg_image("chex3.jpg"); + + if( ppm ) write_pnm_image("chex3-dup.ppm", *ppm); + if( tif ) write_tiff_image("chex3-dup.tif", *tif); + if( png ) write_png_image("chex3-dup.png", *png); + if( jpg ) write_jpeg_image("chex3-dup.jpg", *jpg); +} + +int main() +{ + grayscale_test(); + rgb_test(); + + return 0; +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx new file mode 100644 index 00000000..42b9ad83 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-script.cxx @@ -0,0 +1,74 @@ +/************************************************************************ + + Test the libgfx scripting facility. + + by Michael Garland, 2000. + + $Id: t-script.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> +#include <gfx/script.h> +#include <gfx/vec3.h> + +using namespace std; + +// usage: add <x>* +// Adds all numbers listed on the line and prints the result +// +// usage: avg <x>* +// Averages all numbers listed on the line and prints the result +// +int proc_add(const CmdLine &cmd) +{ + std::vector<double> values; + double sum = 0.0; + + cmd.collect_as_numbers(values); + std::vector<double>::size_type count; + for(count=0; count<values.size(); count++) + sum += values[count]; + + if( cmd.opname() == "avg" && count>0 ) + sum /= (double)count; + + cout << sum << endl; + return SCRIPT_OK; +} + +// usage: vec3 <x> <y> <z> +// Constructs a 3-vector and prints the result +int proc_vec3(const CmdLine &cmd) +{ + if( cmd.argcount() != 3 ) return SCRIPT_ERR_SYNTAX; + + Vec3 v; + cmd.collect_as_numbers(v, 3); + + cout << v << endl; + return SCRIPT_OK; +} + +// usage: echo <msg> +// Prints all the text following the command name verbatim +int proc_echo(const CmdLine &cmd) +{ + cout << cmd.argline() << endl; + return SCRIPT_OK; +} + +int main(int argc, char *argv[]) +{ + CmdEnv env; + + env.register_command("add", proc_add); + env.register_command("avg", proc_add); + env.register_command("echo", proc_echo); + env.register_command("vec3", proc_vec3); + + for(int i=1; i<argc; i++) + env.do_file(argv[i]); + + return 0; +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/t-vec.cxx b/debian/fireflies/fireflies-2.08/libgfx/tests/t-vec.cxx new file mode 100644 index 00000000..434c97d3 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/t-vec.cxx @@ -0,0 +1,78 @@ +/************************************************************************ + + Test various vector math facilities provided by libgfx. + + by Michael Garland, 2000. + + $Id: t-vec.cxx 426 2004-09-27 04:34:55Z garland $ + + ************************************************************************/ + +#include <gfx/gfx.h> + +#include <gfx/vec2.h> +#include <gfx/vec3.h> +#include <gfx/vec4.h> +#include <gfx/intvec.h> + +using namespace std; + +void test_intvec() +{ + cout << "Testing IntVec types" << endl; + + class Normal : public IntVec<short, SHRT_MAX, 3> + { + public: + Normal(const Vec3& v) { (*this) = v; } + + Vec3 unpack() const { return Vec3((*this)[0],(*this)[1],(*this)[2]); } + void pack(const Vec3& v) + { set(0, v[0]); set(1, v[1]); set(2, v[2]); } + + Normal& operator=(const Vec3& v) { pack(v); return *this; } + }; + + Normal n = Vec3(1.0, 0.4, -1.0); + cout << " n = " << n.unpack() << endl; + + n.set(0, -1.0); n.set(1, 0.4); n.set(2, 1); + cout << " n = " << n[0] << " " << n[1] << " " << n[2] << endl; + + + typedef IntVec3<unsigned char, UCHAR_MAX> byteColor; + byteColor rgb(0.8, 0.2, 0.2); + cout << " rgb = " << rgb.unpack() << endl; +} + +template<class Vec> +void test_vector() +{ + Vec u = 0; + Vec v = 0; + + u[0] = 1; + v[1] = 1; + + Vec x = u * 2.0; + Vec y = v / 2.0; + + cout << " x = " << x << endl; + cout << " y = " << y << endl; +} + +int main() +{ + cout << "+ Testing class Vec2" << endl; + test_vector<Vec2>(); + + cout << "+ Testing class Vec3" << endl; + test_vector<Vec3>(); + + cout << "+ Testing class Vec4" << endl; + test_vector<Vec4>(); + + test_intvec(); + + return 0; +} diff --git a/debian/fireflies/fireflies-2.08/libgfx/tests/test1.sc b/debian/fireflies/fireflies-2.08/libgfx/tests/test1.sc new file mode 100644 index 00000000..489f8cb5 --- /dev/null +++ b/debian/fireflies/fireflies-2.08/libgfx/tests/test1.sc @@ -0,0 +1,17 @@ +# This is a test script meant to be fed to t-script. It is not meant as an +# exhaustive test, but mainly as a demonstration. +# +# $Id: test1.sc 170 2000-09-06 21:43:25Z garland $ +# + +echo The following sum should be 15 +add 1 2 3 4 5 + +echo +echo The following average should be 3.5 +avg 3 8 2 1 + +echo +echo The following is the vector [1 0 0] +vec3 1 0 0 + |