2
* Pure Data Packet module.
3
* Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
5
* This program is free software; you can redistribute it and/or modify
6
* it under the terms of the GNU General Public License as published by
7
* the Free Software Foundation; either version 2 of the License, or
8
* (at your option) any later version.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23
#include "pdp_3dp_base.h"
24
#include "pdp_opengl.h"
27
typedef struct _color_command
29
t_pdp_dpd_command x_base;
35
typedef struct _pdp_3d_color
37
t_pdp_3dp_base x_base;
38
t_pdp_dpd_commandfactory x_cfact;
50
static void pdp_3d_color_process_right(t_color_command *x)
53
if (pdp_packet_3Dcontext_isvalid(p)){
54
pdp_packet_3Dcontext_set_rendering_context(p);
57
glGetFloatv(GL_CURRENT_COLOR, x->x_oldcolor);
60
glColor4fv(x->x_newcolor);
65
static void pdp_3d_color_process_left(t_color_command *x)
68
if (pdp_packet_3Dcontext_isvalid(p)){
69
pdp_packet_3Dcontext_set_rendering_context(p);
71
/* restore old color */
72
glColor4fv(x->x_oldcolor);
76
pdp_dpd_command_suicide(x);
80
/* PD OBJECT METHODS */
81
static void *pdp_3d_color_get_new_command(t_pdp_3d_color *x)
83
t_color_command *c = (t_color_command *)pdp_dpd_commandfactory_get_new_command(&x->x_cfact);
84
c->x_newcolor[0] = x->x_red;
85
c->x_newcolor[1] = x->x_green;
86
c->x_newcolor[2] = x->x_blue;
87
c->x_newcolor[3] = x->x_alpha;
88
c->x_context = pdp_3dp_base_get_context_packet(x);
93
static void pdp_3d_color_set_r(t_pdp_3d_color *x, t_floatarg f) {x->x_red = f;}
94
static void pdp_3d_color_set_g(t_pdp_3d_color *x, t_floatarg f) {x->x_green = f;}
95
static void pdp_3d_color_set_b(t_pdp_3d_color *x, t_floatarg f) {x->x_blue = f;}
96
static void pdp_3d_color_set_a(t_pdp_3d_color *x, t_floatarg f) {x->x_alpha = f;}
99
t_class *pdp_3d_color_class;
102
void pdp_3d_color_free(t_pdp_3d_color *x)
104
pdp_3dp_base_free(x);
107
void *pdp_3d_color_new(t_floatarg r, t_floatarg g, t_floatarg b, t_floatarg a)
109
t_pdp_3d_color *x = (t_pdp_3d_color *)pd_new(pdp_3d_color_class);
112
pdp_3dp_base_init(x);
116
pdp_base_add_gen_inlet(x, gensym("float"), gensym("r"));
117
pdp_base_add_gen_inlet(x, gensym("float"), gensym("g"));
118
pdp_base_add_gen_inlet(x, gensym("float"), gensym("b"));
119
pdp_base_add_gen_inlet(x, gensym("float"), gensym("a"));
122
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_color_process_left, 0);
123
pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_color_process_right, 0);
131
pdp_dpd_commandfactory_init(&x->x_cfact, sizeof(t_color_command));
133
/* register command factory method */
134
pdp_dpd_base_register_command_factory_method(x, (t_pdp_newmethod)pdp_3d_color_get_new_command);
146
void pdp_3d_color_setup(void)
150
pdp_3d_color_class = class_new(gensym("3dp_color"), (t_newmethod)pdp_3d_color_new,
151
(t_method)pdp_3d_color_free, sizeof(t_pdp_3d_color), 0,
152
A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_DEFFLOAT, A_NULL);
155
pdp_3dp_base_setup(pdp_3d_color_class);
157
class_addmethod(pdp_3d_color_class, (t_method)pdp_3d_color_set_r, gensym("r"), A_FLOAT, A_NULL);
158
class_addmethod(pdp_3d_color_class, (t_method)pdp_3d_color_set_g, gensym("g"), A_FLOAT, A_NULL);
159
class_addmethod(pdp_3d_color_class, (t_method)pdp_3d_color_set_b, gensym("b"), A_FLOAT, A_NULL);
160
class_addmethod(pdp_3d_color_class, (t_method)pdp_3d_color_set_a, gensym("a"), A_FLOAT, A_NULL);