2 * Copyright © 2011 VMware, Inc.
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
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
25 * Tests simple two-sided lighting with separate specular color.
27 * One command line option: if "flat" is specified, use flat shading.
28 * It shouldn't make any difference though because we only specify one normal
35 #include "piglit-util-gl.h"
37 PIGLIT_GL_TEST_CONFIG_BEGIN
39 config
.supports_gl_compat_version
= 10;
41 config
.window_width
= 256;
42 config
.window_height
= 256;
43 config
.window_visual
= PIGLIT_GL_VISUAL_RGB
| PIGLIT_GL_VISUAL_DOUBLE
;
45 PIGLIT_GL_TEST_CONFIG_END
47 static const GLfloat red
[4] = {1, 0, 0, 0};
48 static const GLfloat green
[4] = {0, 1, 0, 1};
49 static const GLfloat blue
[4] = {0, 0, 1, 1};
50 static const GLfloat purple
[4] = {1, 0, 1, 1};
51 static const GLfloat yellow
[4] = {1, 1, 0, 1};
57 int x0
= piglit_width
* 1 / 4;
58 int x1
= piglit_width
* 3 / 4;
59 int y0
= piglit_height
* 1 / 4;
60 int y1
= piglit_height
* 3 / 4;
61 GLboolean pass
= GL_TRUE
;
63 glClear(GL_COLOR_BUFFER_BIT
);
65 glFrontFace(GL_CCW
); /* the default winding */
68 /* counter-clockwise / front-facing */
70 glVertex2f(-1.0, -1.0);
71 glVertex2f( 0.0, -1.0);
72 glVertex2f( 0.0, 0.0);
73 glVertex2f(-1.0, 0.0);
75 /* clockwise / back-facing */
77 glVertex2f( 0.0, -1.0);
78 glVertex2f( 0.0, 0.0);
79 glVertex2f( 1.0, 0.0);
80 glVertex2f( 1.0, -1.0);
83 glFrontFace(GL_CW
); /* reverse winding */
86 /* counter-clockwise / back-facing */
88 glVertex2f(-1.0, 0.0);
89 glVertex2f( 0.0, 0.0);
90 glVertex2f( 0.0, 1.0);
91 glVertex2f(-1.0, 1.0);
93 /* clockwise / front-facing */
95 glVertex2f( 0.0, 0.0);
96 glVertex2f( 0.0, 1.0);
97 glVertex2f( 1.0, 1.0);
98 glVertex2f( 1.0, 0.0);
101 pass
= piglit_probe_pixel_rgb(x0
, y0
, yellow
) && pass
;
102 pass
= piglit_probe_pixel_rgb(x1
, y0
, purple
) && pass
;
103 pass
= piglit_probe_pixel_rgb(x0
, y1
, purple
) && pass
;
104 pass
= piglit_probe_pixel_rgb(x1
, y1
, yellow
) && pass
;
106 piglit_present_results();
108 return pass
? PIGLIT_PASS
: PIGLIT_FAIL
;
113 piglit_init(int argc
, char **argv
)
115 GLubyte teximage
[8][8][4];
119 for (i
= 1; i
< argc
; i
++) {
120 if (strcmp(argv
[i
], "flat") == 0) {
121 glShadeModel(GL_FLAT
);
126 glClearColor(0.5, 0.5, 0.5, 0.0);
128 glMatrixMode(GL_PROJECTION
);
130 glOrtho(-1.1, 1.1, -1.1, 1.1, -1.0, 1.0);
131 glMatrixMode(GL_MODELVIEW
);
134 /* front diffuse = green */
135 /* back diffuse = blue */
136 /* front/back specular = red */
137 glMaterialfv(GL_FRONT
, GL_AMBIENT_AND_DIFFUSE
, green
);
138 glMaterialfv(GL_BACK
, GL_AMBIENT_AND_DIFFUSE
, blue
);
139 glMaterialfv(GL_FRONT_AND_BACK
, GL_SPECULAR
, red
);
140 glLightModeli( GL_LIGHT_MODEL_COLOR_CONTROL
, GL_SEPARATE_SPECULAR_COLOR
);
141 glLightModeli(GL_LIGHT_MODEL_TWO_SIDE
, GL_TRUE
);
143 glEnable(GL_LIGHTING
);
145 /* make solid white texture */
146 glGenTextures(1, &t
);
147 glBindTexture(GL_TEXTURE_2D
, t
);
148 memset(teximage
, 255, sizeof(teximage
));
149 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
150 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
151 glTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 8, 8, 0,
152 GL_RGBA
, GL_UNSIGNED_BYTE
, teximage
);
153 glEnable(GL_TEXTURE_2D
);