aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/extras/Mesa_6.4.2/progs/samples/tkmap.c
blob: 3ded79cacaa0e083b7fced4ef9566b22f7b7a3ad (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

enum {
    COLOR_BLACK = 0,
    COLOR_RED,
    COLOR_GREEN,
    COLOR_YELLOW,
    COLOR_BLUE,
    COLOR_MAGENTA,
    COLOR_CYAN,
    COLOR_WHITE
};

static float RGBMap[9][3] = {
    {0, 0, 0},
    {1, 0, 0},
    {0, 1, 0},
    {1, 1, 0},
    {0, 0, 1},
    {1, 0, 1},
    {0, 1, 1},
    {1, 1, 1},
    {0.5, 0.5, 0.5}
};

static void SetColor(int c)
{
    if (glutGet(GLUT_WINDOW_RGBA))
        glColor3fv(RGBMap[c]);
    else
        glIndexf(c);
}

static void InitMap(void)
{
    int i;

    if (rgb)
	return;

    for (i = 0; i < 9; i++)
	    glutSetColor(i, RGBMap[i][0], RGBMap[i][1], RGBMap[i][2]);
}

static void SetFogRamp(int density, int startIndex)
{
    int fogValues, colorValues;
    int i, j, k;
    float intensity;

    fogValues = 1 << density;
    colorValues = 1 << startIndex;
    for (i = 0; i < colorValues; i++) {
	for (j = 0; j < fogValues; j++) {
	    k = i * fogValues + j;
	    intensity = (i * fogValues + j * colorValues) / 255.0;
	    glutSetColor(k, intensity, intensity, intensity);
	}
    }
}

static void SetGreyRamp(void)
{
    int i;
    float intensity;

    for (i = 0; i < 255; i++) {
	intensity = i / 255.0;
	glutSetColor(i, intensity, intensity, intensity);
    }
}