2 * Another test for noise() functions (noise1 to noise4 tested independently).
17 static const char *VertShaderText
=
19 " gl_TexCoord[0].xyz = gl_Vertex.xyz;\n"
20 " gl_TexCoord[0].w = gl_MultiTexCoord1.x;\n"
21 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
24 static const char *FragShaderText
[ 4 ] = {
27 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].w ) * 0.5 + 0.5;\n"
28 " gl_FragColor.a = 1;\n"
32 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xw ) * 0.5 + 0.5;\n"
33 " gl_FragColor.a = 1;\n"
37 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyw ) * 0.5 + 0.5;\n"
38 " gl_FragColor.a = 1;\n"
42 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyzw ) * 0.5 + 0.5;\n"
43 " gl_FragColor.a = 1;\n"
54 /* program/shader objects */
55 static GLuint fragShader
[ 4 ];
56 static GLuint vertShader
;
57 static GLuint program
[ 4 ];
60 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
61 static GLfloat Slice
= 0.0;
62 static GLboolean Anim
= GL_FALSE
;
76 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
78 glMultiTexCoord1f( GL_TEXTURE1
, Slice
);
81 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
82 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
83 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
85 glutSolidTeapot( 1.0 );
94 Reshape(int width
, int height
)
96 glViewport(0, 0, width
, height
);
97 glMatrixMode(GL_PROJECTION
);
99 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
100 glMatrixMode(GL_MODELVIEW
);
102 glTranslatef(0.0f
, 0.0f
, -15.0f
);
111 glDeleteShader_func(vertShader
);
112 for( i
= 0; i
< 4; i
++ ) {
113 glDeleteShader_func(fragShader
[ i
]);
114 glDeleteProgram_func(program
[ i
]);
116 glutDestroyWindow(win
);
121 Key(unsigned char key
, int x
, int y
)
123 const GLfloat step
= 0.01;
130 glutIdleFunc(Anim
? Idle
: NULL
);
147 glUseProgram_func(program
[ key
- '1' ]);
159 SpecialKey(int key
, int x
, int y
)
161 const GLfloat step
= 3.0f
;
186 LoadAndCompileShader(GLuint shader
, const char *text
)
190 glShaderSource_func(shader
, 1, (const GLchar
**) &text
, NULL
);
192 glCompileShader_func(shader
);
194 glGetShaderiv_func(shader
, GL_COMPILE_STATUS
, &stat
);
198 glGetShaderInfoLog_func(shader
, 1000, &len
, log
);
199 fprintf(stderr
, "noise: problem compiling shader: %s\n", log
);
203 printf("Shader compiled OK\n");
209 CheckLink(GLuint prog
)
212 glGetProgramiv_func(prog
, GL_LINK_STATUS
, &stat
);
216 glGetProgramInfoLog_func(prog
, 1000, &len
, log
);
217 fprintf(stderr
, "Linker error:\n%s\n", log
);
220 fprintf(stderr
, "Link success!\n");
231 version
= (const char *) glGetString(GL_VERSION
);
232 if (version
[0] != '2' || version
[1] != '.') {
233 printf("Warning: this program expects OpenGL 2.0\n");
239 vertShader
= glCreateShader_func(GL_VERTEX_SHADER
);
240 LoadAndCompileShader(vertShader
, VertShaderText
);
242 for( i
= 0; i
< 4; i
++ ) {
243 fragShader
[ i
] = glCreateShader_func(GL_FRAGMENT_SHADER
);
244 LoadAndCompileShader(fragShader
[ i
], FragShaderText
[ i
]);
245 program
[ i
] = glCreateProgram_func();
246 glAttachShader_func(program
[ i
], fragShader
[ i
]);
247 glAttachShader_func(program
[ i
], vertShader
);
248 glLinkProgram_func(program
[ i
]);
249 CheckLink(program
[ i
]);
252 glUseProgram_func(program
[ 0 ]);
254 assert(glGetError() == 0);
256 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
260 glFrontFace( GL_CW
);
261 glEnable( GL_CULL_FACE
);
262 glEnable( GL_DEPTH_TEST
);
267 main(int argc
, char *argv
[])
269 glutInit(&argc
, argv
);
270 glutInitWindowPosition( 0, 0);
271 glutInitWindowSize(400, 400);
272 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
273 win
= glutCreateWindow(argv
[0]);
275 glutReshapeFunc(Reshape
);
276 glutKeyboardFunc(Key
);
277 glutSpecialFunc(SpecialKey
);
278 glutDisplayFunc(Redisplay
);