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

« back to all changes in this revision

Viewing changes to opengl/modules/pdp_3d_push.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
 
 
23
 
#include <GL/gl.h>
24
 
#include "pdp_opengl.h"
25
 
#include "pdp_3dp_base.h"
26
 
 
27
 
typedef struct pdp_3d_push_struct
28
 
{
29
 
    t_pdp_3dp_base x_base;
30
 
    GLenum x_matrix;
31
 
    int x_change_mode;
32
 
 
33
 
} t_pdp_3d_push;
34
 
 
35
 
 
36
 
 
37
 
static void pdp_3d_push_process_right(t_pdp_3d_push *x)
38
 
{
39
 
    int p = pdp_3dp_base_get_context_packet(x);
40
 
    if (-1 != p){
41
 
 
42
 
        /* push one of the matrices */
43
 
        glMatrixMode(x->x_matrix);
44
 
        glPushMatrix();
45
 
 
46
 
        /* set default matrix to modelview */
47
 
        if (!x->x_change_mode) glMatrixMode(GL_MODELVIEW);
48
 
 
49
 
    }
50
 
}
51
 
static void pdp_3d_push_process_left(t_pdp_3d_push *x)
52
 
{
53
 
    int p = pdp_3dp_base_get_context_packet(x);
54
 
    if (-1 != p){
55
 
 
56
 
        /* restore the saved matrix */
57
 
        glMatrixMode(x->x_matrix);
58
 
        glPopMatrix();
59
 
 
60
 
        /* set default matrix back to modelview */
61
 
        glMatrixMode(GL_MODELVIEW);
62
 
 
63
 
    }
64
 
 
65
 
}
66
 
 
67
 
 
68
 
static void pdp_3d_mode_process_right(t_pdp_3d_push *x)
69
 
{
70
 
    int p = pdp_3dp_base_get_context_packet(x);
71
 
    if (-1 != p){
72
 
 
73
 
        /* change matrix mode */
74
 
        glMatrixMode(x->x_matrix);
75
 
 
76
 
    }
77
 
}
78
 
 
79
 
static void pdp_3d_mode_process_left(t_pdp_3d_push *x)
80
 
{
81
 
    int p = pdp_3dp_base_get_context_packet(x);
82
 
    if (-1 != p){
83
 
 
84
 
        /* restore default matrix to modelview */
85
 
        glMatrixMode(GL_MODELVIEW);
86
 
 
87
 
    }
88
 
}
89
 
 
90
 
 
91
 
static void pdp_3d_push_setmatrix(t_pdp_3d_push *x, t_symbol *s)
92
 
{
93
 
    GLenum m;
94
 
 
95
 
    /* find out which matrix to push */
96
 
    if (s == gensym("projection")) m = GL_PROJECTION;
97
 
    else if (s == gensym("modelview")) m = GL_MODELVIEW;
98
 
    else if (s == gensym("texture")) m = GL_TEXTURE;
99
 
    else if (s == gensym("color")) m = GL_COLOR;
100
 
 
101
 
    /* default is modelview */
102
 
    else m = GL_MODELVIEW;
103
 
 
104
 
    x->x_matrix = m;
105
 
}
106
 
 
107
 
 
108
 
t_class *pdp_3d_push_class;
109
 
 
110
 
 
111
 
 
112
 
void pdp_3d_push_free(t_pdp_3d_push *x)
113
 
{
114
 
    pdp_3dp_base_free(x);
115
 
}
116
 
 
117
 
void *pdp_3d_push_mode_new(t_symbol *s)
118
 
{
119
 
    t_pdp_3d_push *x = (t_pdp_3d_push *)pd_new(pdp_3d_push_class);
120
 
 
121
 
    /* super init */
122
 
    pdp_3dp_base_init(x);
123
 
 
124
 
    /* setup which matrix we are talking about */
125
 
    pdp_3d_push_setmatrix(x, s);
126
 
 
127
 
    x->x_change_mode = 0;
128
 
 
129
 
    return (void *)x;
130
 
}
131
 
 
132
 
void *pdp_3d_push_new(t_symbol *s, t_floatarg f)
133
 
{
134
 
    t_pdp_3d_push *x = (t_pdp_3d_push *)pdp_3d_push_mode_new(s);
135
 
 
136
 
    /* create dpd outlets */
137
 
    pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_push_process_left, 0);
138
 
    pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_push_process_right, 0);
139
 
 
140
 
    x->x_change_mode = (f != 0.0f);
141
 
    
142
 
    return (void *)x;
143
 
}
144
 
 
145
 
 
146
 
void *pdp_3d_mode_new(t_symbol *s)
147
 
{
148
 
    t_pdp_3d_push *x = (t_pdp_3d_push *)pdp_3d_push_mode_new(s);
149
 
 
150
 
    /* create dpd outlets */
151
 
    pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_mode_process_left, 0);
152
 
    pdp_3dp_base_add_outlet(x, (t_pdp_method)pdp_3d_mode_process_right, 0);
153
 
 
154
 
 
155
 
    return (void *)x;
156
 
}
157
 
 
158
 
 
159
 
 
160
 
#ifdef __cplusplus
161
 
extern "C"
162
 
{
163
 
#endif
164
 
 
165
 
 
166
 
void pdp_3d_push_setup(void)
167
 
{
168
 
 
169
 
 
170
 
    pdp_3d_push_class = class_new(gensym("3dp_push"), (t_newmethod)pdp_3d_push_new,
171
 
        (t_method)pdp_3d_push_free, sizeof(t_pdp_3d_push), 0, A_DEFSYMBOL, A_NULL);
172
 
 
173
 
    class_addcreator((t_newmethod)pdp_3d_mode_new, gensym("3dp_mode"), A_DEFSYMBOL, A_NULL);
174
 
 
175
 
    pdp_3dp_base_setup(pdp_3d_push_class);
176
 
 
177
 
}
178
 
 
179
 
#ifdef __cplusplus
180
 
}
181
 
#endif