aboutsummaryrefslogtreecommitdiff
path: root/opengl/include
diff options
context:
space:
mode:
Diffstat (limited to 'opengl/include')
-rw-r--r--opengl/include/Makefile5
-rw-r--r--opengl/include/pdp_3Dcontext.h94
-rw-r--r--opengl/include/pdp_3dp_base.h35
-rw-r--r--opengl/include/pdp_mesh.h210
-rw-r--r--opengl/include/pdp_opengl.h33
-rw-r--r--opengl/include/pdp_texture.h93
6 files changed, 470 insertions, 0 deletions
diff --git a/opengl/include/Makefile b/opengl/include/Makefile
new file mode 100644
index 0000000..f2075ee
--- /dev/null
+++ b/opengl/include/Makefile
@@ -0,0 +1,5 @@
+all:
+
+clean:
+ rm -rf *~
+
diff --git a/opengl/include/pdp_3Dcontext.h b/opengl/include/pdp_3Dcontext.h
new file mode 100644
index 0000000..2af1dcf
--- /dev/null
+++ b/opengl/include/pdp_3Dcontext.h
@@ -0,0 +1,94 @@
+/*
+ * pdp system module - 3d render context packet type
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+
+/* the 3d render context packet: platform independent data structure
+ and method prototypes */
+
+
+#ifndef PDP_3DCONTEXT_H
+#define PDP_3DCONTEXT_H
+
+#include "pdp.h"
+
+
+
+
+typedef struct _3dcontext
+{
+ u32 encoding; /* the kind of render context */
+ u32 width; /* context width */
+ u32 height; /* context height */
+ u32 sub_width; /* portion that is currently used */
+ u32 sub_height;
+ void *drawable; /* context's drawable (i.e. Window, GLXPbuffer, ...) */
+ void *context; /* context's context object */
+
+} t_3Dcontext;
+
+#define PDP_3DCONTEXT 5 /* 3d context packet id */
+#define PDP_3DCONTEXT_WINDOW 1 /* window context packet id */
+#define PDP_3DCONTEXT_PBUFFER 2 /* pbuf context packet id */
+
+/* all symbols are C-style */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+ /* info methods */
+ u32 pdp_packet_3Dcontext_width(int packet);
+ u32 pdp_packet_3Dcontext_subwidth(int packet);
+ u32 pdp_packet_3Dcontext_height(int packet);
+ u32 pdp_packet_3Dcontext_subheight(int packet);
+ float pdp_packet_3Dcontext_subaspect(int packet);
+ int pdp_packet_3Dcontext_isvalid(int packet);
+ t_3Dcontext *pdp_packet_3Dcontext_info(int packet);
+
+
+ /* setters */
+ void pdp_packet_3Dcontext_set_subwidth(int packet, u32 w);
+ void pdp_packet_3Dcontext_set_subheight(int packet, u32 h);
+
+
+ /* render context activation and initialization */
+ void pdp_packet_3Dcontext_set_rendering_context(int packet);
+ void pdp_packet_3Dcontext_unset_rendering_context(int packet);
+ void pdp_packet_3Dcontext_setup_3d_context(int p);
+ void pdp_packet_3Dcontext_setup_2d_context(int p);
+
+ /* constructors */
+ int pdp_packet_new_3Dcontext_pbuf(u32 width, u32 height, u32 depth);
+ int pdp_packet_new_3Dcontext_win(void);
+
+ /* window specific methods */
+ void pdp_packet_3Dcontext_win_resize(int packet, int width, int height);
+ void pdp_packet_3Dcontext_win_send_events(int packet, t_outlet *outlet);
+ void pdp_packet_3Dcontext_win_cursor(int packet, bool toggle);
+ void pdp_packet_3Dcontext_win_swapbuffers(int packet);
+
+ /* converters */
+ int pdp_packet_3Dcontext_snap_to_bitmap(int packet, int w, int h);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/opengl/include/pdp_3dp_base.h b/opengl/include/pdp_3dp_base.h
new file mode 100644
index 0000000..5c53f51
--- /dev/null
+++ b/opengl/include/pdp_3dp_base.h
@@ -0,0 +1,35 @@
+#include "pdp_opengl.h"
+#include "pdp_dpd_base.h"
+
+typedef struct _pdp_3dp_base
+{
+ t_pdp_dpd_base b_base;
+
+} t_pdp_3dp_base;
+
+/* destructor */
+void pdp_3dp_base_free(void *x);
+
+/* init method */
+void pdp_3dp_base_init(void *x);
+
+/* class setup method */
+void pdp_3dp_base_setup(t_class *class);
+
+
+/* base class methods */
+#define pdp_3dp_base_get_context_packet pdp_dpd_base_get_context_packet
+#define pdp_3dp_base_set_context_packet pdp_dpd_base_set_context_packet
+#define pdp_3dp_base_add_outlet pdp_dpd_base_add_outlet
+#define pdp_3dp_base_add_cleanup pdp_dpd_base_add_cleanup
+#define pdp_3dp_base_add_inspect pdp_dpd_base_add_inspect
+#define pdp_3dp_base_disable_active_inlet pdp_dpd_base_disable_active_inlet
+#define pdp_3dp_base_move_context_packet pdp_dpd_base_move_context_packet
+#define pdp_3dp_base_bang pdp_dpd_base_bang
+#define pdp_3dp_base_get_queue pdp_dpd_base_get_queue
+#define pdp_3dp_base_enable_outlet pdp_dpd_base_enable_outlet
+#define pdp_3dp_base_register_complete_notify pdp_dpd_base_register_complete_notify
+#define pdp_3dp_base_register_get_command_object pdp_dpd_base_register_get_command_object
+#define pdp_3dp_base_queue_wait pdp_dpd_base_queue_wait
+#define pdp_3dp_base_queue_command pdp_dpd_base_queue_command
+
diff --git a/opengl/include/pdp_mesh.h b/opengl/include/pdp_mesh.h
new file mode 100644
index 0000000..8fd6dff
--- /dev/null
+++ b/opengl/include/pdp_mesh.h
@@ -0,0 +1,210 @@
+/*
+ * Pure Data Packet module. mesh object specification
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+/* a very naive approach to triangular meshes */
+
+#ifndef PDP_MESH_H
+#define PDP_MESH_H
+#include "pdp_list.h"
+
+
+/* VERTEX type
+ a vertex has a coordinate and normal vector
+ a list of triangles it is connected to
+ and a list of vertexes it is connected to (these count as links) */
+
+typedef struct _vertex
+{
+ float c[3]; // coordinates
+ float n[3]; // normal (or force vector)
+ t_pdp_list *trilist;
+ t_pdp_list *vertlist;
+} t_vertex;
+
+
+/* TRIANGLE type:
+ a triangle consist of
+ - 3 vertices
+ - 3 optional median vertices (subdivision intermediates) */
+typedef struct _triangle
+{
+ t_vertex *v[3]; // vertices
+ t_vertex *m[3]; // median vertices
+ float n[3]; //triangle normal
+} t_triangle;
+
+
+/* MESH type:
+ a mesh is a list of vertices
+ and a list of triangles (connections) */
+typedef struct _mesh
+{
+ t_pdp_list *triangles;
+ t_pdp_list *vertices;
+ int normal_type;
+ int refine_type;
+} t_mesh;
+
+
+
+/* object configuratie */
+#define MESH_NORMAL_SPHERE 1 // normal = origin -> vertex
+#define MESH_NORMAL_PRISM 2 // normal = center of gravity of prism base -> vertex
+#define MESH_NORMAL_RANDOM 3 // normal = random vector
+#define MESH_NORMAL_AVERAGE 4 // normal = average of surrounding triangles
+
+/* refinement method */
+#define MESH_REFINE_THREE 1 // triangle -> 3 triangles connecting center of gravity
+#define MESH_REFINE_FOUR 2 // triangle -> 4 triangles connecting link medians
+
+// vector utility stuff
+
+// fixed size iterators for the lazy
+#define I3(i) for(i=0; i<3; i++)
+#define I4(i) for(i=0; i<4; i++)
+
+static inline float _vector3_dot(float *v0, float *v1)
+{
+ float d;
+ d = v0[0] * v1[0];
+ d += v0[1] * v1[1];
+ d += v0[2] * v1[2];
+ return d;
+}
+
+static inline void _vector3_scale(float *v, float s)
+{
+ int k;
+ I3(k) v[k] *= s;
+}
+
+static inline float _vector3_normalize(float *v)
+{
+ float length = 0;
+ float scale = 0;
+ int k;
+ length = sqrt(_vector3_dot(v,v));
+ scale = 1.0f / length;
+ _vector3_scale(v, scale);
+ return length;
+}
+
+static inline void _vector3_cross(float *a, float *b, float *r)
+{
+ r[0] = a[1]*b[2] - a[2]*b[1];
+ r[1] = a[2]*b[0] - a[0]*b[2];
+ r[2] = a[0]*b[1] - a[1]*b[0];
+}
+
+static inline float _rand(void)
+{
+ long int r = random();
+ float f;
+ r -= (RAND_MAX >> 1);
+ f = (float)r;
+ f *= (2.0f / (float)RAND_MAX);
+ return f;
+}
+
+
+
+
+/* VERTEX methods */
+void vertex_add_triangle(t_vertex *v, t_triangle *t);
+void vertex_remove_triangle(t_vertex *v, t_triangle *t);
+void vertex_add_neighbour(t_vertex *v, t_vertex *neighbour);
+
+
+/* constructor/destructors are "private"
+ they may only be called by the mesh object to ensure
+ the vector list stays sound (i.e. without duplicates) */
+void _vertex_free(t_vertex *v);
+t_vertex *_vertex_new(float *c, float *n);
+
+
+void vertex_compute_normal_random(t_vertex *v);
+void vertex_compute_normal_sphere(t_vertex *v);
+void vertex_compute_normal_prism(t_vertex *v);
+float vertex_normalize(t_vertex *v);
+
+
+/* TRIANGLE methods */
+
+/* create triangle (a connection between 3 vertices):
+ counterclockwize with facing front
+ this method is "private"
+ you can only create triangles as part of a mesh */
+t_triangle *_triangle_new(t_vertex *v0, t_vertex *v1, t_vertex *v2);
+
+/* delete a triangle, disconnecting the vertices */
+void _triangle_free(t_triangle *t);
+
+/* get triangle that shares the link between v0 and v1 */
+t_triangle *triangle_neighbour(t_triangle *t, t_vertex *v0, t_vertex *v1);
+
+/* add a median vector to a link in a triangle
+ note: vertices must be in triangle, or behaviour is undefined */
+void triangle_add_median(t_triangle *t, t_vertex *v0, t_vertex *v1, t_vertex *median);
+
+/* MESH methods */
+
+/* add and remove methods for vertices and triangles */
+t_vertex *mesh_vertex_add(t_mesh *m, float *c, float *n);
+void mesh_vertex_remove(t_mesh *m, t_vertex *v);
+t_triangle *mesh_triangle_add(t_mesh *m, t_vertex *v0, t_vertex *v1, t_vertex *v2);
+void mesh_triangle_remove(t_mesh *m, t_triangle *t);
+
+/* calculate normals */
+void mesh_calculate_normals(t_mesh *m);
+
+/* split a triangle in 4, using the intermedia median vertex storage */
+void mesh_split_four(t_mesh *m, t_triangle *old_t);
+
+/* split a triangle in 3 */
+void mesh_split_three(t_mesh *m, t_triangle *old_t);
+
+void mesh_split_all_four(t_mesh *m);
+
+void mesh_split_all_three(t_mesh *m);
+
+void mesh_split_random_three(t_mesh *m);
+
+void mesh_free(t_mesh *m);
+
+t_mesh *_mesh_new(void);
+
+/* new tetra */
+t_mesh *mesh_new_tetra(void);
+
+
+
+void _mesh_relax_compute_resultant_spring(t_mesh *m, float *center, float d0, float r0);
+void _mesh_relax_apply_force(t_mesh *m, float k);
+void mesh_compute_center(t_mesh *m, float *c);
+void mesh_translate(t_mesh *m, float *c);
+
+/* relax a mesh (move toward equal link length) */
+void mesh_relax(t_mesh *m, float step, float d0, float r0);
+
+/* print some debug information */
+void mesh_debug(t_mesh *m);
+
+
+#endif
diff --git a/opengl/include/pdp_opengl.h b/opengl/include/pdp_opengl.h
new file mode 100644
index 0000000..c32735d
--- /dev/null
+++ b/opengl/include/pdp_opengl.h
@@ -0,0 +1,33 @@
+/*
+ * OpenGL Extension Module for pdp - Main header file
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef PDP_OPENGL_H
+#define PDP_OPENGL_H
+
+
+
+#include "pdp.h"
+#include "pdp_texture.h"
+#include "pdp_3Dcontext.h"
+
+t_pdp_procqueue* pdp_opengl_get_queue(void);
+
+
+#endif
diff --git a/opengl/include/pdp_texture.h b/opengl/include/pdp_texture.h
new file mode 100644
index 0000000..7a40cdd
--- /dev/null
+++ b/opengl/include/pdp_texture.h
@@ -0,0 +1,93 @@
+/*
+ * pdp system module - texture packet type
+ * Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef PDP_TEXTURE_H
+#define PDP_TEXTURE_H
+
+//#include <GL/gl.h>
+//#include <GL/glu.h>
+//#include <GL/glx.h>
+//#include <GL/glut.h>
+#include "pdp.h"
+
+
+
+
+
+/* TEXTURE PACKET */
+
+typedef struct
+{
+ u32 tex_obj; /* gl texture object */
+ s32 format; /* texture format */
+ u32 width; /* dims */
+ u32 height;
+
+ u32 sub_width; /* portion of texture used */
+ u32 sub_height;
+
+} t_texture;
+
+#define PDP_TEXTURE 4 /* opengl texture object */
+
+
+/* all symbols are C-style */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+
+/* check if valid texture packet. all other methods assume packet is valid */
+bool pdp_packet_texture_isvalid(int packet);
+
+/* returns a pointer to the packet subheader whem the packet contains a texture */
+/* try not to use the header directly, use clone and copy methods instead */
+t_texture *pdp_packet_texture_info(int packet);
+
+/* texture constructors */
+int pdp_packet_new_texture(u32 width, u32 height, s32 format); /* create a texture packet */
+
+
+/* texture operators */
+void pdp_packet_texture_make_current(int packet); /* make a texture the current texture context */
+u32 pdp_packet_texture_total_width(int packet); /* width of texture */
+u32 pdp_packet_texture_total_height(int packet); /* get heigth of texture */
+u32 pdp_packet_texture_sub_width(int packet); /* width of subtexture */
+u32 pdp_packet_texture_sub_height(int packet); /* heigth of subtexture */
+float pdp_packet_texture_fracx(int packet); /* x fraction */
+float pdp_packet_texture_fracy(int packet); /* y fraction */
+float pdp_packet_texture_sub_aspect(int packet);
+
+/* some utility methods */
+void pdp_packet_texture_make_current_enable(int packet); /* make current & enable with default texture settings (for the lazy)*/
+void pdp_packet_texture_setup_2d_context(int packet); /* set up 2d context (viewport, projection, modelview) from texture dims */
+
+
+
+
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif //PDP_TEXTURE_H