2 * Another test for noise() functions (noise1 to noise4 tested independently).
16 static const char *VertShaderText
=
18 " gl_TexCoord[0].xyz = gl_Vertex.xyz;\n"
19 " gl_TexCoord[0].w = gl_MultiTexCoord1.x;\n"
20 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
23 static const char *FragShaderText
[ 4 ] = {
26 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].w ) * 0.5 + 0.5;\n"
27 " gl_FragColor.a = 1;\n"
31 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xw ) * 0.5 + 0.5;\n"
32 " gl_FragColor.a = 1;\n"
36 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyw ) * 0.5 + 0.5;\n"
37 " gl_FragColor.a = 1;\n"
41 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyzw ) * 0.5 + 0.5;\n"
42 " gl_FragColor.a = 1;\n"
53 /* program/shader objects */
54 static GLuint fragShader
[ 4 ];
55 static GLuint vertShader
;
56 static GLuint program
[ 4 ];
59 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
60 static GLfloat Slice
= 0.0;
61 static GLboolean Anim
= GL_FALSE
;
75 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
77 glMultiTexCoord1f( GL_TEXTURE1
, Slice
);
80 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
81 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
82 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
84 glutSolidTeapot( 1.0 );
93 Reshape(int width
, int height
)
95 glViewport(0, 0, width
, height
);
96 glMatrixMode(GL_PROJECTION
);
98 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
99 glMatrixMode(GL_MODELVIEW
);
101 glTranslatef(0.0f
, 0.0f
, -15.0f
);
110 glDeleteShader_func(vertShader
);
111 for( i
= 0; i
< 4; i
++ ) {
112 glDeleteShader_func(fragShader
[ i
]);
113 glDeleteProgram_func(program
[ i
]);
115 glutDestroyWindow(win
);
120 Key(unsigned char key
, int x
, int y
)
122 const GLfloat step
= 0.01;
129 glutIdleFunc(Anim
? Idle
: NULL
);
146 glUseProgram_func(program
[ key
- '1' ]);
158 SpecialKey(int key
, int x
, int y
)
160 const GLfloat step
= 3.0f
;
185 LoadAndCompileShader(GLuint shader
, const char *text
)
189 glShaderSource_func(shader
, 1, (const GLchar
**) &text
, NULL
);
191 glCompileShader_func(shader
);
193 glGetShaderiv_func(shader
, GL_COMPILE_STATUS
, &stat
);
197 glGetShaderInfoLog_func(shader
, 1000, &len
, log
);
198 fprintf(stderr
, "noise: problem compiling shader: %s\n", log
);
202 printf("Shader compiled OK\n");
208 CheckLink(GLuint prog
)
211 glGetProgramiv_func(prog
, GL_LINK_STATUS
, &stat
);
215 glGetProgramInfoLog_func(prog
, 1000, &len
, log
);
216 fprintf(stderr
, "Linker error:\n%s\n", log
);
219 fprintf(stderr
, "Link success!\n");
230 version
= (const char *) glGetString(GL_VERSION
);
231 if (version
[0] != '2' || version
[1] != '.') {
232 printf("Warning: this program expects OpenGL 2.0\n");
238 vertShader
= glCreateShader_func(GL_VERTEX_SHADER
);
239 LoadAndCompileShader(vertShader
, VertShaderText
);
241 for( i
= 0; i
< 4; i
++ ) {
242 fragShader
[ i
] = glCreateShader_func(GL_FRAGMENT_SHADER
);
243 LoadAndCompileShader(fragShader
[ i
], FragShaderText
[ i
]);
244 program
[ i
] = glCreateProgram_func();
245 glAttachShader_func(program
[ i
], fragShader
[ i
]);
246 glAttachShader_func(program
[ i
], vertShader
);
247 glLinkProgram_func(program
[ i
]);
248 CheckLink(program
[ i
]);
251 glUseProgram_func(program
[ 0 ]);
253 assert(glGetError() == 0);
255 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
259 glFrontFace( GL_CW
);
260 glEnable( GL_CULL_FACE
);
261 glEnable( GL_DEPTH_TEST
);
266 main(int argc
, char *argv
[])
268 glutInit(&argc
, argv
);
269 glutInitWindowPosition( 0, 0);
270 glutInitWindowSize(400, 400);
271 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
272 win
= glutCreateWindow(argv
[0]);
273 glutReshapeFunc(Reshape
);
274 glutKeyboardFunc(Key
);
275 glutSpecialFunc(SpecialKey
);
276 glutDisplayFunc(Redisplay
);