~kamalmostafa/ubuntu/lucid/pdp/fix-504941-ftbfs

« back to all changes in this revision

Viewing changes to opengl/modules/pdp_3d_color.c

  • Committer: Bazaar Package Importer
  • Author(s): Guenter Geiger (Debian/GNU)
  • Date: 2005-03-15 22:21:05 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20050315222105-1q287rsihmd9j1tb
Tags: 1:0.12.4-2
* fixed the hardcoded depends
* added 3dp library

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 *   Pure Data Packet module.
3
 
 *   Copyright (c) by Tom Schouten <pdp@zzz.kotnet.org>
4
 
 *
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.
9
 
 *
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.
14
 
 *
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.
18
 
 *
19
 
 */
20
 
 
21
 
 
22
 
#include <GL/gl.h>
23
 
#include "pdp_3dp_base.h"
24
 
#include "pdp_opengl.h"
25
 
 
26
 
 
27
 
typedef struct _color_command
28
 
{
29
 
    t_pdp_dpd_command x_base;
30
 
    int x_context;
31
 
    float x_newcolor[4];
32
 
    float x_oldcolor[4];
33
 
} t_color_command;
34
 
 
35
 
typedef struct _pdp_3d_color
36
 
{
37
 
    t_pdp_3dp_base x_base;
38
 
    t_pdp_dpd_commandfactory x_cfact;
39
 
 
40
 
    float x_red;
41
 
    float x_green;
42
 
    float x_blue;
43
 
    float x_alpha;
44
 
 
45
 
} t_pdp_3d_color;
46
 
 
47
 
 
48
 
 
49
 
/* COMMAND METHODS */
50
 
static void pdp_3d_color_process_right(t_color_command *x)
51
 
{
52
 
    int p = x->x_context;
53
 
    if (pdp_packet_3Dcontext_isvalid(p)){
54
 
        pdp_packet_3Dcontext_set_rendering_context(p);
55
 
 
56
 
        /* save old color*/
57
 
        glGetFloatv(GL_CURRENT_COLOR, x->x_oldcolor);
58
 
 
59
 
        /* set new color */
60
 
        glColor4fv(x->x_newcolor);
61
 
    }
62
 
 
63
 
}
64
 
 
65
 
static void pdp_3d_color_process_left(t_color_command *x)
66
 
{
67
 
    int p = x->x_context;
68
 
    if (pdp_packet_3Dcontext_isvalid(p)){
69
 
        pdp_packet_3Dcontext_set_rendering_context(p);
70
 
 
71
 
        /* restore old color */
72
 
        glColor4fv(x->x_oldcolor);
73
 
        //glColor4f(1,1,1,1);
74
 
    }
75
 
    /* kill self */
76
 
    pdp_dpd_command_suicide(x);
77
 
}
78
 
 
79
 
 
80
 
/* PD OBJECT METHODS */
81
 
static void *pdp_3d_color_get_new_command(t_pdp_3d_color *x)
82
 
{
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);
89
 
    return (void *)c;
90
 
}
91
 
 
92
 
 
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;}
97
 
 
98
 
 
99
 
t_class *pdp_3d_color_class;
100
 
 
101
 
 
102
 
void pdp_3d_color_free(t_pdp_3d_color *x)
103
 
{
104
 
    pdp_3dp_base_free(x);
105
 
}
106
 
 
107
 
void *pdp_3d_color_new(t_floatarg r, t_floatarg g, t_floatarg b, t_floatarg a)
108
 
{
109
 
    t_pdp_3d_color *x = (t_pdp_3d_color *)pd_new(pdp_3d_color_class);
110
 
 
111
 
    /* super init */
112
 
    pdp_3dp_base_init(x);
113
 
 
114
 
 
115
 
    /* input */
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"));
120
 
 
121
 
    /* output */
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);
124
 
 
125
 
    x->x_red = r;
126
 
    x->x_green = g;
127
 
    x->x_blue = b;
128
 
    x->x_alpha = a;
129
 
 
130
 
    /* init factory */
131
 
    pdp_dpd_commandfactory_init(&x->x_cfact, sizeof(t_color_command));
132
 
 
133
 
    /* register command factory method */
134
 
    pdp_dpd_base_register_command_factory_method(x, (t_pdp_newmethod)pdp_3d_color_get_new_command);
135
 
 
136
 
    return (void *)x;
137
 
}
138
 
 
139
 
 
140
 
#ifdef __cplusplus
141
 
extern "C"
142
 
{
143
 
#endif
144
 
 
145
 
 
146
 
void pdp_3d_color_setup(void)
147
 
{
148
 
 
149
 
 
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);
153
 
 
154
 
 
155
 
    pdp_3dp_base_setup(pdp_3d_color_class);
156
 
 
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);  
161
 
 
162
 
 
163
 
}
164
 
 
165
 
#ifdef __cplusplus
166
 
}
167
 
#endif