diff options
author | Tavian Barnes <tavianator@gmail.com> | 2009-07-12 21:17:12 +0000 |
---|---|---|
committer | Tavian Barnes <tavianator@gmail.com> | 2009-07-12 21:17:12 +0000 |
commit | bcf65bd050d9fbe364a60ab7ec0221539ca2c2af (patch) | |
tree | 5e5196b9ec7269f57c83da9536bf1de91e92e91d | |
parent | 249203127d1ae989785978024ef0ad25bc994384 (diff) | |
download | dimension-bcf65bd050d9fbe364a60ab7ec0221539ca2c2af.tar.xz |
Begin dmnsn_texture* type.
-rw-r--r-- | libdimension/Makefile.am | 16 | ||||
-rw-r--r-- | libdimension/dimension.h | 2 | ||||
-rw-r--r-- | libdimension/dimension/object.h | 6 | ||||
-rw-r--r-- | libdimension/dimension/pigments.h | 32 | ||||
-rw-r--r-- | libdimension/dimension/texture.h | 59 | ||||
-rw-r--r-- | libdimension/object.c | 1 | ||||
-rw-r--r-- | libdimension/pigments.c | 64 | ||||
-rw-r--r-- | libdimension/texture.c | 50 |
8 files changed, 222 insertions, 8 deletions
diff --git a/libdimension/Makefile.am b/libdimension/Makefile.am index ea12794..2333baf 100644 --- a/libdimension/Makefile.am +++ b/libdimension/Makefile.am @@ -26,12 +26,14 @@ nobase_include_HEADERS = dimension.h \ dimension/error.h \ dimension/geometry.h \ dimension/gl.h \ - dimension/png.h \ - dimension/progress.h \ dimension/object.h \ dimension/objects.h \ + dimension/pigments.h \ + dimension/png.h \ + dimension/progress.h \ dimension/raytrace.h \ - dimension/scene.h + dimension/scene.h \ + dimension/texture.h lib_LTLIBRARIES = libdimension.la @@ -44,11 +46,13 @@ libdimension_la_SOURCES = $(nobase_include_HEADERS) \ geometry.c \ gl.c \ inlines.c \ - png.c \ - progress.c \ object.c \ objects.c \ + pigments.c \ + png.c \ + progress.c \ raytrace.c \ - scene.c + scene.c \ + texture.c libdimension_la_LDFLAGS = -version-info 0:0:0 libdimension_la_LIBADD = -lm -lpthread -lpng -lGL diff --git a/libdimension/dimension.h b/libdimension/dimension.h index 684748d..0c6ae26 100644 --- a/libdimension/dimension.h +++ b/libdimension/dimension.h @@ -65,6 +65,8 @@ extern "C" { #include <dimension/canvas.h> #include <dimension/gl.h> #include <dimension/png.h> +#include <dimension/texture.h> +#include <dimension/pigments.h> #include <dimension/object.h> #include <dimension/objects.h> #include <dimension/camera.h> diff --git a/libdimension/dimension/object.h b/libdimension/dimension/object.h index 314a543..2da3ac7 100644 --- a/libdimension/dimension/object.h +++ b/libdimension/dimension/object.h @@ -35,8 +35,7 @@ typedef int dmnsn_object_inside_fn(const dmnsn_object *object, dmnsn_vector point); struct dmnsn_object { - /* Generic pointer for object info */ - void *ptr; + dmnsn_texture *texture; /* Transformation matrix */ dmnsn_matrix trans; @@ -44,6 +43,9 @@ struct dmnsn_object { /* Callback functions */ dmnsn_object_intersections_fn *intersections_fn; dmnsn_object_inside_fn *inside_fn; + + /* Generic pointer for object info */ + void *ptr; }; /* Allocate a dummy object */ diff --git a/libdimension/dimension/pigments.h b/libdimension/dimension/pigments.h new file mode 100644 index 0000000..ed0c3b2 --- /dev/null +++ b/libdimension/dimension/pigments.h @@ -0,0 +1,32 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +/* + * Custom pigments. + */ + +#ifndef DIMENSION_PIGMENTS_H +#define DIMENSION_PIGMENTS_H + +/* A solid color */ +dmnsn_pigment *dmnsn_new_solid_pigment(dmnsn_color color); +void dmnsn_delete_solid_pigment(dmnsn_pigment *pigment); + +#endif /* DIMENSION_PIGMENTS_H */ diff --git a/libdimension/dimension/texture.h b/libdimension/dimension/texture.h new file mode 100644 index 0000000..2eabe84 --- /dev/null +++ b/libdimension/dimension/texture.h @@ -0,0 +1,59 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +/* + * Object textures. + */ + +#ifndef DIMENSION_TEXTURE_H +#define DIMENSION_TEXTURE_H + +/* + * Pigments + */ + +/* Forward-declare dmnsn_pigment */ +typedef struct dmnsn_pigment dmnsn_pigment; + +/* Pigment callback */ +typedef dmnsn_color dmnsn_pigment_fn(const dmnsn_pigment *pigment, + dmnsn_vector v); + +/* dmnsn_pigment definition */ +struct dmnsn_pigment { + dmnsn_pigment_fn *pigment_fn; + void *ptr; +}; + +dmnsn_pigment *dmnsn_new_pigment(); +void dmnsn_delete_pigment(dmnsn_pigment *pigment); + +/* + * A complete texture + */ + +typedef struct { + dmnsn_pigment *pigment; +} dmnsn_texture; + +dmnsn_texture *dmnsn_new_texture(); +void dmnsn_delete_texture(dmnsn_texture *texture); + +#endif /* DIMENSION_TEXTURE_H */ diff --git a/libdimension/object.c b/libdimension/object.c index d4779dc..0556921 100644 --- a/libdimension/object.c +++ b/libdimension/object.c @@ -27,6 +27,7 @@ dmnsn_new_object() { dmnsn_object *object = malloc(sizeof(dmnsn_object)); if (object) { + object->texture = NULL; object->trans = dmnsn_identity_matrix(); } return object; diff --git a/libdimension/pigments.c b/libdimension/pigments.c new file mode 100644 index 0000000..3b417f6 --- /dev/null +++ b/libdimension/pigments.c @@ -0,0 +1,64 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "dimension.h" +#include <stdlib.h> /* For malloc */ + +/* Solid color pigment callback */ +static dmnsn_color dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, + dmnsn_vector v); + +/* Create a solid color */ +dmnsn_pigment * +dmnsn_new_solid_pigment(dmnsn_color color) +{ + dmnsn_color *solid; + dmnsn_pigment *pigment = dmnsn_new_pigment(); + if (pigment) { + solid = malloc(sizeof(dmnsn_color)); + if (!solid) { + dmnsn_delete_pigment(pigment); + return NULL; + } + *solid = color; + + pigment->pigment_fn = &dmnsn_solid_pigment_fn; + pigment->ptr = solid; + } + + return pigment; +} + +/* Destroy a solid color */ +void dmnsn_delete_solid_pigment(dmnsn_pigment *pigment) +{ + if (pigment) { + free(pigment->ptr); + dmnsn_delete_pigment(pigment); + } +} + +/* Solid color callback */ +static dmnsn_color +dmnsn_solid_pigment_fn(const dmnsn_pigment *pigment, dmnsn_vector v) +{ + dmnsn_color *color = pigment->ptr; + return *color; +} diff --git a/libdimension/texture.c b/libdimension/texture.c new file mode 100644 index 0000000..511c6b0 --- /dev/null +++ b/libdimension/texture.c @@ -0,0 +1,50 @@ +/************************************************************************* + * Copyright (C) 2009 Tavian Barnes <tavianator@gmail.com> * + * * + * This file is part of The Dimension Library. * + * * + * The Dimension Library is free software; you can redistribute it and/ * + * or modify it under the terms of the GNU Lesser General Public License * + * as published by the Free Software Foundation; either version 3 of the * + * License, or (at your option) any later version. * + * * + * The Dimension Library is distributed in the hope that it will be * + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty * + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * + * Lesser General Public License for more details. * + * * + * You should have received a copy of the GNU Lesser General Public * + * License along with this program. If not, see * + * <http://www.gnu.org/licenses/>. * + *************************************************************************/ + +#include "dimension.h" +#include <stdlib.h> /* For malloc */ + +/* Allocate an dummy pigment */ +dmnsn_pigment * +dmnsn_new_pigment() +{ + return malloc(sizeof(dmnsn_pigment)); +} + +/* Free a dummy pigment */ +void +dmnsn_delete_pigment(dmnsn_pigment *pigment) +{ + free(pigment); +} + +/* Allocate a dummy texture */ +dmnsn_texture * +dmnsn_new_texture() +{ + return malloc(sizeof(dmnsn_texture)); +} + +/* Free a dummy texture */ +void +dmnsn_delete_texture(dmnsn_texture *texture) +{ + free(texture); +} |