summaryrefslogtreecommitdiffstats
path: root/chalk/colorspaces/wetsticky/ws/ogl_interface.c
blob: 76a552a9c3d66a9e9fd8e990ce1ff86c8375cbc7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
/*
        FILE:           xgl_interface.c
        PURPOSE:        Creation and access to a OpenGL window
			to wet+sticky using OpenGL
        AUTHOR:         David England
        VERSION:        1.00  (21-June-96)

Copyright 1991, 1992, 2002, 2003 Tunde Cockshott, Kevin Waite, David England. 

Contact David England d.england@livjm.ac.uk
School of Computing and Maths Sciences,
Liverpool John Moores University 
Liverpool L3 3AF
United Kingdom
Phone +44 151 231 2271


Wet and Sticky 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. Wet and Sticky 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 Wet and Sticky; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 

*/

#include <GL/gl.h>
#include <GL/glu.h>
/*#include <imp.h>*/
/*#include "aux.h"*/

#include <stdio.h>

#include "constants.h"
#include "types.h"
#include "engine.h"
#include "canvas.h"

static int count=0;


void nullProc()
{
}

void SetupCmap()
{
}

float Value(n1, n2, hue)
float n1, n2, hue;
{
	if (hue > 360 )
		hue = hue -360;
	else if (hue < 0 )
		hue = hue +360;
	if (hue < 60  )
		return n1+(n2-n1)*hue/60;
	else if (hue < 180 )
		return n2;
	else if (hue < 240 )
		return n1+(n2-n1)*(240-hue)/60;
	else return n1;
}


RGB_COLOUR hls_to_rgb(h, l, s)
int h;
float l;
float s;
{
RGB_COLOUR rgb_colour;
float m1, m2;

if (l <= 0.5 )
	m2 = l*(1+s);
else 
	m2 = l+s -  l*s;
m1 = 2*l-m2;

rgb_colour.r = Value(m1, m2, h+120);
rgb_colour.g = Value(m1,m2, h);
rgb_colour.b = Value(m1,m2, h-120);

return (rgb_colour);
}

void
DrawPoint(x,y,hls_col)
int x;
int y;
HLS_COLOUR hls_col;
/* Draw a point on the window and the back-up Pixmap */
{
RGB_COLOUR rgb_colour;

	rgb_colour = hls_to_rgb(hls_col.hue,
				hls_col.lightness,
				hls_col.saturation);


	printf("h %.2f l %.2f s %.2f\n", hls_col.hue, hls_col.lightness,
				hls_col.saturation);

	printf( "r %.2f g %.2f b %.2f\n", rgb_colour.r, rgb_colour.g,
                                rgb_colour.b);

	glColor3f(rgb_colour.r, rgb_colour.g, rgb_colour.b);

	glBegin(GL_POINTS);
		glVertex2s(x,y);
		glVertex2s(x+1,y+1);
	glEnd();

}

void
DrawVolumePoint(x,y,attr)
int x;
int y;
int attr;
{
/*set colour, draw point at offset */	
}

void
DrawDrynessPoint(x,y,attr)
int x;
int y;
int attr;
/* Draw a point on the window and the back-up Pixmap */
{

}

void
ClearWindow()
{

}

static void
CleanWindow()
/* Fill a window with a solid, white rectangle */
{
}


void CreateWindows(argc, argv, width, height)
int *argc;
char **argv;
int width;
int height;

{

	auxInitDisplayMode( AUX_RGBA);

	auxInitPosition(50,50, width*3, height);

	auxInitWindow(argv[0]);

	glClearColor(1.0, 1.0, 1.0, 0.0);

	glClear(GL_COLOR_BUFFER_BIT);

}


static void
draw_labels()
{
}

void paint_cell(cell, x, y)
CELL_PTR cell;
int x, y;

{
    DrawPoint(x,y, cell->contents.colour);

    /*  volColour is an index into the colour table in the range [0,255].
        It is used to give a false colour image of the canvas's volume.  */

    /*DrawVolumePoint(x,y,volColour);*/


    /*DrawDrynessPoint(x,y,dryness);*/
}




void draw_full_canvas()
{
   int x, y;
   CELL_PTR cell;
   POINT p;
 
          glClear(GL_COLOR_BUFFER_BIT);

  if (DEBUG) {
     printf ("Starting to paint full canvas...");
     fflush(stdout);
   }

   for (y=0; y < CANVAS_HEIGHT; y++) 
     for (x=0; x < CANVAS_WIDTH; x++) {
        p.x = x;
        p.y = y;
        cell = get_cell(p);
        paint_cell(cell, x, y);
     }

   glFlush();
	sleep(10);
  
  if (DEBUG) printf ("done.\n");
}

void
bump_map()
{
	POINT p;
	CELL_PTR cell;
	register int x, y;
	register int colour;


   for (y=0; y < CANVAS_HEIGHT; y++) {
     for (x=0; x < CANVAS_WIDTH; x++) {
        p.x = x;
        p.y = y;
        cell = get_cell(p);
	colour = (int) new_intensity_value(p);

/*	colour = (int) (cell->contents.colour.hue *
                        ((float) MAX_COLOUR_INDEX / 360.0));*/
	DrawDrynessPoint(x,y,colour);
     }
  }

}


void evolve_paint()
{
   int k;
   POINT p;
   CELL_PTR cell;
   int  new_x, new_y;
   extern int count;

	/*count++;
	if (count > 500) {
		fprintf(stderr,".");
		fflush(stderr);
		bump_map();
	}*/

   for (k=0; k < STEP_LIMIT; k++) single_step();
   while (TRUE) {
      next_cell_for_repaint(&cell, &p);
      if (cell == NIL) return;
      paint_cell(cell, p.x, p.y);     
	   glFlush();
   } 
      

}

void StartVolumeWindow()
{
}

void StartDrynessWindow()
{
}

void StartWindows()
{


        draw_full_canvas();
	compute_shade_vectors(); /* Set vectors for shading */
	draw_labels();

	/*auxIdleFunc(evolve_paint);
	
	auxMainLoop(draw_full_canvas);*/


}

void
stroke()
{
	
}


void
stroke_motion()
{

}