2 * Test noise() functions.
15 #include "shaderutil.h"
18 static const char *VertShaderText
=
20 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
21 " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
24 static const char *FragShaderText
=
25 "uniform vec4 Scale, Bias;\n"
26 "uniform float Slice;\n"
29 " vec4 scale = vec4(5.0);\n"
31 " p.xy = gl_TexCoord[0].xy;\n"
34 " vec4 n = noise4(p * scale);\n"
35 " gl_FragColor = n * Scale + Bias;\n"
39 static struct uniform_info Uniforms
[] = {
40 { "Scale", 4, GL_FLOAT
, { 0.5, 0.4, 0.0, 0}, -1 },
41 { "Bias", 4, GL_FLOAT
, { 0.5, 0.3, 0.0, 0}, -1 },
42 { "Slice", 1, GL_FLOAT
, { 0.5, 0, 0, 0}, -1 },
46 /* program/shader objects */
47 static GLuint fragShader
;
48 static GLuint vertShader
;
49 static GLuint program
;
52 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
, zRot
= 0.0f
;
53 static GLfloat Slice
= 0.0;
54 static GLboolean Anim
= GL_FALSE
;
68 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
70 glUniform1fv_func(Uniforms
[2].location
, 1, &Slice
);
73 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
74 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
75 glRotatef(zRot
, 0.0f
, 0.0f
, 1.0f
);
78 glTexCoord2f(0, 0); glVertex2f(-2, -2);
79 glTexCoord2f(1, 0); glVertex2f( 2, -2);
80 glTexCoord2f(1, 1); glVertex2f( 2, 2);
81 glTexCoord2f(0, 1); glVertex2f(-2, 2);
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
);
106 glDeleteShader_func(fragShader
);
107 glDeleteShader_func(vertShader
);
108 glDeleteProgram_func(program
);
109 glutDestroyWindow(win
);
114 Key(unsigned char key
, int x
, int y
)
116 const GLfloat step
= 0.01;
123 glutIdleFunc(Anim
? Idle
: NULL
);
146 SpecialKey(int key
, int x
, int y
)
148 const GLfloat step
= 3.0f
;
175 if (!ShadersSupported())
180 vertShader
= CompileShaderText(GL_VERTEX_SHADER
, VertShaderText
);
181 fragShader
= CompileShaderText(GL_FRAGMENT_SHADER
, FragShaderText
);
182 program
= LinkShaders(vertShader
, fragShader
);
184 glUseProgram_func(program
);
186 InitUniforms(program
, Uniforms
);
188 assert(glGetError() == 0);
190 glClearColor(0.4f
, 0.4f
, 0.8f
, 0.0f
);
192 printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER
));
194 assert(glIsProgram_func(program
));
195 assert(glIsShader_func(fragShader
));
196 assert(glIsShader_func(vertShader
));
203 main(int argc
, char *argv
[])
205 glutInit(&argc
, argv
);
206 glutInitWindowPosition( 0, 0);
207 glutInitWindowSize(400, 400);
208 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
209 win
= glutCreateWindow(argv
[0]);
210 glutReshapeFunc(Reshape
);
211 glutKeyboardFunc(Key
);
212 glutSpecialFunc(SpecialKey
);
213 glutDisplayFunc(Redisplay
);