2 * Another test for noise() functions (noise1 to noise4 tested independently).
14 static const char *VertShaderText
=
16 " gl_TexCoord[0].xyz = gl_Vertex.xyz;\n"
17 " gl_TexCoord[0].w = gl_MultiTexCoord1.x;\n"
18 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
21 static const char *FragShaderText
[ 4 ] = {
24 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].w ) * 0.5 + 0.5;\n"
25 " gl_FragColor.a = 1;\n"
29 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xw ) * 0.5 + 0.5;\n"
30 " gl_FragColor.a = 1;\n"
34 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyw ) * 0.5 + 0.5;\n"
35 " gl_FragColor.a = 1;\n"
39 " gl_FragColor.rgb = noise3( gl_TexCoord[ 0 ].xyzw ) * 0.5 + 0.5;\n"
40 " gl_FragColor.a = 1;\n"
51 /* program/shader objects */
52 static GLuint fragShader
[ 4 ];
53 static GLuint vertShader
;
54 static GLuint program
[ 4 ];
57 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
58 static GLfloat Slice
= 0.0;
59 static GLboolean Anim
= GL_FALSE
;
73 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
75 glMultiTexCoord1f( GL_TEXTURE1
, Slice
);
78 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
79 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
80 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
82 glutSolidTeapot( 1.0 );
91 Reshape(int width
, int height
)
93 glViewport(0, 0, width
, height
);
94 glMatrixMode(GL_PROJECTION
);
96 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
97 glMatrixMode(GL_MODELVIEW
);
99 glTranslatef(0.0f
, 0.0f
, -15.0f
);
108 glDeleteShader(vertShader
);
109 for( i
= 0; i
< 4; i
++ ) {
110 glDeleteShader(fragShader
[ i
]);
111 glDeleteProgram(program
[ i
]);
113 glutDestroyWindow(win
);
118 Key(unsigned char key
, int x
, int y
)
120 const GLfloat step
= 0.01;
127 glutIdleFunc(Anim
? Idle
: NULL
);
144 glUseProgram(program
[ key
- '1' ]);
156 SpecialKey(int key
, int x
, int y
)
158 const GLfloat step
= 3.0f
;
183 LoadAndCompileShader(GLuint shader
, const char *text
)
187 glShaderSource(shader
, 1, (const GLchar
**) &text
, NULL
);
189 glCompileShader(shader
);
191 glGetShaderiv(shader
, GL_COMPILE_STATUS
, &stat
);
195 glGetShaderInfoLog(shader
, 1000, &len
, log
);
196 fprintf(stderr
, "noise: problem compiling shader: %s\n", log
);
200 printf("Shader compiled OK\n");
206 CheckLink(GLuint prog
)
209 glGetProgramiv(prog
, GL_LINK_STATUS
, &stat
);
213 glGetProgramInfoLog(prog
, 1000, &len
, log
);
214 fprintf(stderr
, "Linker error:\n%s\n", log
);
217 fprintf(stderr
, "Link success!\n");
228 version
= (const char *) glGetString(GL_VERSION
);
229 if (version
[0] != '2' || version
[1] != '.') {
230 printf("Warning: this program expects OpenGL 2.0\n");
234 vertShader
= glCreateShader(GL_VERTEX_SHADER
);
235 LoadAndCompileShader(vertShader
, VertShaderText
);
237 for( i
= 0; i
< 4; i
++ ) {
238 fragShader
[ i
] = glCreateShader(GL_FRAGMENT_SHADER
);
239 LoadAndCompileShader(fragShader
[ i
], FragShaderText
[ i
]);
240 program
[ i
] = glCreateProgram();
241 glAttachShader(program
[ i
], fragShader
[ i
]);
242 glAttachShader(program
[ i
], vertShader
);
243 glLinkProgram(program
[ i
]);
244 CheckLink(program
[ i
]);
247 glUseProgram(program
[ 0 ]);
249 assert(glGetError() == 0);
251 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
255 glFrontFace( GL_CW
);
256 glEnable( GL_CULL_FACE
);
257 glEnable( GL_DEPTH_TEST
);
262 main(int argc
, char *argv
[])
264 glutInit(&argc
, argv
);
265 glutInitWindowSize(400, 400);
266 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
267 win
= glutCreateWindow(argv
[0]);
269 glutReshapeFunc(Reshape
);
270 glutKeyboardFunc(Key
);
271 glutSpecialFunc(SpecialKey
);
272 glutDisplayFunc(Redisplay
);