2 * Test OpenGL 2.0 dx/dy functions for texcoords.
6 * NOTE: resize the window to observe how the partial derivatives of
7 * the texcoords change.
20 #include "shaderutil.h"
23 static char *FragProgFile
= NULL
;
24 static char *VertProgFile
= NULL
;
25 static GLuint fragShader
;
26 static GLuint vertShader
;
27 static GLuint program
;
28 static GLuint SphereList
, RectList
, CurList
;
30 static GLboolean anim
= GL_TRUE
;
31 static GLfloat xRot
= 0.0f
, yRot
= 0.0f
;
37 glClear(GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
40 glRotatef(xRot
, 1.0f
, 0.0f
, 0.0f
);
41 glRotatef(yRot
, 0.0f
, 1.0f
, 0.0f
);
52 yRot
= glutGet(GLUT_ELAPSED_TIME
) * 0.1;
58 Reshape(int width
, int height
)
60 glViewport(0, 0, width
, height
);
61 glMatrixMode(GL_PROJECTION
);
63 glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 25.0);
64 glMatrixMode(GL_MODELVIEW
);
66 glTranslatef(0.0f
, 0.0f
, -15.0f
);
73 glDeleteShader_func(fragShader
);
74 glDeleteShader_func(vertShader
);
75 glDeleteProgram_func(program
);
76 glutDestroyWindow(win
);
81 Key(unsigned char key
, int x
, int y
)
96 if (CurList
== SphereList
)
111 SpecialKey(int key
, int x
, int y
)
113 const GLfloat step
= 3.0f
;
139 GLUquadricObj
*obj
= gluNewQuadric();
140 SphereList
= glGenLists(1);
141 gluQuadricTexture(obj
, GL_TRUE
);
142 glNewList(SphereList
, GL_COMPILE
);
143 gluSphere(obj
, 2.0f
, 30, 15);
151 RectList
= glGenLists(1);
152 glNewList(RectList
, GL_COMPILE
);
154 glTexCoord2f(0, 0); glVertex2f(-2, -2);
155 glTexCoord2f(1, 0); glVertex2f( 2, -2);
156 glTexCoord2f(1, 1); glVertex2f( 2, 2);
157 glTexCoord2f(0, 1); glVertex2f(-2, 2);
166 static const char *fragShaderText
=
168 " gl_FragColor = abs(dFdy(gl_TexCoord[0])) * 50.0;\n"
169 " // gl_FragColor = gl_TexCoord[0];\n"
171 static const char *vertShaderText
=
173 " gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;\n"
174 " gl_TexCoord[0] = gl_MultiTexCoord0;\n"
177 if (!ShadersSupported())
182 vertShader
= CompileShaderText(GL_VERTEX_SHADER
, vertShaderText
);
183 fragShader
= CompileShaderText(GL_FRAGMENT_SHADER
, fragShaderText
);
184 program
= LinkShaders(vertShader
, fragShader
);
186 glUseProgram_func(program
);
188 /*assert(glGetError() == 0);*/
190 glClearColor(0.3f
, 0.3f
, 0.3f
, 0.0f
);
191 glEnable(GL_DEPTH_TEST
);
196 CurList
= SphereList
;
198 printf("GL_RENDERER = %s\n",(const char *) glGetString(GL_RENDERER
));
200 assert(glIsProgram_func(program
));
201 assert(glIsShader_func(fragShader
));
202 assert(glIsShader_func(vertShader
));
209 ParseOptions(int argc
, char *argv
[])
212 for (i
= 1; i
< argc
; i
++) {
213 if (strcmp(argv
[i
], "-fs") == 0) {
214 FragProgFile
= argv
[i
+1];
216 else if (strcmp(argv
[i
], "-vs") == 0) {
217 VertProgFile
= argv
[i
+1];
224 main(int argc
, char *argv
[])
226 glutInit(&argc
, argv
);
227 glutInitWindowPosition( 0, 0);
228 glutInitWindowSize(200, 200);
229 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
230 win
= glutCreateWindow(argv
[0]);
231 glutReshapeFunc(Reshape
);
232 glutKeyboardFunc(Key
);
233 glutSpecialFunc(SpecialKey
);
234 glutDisplayFunc(Redisplay
);
237 ParseOptions(argc
, argv
);