fix the spelling in whole piglit
[piglit.git] / tests / general / fog-modes.c
blobdea26f89b8d8c14bd94979628d2aa24962ac9c72
1 /*
2 * Copyright © 2010 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
24 /** @file fog-modes.c
26 * Tests that the three fog modes work with fog enabled using the depth value.
29 #include "piglit-util-gl.h"
31 PIGLIT_GL_TEST_CONFIG_BEGIN
33 config.supports_gl_compat_version = 10;
35 config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
37 PIGLIT_GL_TEST_CONFIG_END
39 enum piglit_result
40 piglit_display(void)
42 GLboolean pass = GL_TRUE;
43 int i, mode;
44 float zNear = 0.0, zFar = 1.0;
45 GLfloat fogcolor[4] = {1, 1, 1, 1};
47 glEnable(GL_FOG);
48 glFogfv(GL_FOG_COLOR, fogcolor);
49 glColor4f(0, 0, 0, 0.5);
51 glMatrixMode(GL_PROJECTION);
52 glLoadIdentity();
53 glOrtho(0, 1, 0, 1, -zNear, -zFar);
55 for (mode = 0; mode < 3; mode++) {
56 float y = mode / 3.0;
57 float h = 1.0 / 3.0;
59 switch (mode) {
60 case 0:
61 glFogi(GL_FOG_MODE, GL_LINEAR);
62 glFogf(GL_FOG_START, zNear);
63 glFogf(GL_FOG_END, zFar);
64 break;
65 case 1:
66 glFogi(GL_FOG_MODE, GL_EXP);
67 glFogf(GL_FOG_DENSITY, 2);
68 break;
69 case 2:
70 glFogi(GL_FOG_MODE, GL_EXP2);
71 glFogf(GL_FOG_DENSITY, 2);
72 break;
75 for (i = 0; i < 5; i++) {
76 float x = i / 5.0;
77 float w = 1.0 / 5.0;
78 float z = zNear + (zFar - zNear) * i / 5.0;
80 piglit_draw_rect_z(z, x, y, w, h);
84 for (mode = 0; mode < 3; mode++) {
85 float y = (mode + 0.5) / 3.0 * piglit_height;
86 for (i = 0; i < 5; i++) {
87 float x = (i + 0.5) / 5.0 * piglit_width;
88 float z = zNear + (zFar - zNear) * i / 5.0;
89 float f;
90 float color[4];
92 switch (mode) {
93 case 0:
94 f = (zFar - z) / (zFar - zNear);
95 break;
96 case 1:
97 f = expf(-(2.0 * z));
98 break;
99 case 2:
100 f = expf(-(2.0 * z) * (2.0 * z));
101 break;
103 if (f > 1.0)
104 f = 1.0;
105 if (f < 0.0)
106 f = 0.0;
108 color[0] = 1.0 - f;
109 color[1] = 1.0 - f;
110 color[2] = 1.0 - f;
111 color[3] = 0.5;
113 pass = pass & piglit_probe_pixel_rgba(x, y, color);
117 piglit_present_results();
119 return pass ? PIGLIT_PASS : PIGLIT_FAIL;
122 void piglit_init(int argc, char**argv)