summaryrefslogtreecommitdiffstats
path: root/tests/libdimension/gl.c
diff options
context:
space:
mode:
Diffstat (limited to 'tests/libdimension/gl.c')
-rw-r--r--tests/libdimension/gl.c82
1 files changed, 27 insertions, 55 deletions
diff --git a/tests/libdimension/gl.c b/tests/libdimension/gl.c
index a2538e3..0e5946c 100644
--- a/tests/libdimension/gl.c
+++ b/tests/libdimension/gl.c
@@ -19,100 +19,72 @@
#include "tests.h"
#include <stdlib.h>
-#include <stdio.h>
+#include <unistd.h>
int
-main() {
- dmnsn_display *display;
- dmnsn_progress *progress;
- dmnsn_scene *scene;
- dmnsn_canvas *canvas;
-
+main()
+{
/* Set the resilience low for tests */
dmnsn_set_resilience(DMNSN_SEVERITY_LOW);
- /* Create the default test scene */
- scene = dmnsn_new_default_scene();
+ /* Allocate our canvas */
+ dmnsn_canvas *canvas = dmnsn_new_canvas(768, 480);
/* Optimize the canvas for GL drawing */
- if (dmnsn_gl_optimize_canvas(scene->canvas) != 0) {
- dmnsn_delete_scene(scene);
+ if (dmnsn_gl_optimize_canvas(canvas) != 0) {
+ dmnsn_delete_canvas(canvas);
fprintf(stderr, "--- Couldn't optimize canvas for GL! ---\n");
return EXIT_FAILURE;
}
- dmnsn_clear_canvas(scene->canvas, dmnsn_black);
+ /* Paint the canvas blue */
+ dmnsn_clear_canvas(canvas, dmnsn_blue);
/* Create a new glX display */
- display = dmnsn_new_display(scene->canvas);
+ dmnsn_display *display = dmnsn_new_display(canvas);
if (!display) {
- dmnsn_delete_scene(scene);
fprintf(stderr, "--- WARNING: Couldn't initialize X or glX! ---\n");
return EXIT_SUCCESS;
}
- /* Render the scene */
-
- printf("Rendering scene\n");
- progress = dmnsn_raytrace_scene_async(scene);
-
- /* Display the scene as it's rendered */
- while (dmnsn_get_progress(progress) < 1.0) {
- if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
- fprintf(stderr, "--- Drawing to openGL failed! ---\n");
- return EXIT_FAILURE;
- }
- dmnsn_display_flush(display);
- }
-
- if (dmnsn_finish_progress(progress) != 0) {
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
- fprintf(stderr, "--- Raytracing failed! ---\n");
- return EXIT_FAILURE;
- }
-
- /* Make sure we show the completed rendering */
+ /* Draw to OpenGL */
printf("Drawing to OpenGL\n");
- if (dmnsn_gl_write_canvas(scene->canvas) != 0) {
+ if (dmnsn_gl_write_canvas(canvas) != 0) {
dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
- fprintf(stderr, "--- Drawing to openGL failed! ---\n");
+ dmnsn_delete_canvas(canvas);
+ fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
return EXIT_FAILURE;
}
dmnsn_display_flush(display);
+ dmnsn_delete_canvas(canvas);
- /* Show the image on screen for a bit */
- sleep(1);
+ /*
+ * Now test GL import/export
+ */
- /* Read a canvas from the GL buffer */
+ /* Read the image back from OpenGL */
printf("Reading from OpenGL\n");
- canvas = dmnsn_gl_read_canvas(0, 0, scene->canvas->x, scene->canvas->y);
+ canvas = dmnsn_gl_read_canvas(0, 0, 768, 480);
if (!canvas) {
dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
- fprintf(stderr, "--- Reading canvas from GL buffer failed! ---\n");
+ dmnsn_delete_canvas(canvas);
+ fprintf(stderr, "--- Reading from OpenGL failed! ---\n");
return EXIT_FAILURE;
}
- /* And write it back */
+ /* And draw it back */
printf("Drawing to OpenGL\n");
if (dmnsn_gl_write_canvas(canvas) != 0) {
- dmnsn_delete_canvas(canvas);
dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
- fprintf(stderr, "--- Drawing to openGL failed! ---\n");
+ dmnsn_delete_canvas(canvas);
+ fprintf(stderr, "--- Drawing to OpenGL failed! ---\n");
return EXIT_FAILURE;
}
dmnsn_display_flush(display);
+ dmnsn_delete_canvas(canvas);
- /* Show the image on screen for a bit */
+ /* Show the image on the screen for a bit */
sleep(1);
- dmnsn_delete_canvas(canvas);
- dmnsn_delete_display(display);
- dmnsn_delete_scene(scene);
return EXIT_SUCCESS;
}