Add more structure constructor tests.
[piglit/hramrach.git] / tests / shaders / fp-fog.c
blobd685e34fb39d28bb90eec1f6efdaeeebd3a0646b
1 /*
2 * Copyright © 2008 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
21 * DEALINGS IN THE SOFTWARE.
24 /**
25 * \file
26 * Test passing fog coordinates into a fragment program.
28 * \author Ian Romanick <ian.d.romanick@intel.com>
31 #include "piglit-util.h"
33 static GLint prog = 0;
35 static const char* const program_text =
36 "!!ARBfp1.0\n"
37 "MOV result.color, fragment.fogcoord;\n"
38 "END\n"
41 int piglit_width = 50, piglit_height = 50;
42 int piglit_window_mode = GLUT_RGBA | GLUT_ALPHA | GLUT_DOUBLE;
44 static PFNGLFOGCOORDFPROC pglFogCoordf = NULL;
46 enum piglit_result
47 piglit_display(void)
49 static const struct {
50 float x, y, r;
52 probes[4] = {
53 { 0.5, 1.5, 0.3 },
54 { 1.5, 1.5, 0.6 },
55 { 0.5, 0.5, 0.8 },
56 { 1.5, 0.5, 0.4 },
58 int pass = 1;
59 unsigned i;
61 glClear(GL_COLOR_BUFFER_BIT);
63 pglFogCoordf(0.3);
64 glBegin(GL_QUADS);
65 glVertex2f(0, 1);
66 glVertex2f(1, 1);
67 glVertex2f(1, 2);
68 glVertex2f(0, 2);
69 glEnd();
71 pglFogCoordf(0.6);
72 glBegin(GL_QUADS);
73 glVertex2f(1, 1);
74 glVertex2f(2, 1);
75 glVertex2f(2, 2);
76 glVertex2f(1, 2);
77 glEnd();
79 pglFogCoordf(0.8);
80 glBegin(GL_QUADS);
81 glVertex2f(0, 0);
82 glVertex2f(1, 0);
83 glVertex2f(1, 1);
84 glVertex2f(0, 1);
85 glEnd();
87 pglFogCoordf(0.4);
88 glBegin(GL_QUADS);
89 glVertex2f(1, 0);
90 glVertex2f(2, 0);
91 glVertex2f(2, 1);
92 glVertex2f(1, 1);
93 glEnd();
95 for (i = 0; i < 4; i++) {
96 float expected_color[4];
98 expected_color[0] = probes[i].r;
99 expected_color[1] = 0.0;
100 expected_color[2] = 0.0;
101 expected_color[3] = 1.0;
103 pass &= piglit_probe_pixel_rgba(probes[i].x * piglit_width / 2,
104 probes[i].y * piglit_height / 2,
105 expected_color);
108 glutSwapBuffers();
110 return pass ? PIGLIT_SUCCESS : PIGLIT_FAILURE;
114 static void Reshape(int width, int height)
116 piglit_width = width;
117 piglit_height = height;
119 glViewport(0, 0, width, height);
120 glMatrixMode(GL_PROJECTION);
121 glLoadIdentity();
122 glOrtho(0.0, 2.0, 0.0, 2.0, -2.0, 6.0);
123 glScalef(1.0, 1.0, -1.0); // flip z-axis
124 glMatrixMode(GL_MODELVIEW);
125 glLoadIdentity();
128 void
129 piglit_init(int argc, char **argv)
131 glewInit();
132 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
134 glutReshapeFunc(Reshape);
136 glClearColor(0.3, 0.3, 0.3, 0.3);
138 if (GLEW_VERSION_1_4) {
139 pglFogCoordf = glFogCoordf;
140 } else if (GLEW_EXT_fog_coord) {
141 pglFogCoordf = glFogCoordfEXT;
142 } else {
143 piglit_report_result(PIGLIT_SKIP);
146 piglit_require_fragment_program();
147 prog = piglit_compile_program(GL_FRAGMENT_PROGRAM_ARB, program_text);
149 glEnable(GL_FRAGMENT_PROGRAM_ARB);
150 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, prog);
152 glFogi(GL_FOG_COORDINATE_SOURCE_EXT, GL_FOG_COORDINATE_EXT);
154 Reshape(piglit_width, piglit_height);