From bff7f2b3b440c30d0d6eb692576af57ef42edd1b Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 8 Jul 2009 17:12:02 +0000 Subject: Comments and style adjustments, and a couple fixes. --- tests/gl.c | 17 ++++++++++++++--- tests/glxx.cpp | 23 ++++++++++++++++------- tests/png.c | 8 ++++++++ tests/pngxx.cpp | 5 +++++ tests/raytrace.c | 13 ++++++++++++- tests/raytracexx.cpp | 2 +- tests/tests.c | 2 +- tests/warning.c | 2 +- 8 files changed, 58 insertions(+), 14 deletions(-) (limited to 'tests') diff --git a/tests/gl.c b/tests/gl.c index c9a3ae4..99040c1 100644 --- a/tests/gl.c +++ b/tests/gl.c @@ -26,29 +26,35 @@ main() { dmnsn_display *display; dmnsn_progress *progress; dmnsn_scene *scene; - dmnsn_object *sphere, *cube; + dmnsn_object *cube; dmnsn_matrix trans; + const unsigned int frames = 10; unsigned int i; /* Set the resilience low for tests */ dmnsn_set_resilience(DMNSN_SEVERITY_LOW); + /* Create the default test scene */ scene = dmnsn_new_default_scene(); if (!scene) { fprintf(stderr, "--- Couldn't create default scene! ---\n"); return EXIT_FAILURE; } + /* Optimize the canvas for GL drawing */ if (dmnsn_gl_optimize_canvas(scene->canvas) != 0) { dmnsn_delete_default_scene(scene); fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n"); return EXIT_FAILURE; } - dmnsn_array_get(scene->objects, 0, &sphere); + /* Get the cube object */ dmnsn_array_get(scene->objects, 1, &cube); + + /* Get the camera transformation matrix */ trans = dmnsn_get_perspective_camera_trans(scene->camera); + /* Create a new glX display */ display = dmnsn_new_display(scene->canvas); if (!display) { dmnsn_delete_default_scene(scene); @@ -56,7 +62,10 @@ main() { return EXIT_FAILURE; } - for (i = 0; i < 10; ++i) { + /* Render the animation */ + for (i = 0; i < frames; ++i) { + /* Render the scene */ + progress = dmnsn_raytrace_scene_async(scene); if (!progress) { dmnsn_delete_display(display); @@ -74,6 +83,8 @@ main() { return EXIT_FAILURE; } + /* Display the scene */ + if (dmnsn_gl_write_canvas(scene->canvas) != 0) { dmnsn_delete_display(display); dmnsn_delete_default_scene(scene); diff --git a/tests/glxx.cpp b/tests/glxx.cpp index d88c27d..c582f8c 100644 --- a/tests/glxx.cpp +++ b/tests/glxx.cpp @@ -26,12 +26,18 @@ int main() { using namespace Dimension; + // Set the resilience low for tests + resilience(SEVERITY_LOW); + + // Create the default test scene Scene scene = Tests::default_scene(); + // Get the camera Perspective_Camera& camera = dynamic_cast(scene.camera()); - Cube* cube; + // Find the cube + Cube* cube = 0; for (Scene::Iterator i = scene.begin(); i != scene.end(); ++i) { cube = dynamic_cast(&*i); if (cube) { @@ -42,23 +48,26 @@ main() { throw Dimension_Error("Couldn't find a cube in the default scene."); } - // Set the resilience low for tests - resilience(SEVERITY_LOW); - Raytracer raytracer(scene); GL_Drawer drawer(scene.canvas()); Tests::Display display(scene.canvas()); - // Render the scene - for (unsigned int i = 0; i < 10; ++i) { + // Render the animation + const unsigned int frames = 10; + for (unsigned int i = 0; i < frames; ++i) { + // Render the scene Progress rprogress = raytracer.render_async(); std::cout << "Raytracing scene: " << rprogress << std::endl; rprogress.finish(); + // Display the frame drawer.draw(); display.flush(); - cube->trans(inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube->trans()); + // Rotate the cube and camera for the next frame + cube->trans( + inverse(Matrix::rotation(Vector(0.025, 0.0, 0.0)))*cube->trans() + ); camera.trans(Matrix::rotation(Vector(0.0, -0.05, 0.0))*camera.trans()); } diff --git a/tests/png.c b/tests/png.c index 8db6d63..0949f8b 100644 --- a/tests/png.c +++ b/tests/png.c @@ -40,12 +40,14 @@ main() { /* Set the resilience low for tests */ dmnsn_set_resilience(DMNSN_SEVERITY_LOW); + /* Allocate a canvas */ canvas = dmnsn_new_canvas(3*x, y); if (!canvas) { fprintf(stderr, "--- Allocation of canvas failed! ---\n"); return EXIT_FAILURE; } + /* Optimize the canvas for PNG export */ if (dmnsn_png_optimize_canvas(canvas) != 0) { dmnsn_delete_canvas(canvas); fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n"); @@ -110,6 +112,8 @@ main() { } } + /* Write the image to PNG */ + ofile = fopen("dimension1.png", "wb"); if (!ofile) { fprintf(stderr, "--- Opening 'dimension1.png' for writing failed! ---\n"); @@ -137,6 +141,8 @@ main() { fclose(ofile); dmnsn_delete_canvas(canvas); + /* Read the image back from the PNG file */ + ifile = fopen("dimension1.png", "rb"); if (!ifile) { fprintf(stderr, "--- Opening 'dimension1.png' for reading failed! ---\n"); @@ -160,6 +166,8 @@ main() { fclose(ifile); + /* ... and write it back again */ + ofile = fopen("dimension2.png", "wb"); if (!ofile) { fprintf(stderr, "--- Opening 'dimension2.png' for writing failed! ---\n"); diff --git a/tests/pngxx.cpp b/tests/pngxx.cpp index 27fe89c..731f470 100644 --- a/tests/pngxx.cpp +++ b/tests/pngxx.cpp @@ -94,10 +94,13 @@ main() } } + // Write the image to PNG Progress progress = writer.write_async(); std::cout << "Writing PNG file: " << progress << std::endl; } + // Read the image back from PNG + std::ifstream ifstr("dimensionxx1.png", std::ios::binary); PNG_Reader reader(ifstr); @@ -105,6 +108,8 @@ main() std::cout << "Reading PNG file: " << iprogress << std::endl; Canvas canvas = PNG_Reader::finish(iprogress); + // And write it again + std::ofstream ofstr("dimensionxx2.png", std::ios::binary); PNG_Writer writer(canvas, ofstr); diff --git a/tests/raytrace.c b/tests/raytrace.c index 4d54e1c..0515ab2 100644 --- a/tests/raytrace.c +++ b/tests/raytrace.c @@ -30,13 +30,22 @@ main() { /* Set the resilience low for tests */ dmnsn_set_resilience(DMNSN_SEVERITY_LOW); - /* Allocate our new scene */ + /* Allocate our default scene */ scene = dmnsn_new_default_scene(); if (!scene) { fprintf(stderr, "--- Allocation of default scene failed! ---\n"); return EXIT_FAILURE; } + /* Optimize the canvas for PNG export */ + if (dmnsn_png_optimize_canvas(canvas) != 0) { + dmnsn_delete_canvas(canvas); + fprintf(stderr, "--- Couldn't optimize canvas for PNG! ---\n"); + return EXIT_FAILURE; + } + + /* Render scene */ + progress = dmnsn_raytrace_scene_async(scene); if (!progress) { dmnsn_delete_default_scene(scene); @@ -52,6 +61,8 @@ main() { return EXIT_FAILURE; } + /* Write the image to PNG */ + file = fopen("raytrace.png", "wb"); if (!file) { dmnsn_delete_default_scene(scene); diff --git a/tests/raytracexx.cpp b/tests/raytracexx.cpp index 3fed923..fd99acd 100644 --- a/tests/raytracexx.cpp +++ b/tests/raytracexx.cpp @@ -29,6 +29,7 @@ main() { resilience(SEVERITY_LOW); Scene scene = Tests::default_scene(); + PNG_Writer writer(scene.canvas(), file); // Render the scene { @@ -39,7 +40,6 @@ main() { // Write the canvas std::ofstream file("raytracexx.png"); - PNG_Writer writer(scene.canvas(), file); Progress progress = writer.write_async(); std::cout << "Writing PNG file: " << progress << std::endl; diff --git a/tests/tests.c b/tests/tests.c index 7fd7f19..842405a 100644 --- a/tests/tests.c +++ b/tests/tests.c @@ -28,7 +28,7 @@ dmnsn_new_default_scene() dmnsn_sRGB sRGB; dmnsn_color color; - /* Allocate our new scene */ + /* Allocate a new scene */ scene = dmnsn_new_scene(); if (!scene) { return NULL; diff --git a/tests/warning.c b/tests/warning.c index 46ccf15..e677c54 100644 --- a/tests/warning.c +++ b/tests/warning.c @@ -17,7 +17,7 @@ * along with this program. If not, see . * *************************************************************************/ -// Make sure warnings don't kill us - this test should pass +/* Make sure warnings don't kill us - this test should pass */ #include "tests.h" #include -- cgit v1.2.3