summaryrefslogtreecommitdiffstats
path: root/progs/glsl/deriv.c
diff options
context:
space:
mode:
Diffstat (limited to 'progs/glsl/deriv.c')
-rw-r--r--progs/glsl/deriv.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/progs/glsl/deriv.c b/progs/glsl/deriv.c
index 265a5157154..588246b71ac 100644
--- a/progs/glsl/deriv.c
+++ b/progs/glsl/deriv.c
@@ -27,11 +27,15 @@ static GLuint SphereList, RectList, CurList;
static GLint win = 0;
static GLboolean anim = GL_TRUE;
static GLfloat xRot = 0.0f, yRot = 0.0f;
+static GLint WinSize[2];
+static GLint WinSizeUniform = -1;
static void
Redisplay(void)
{
+ glUniform2iv(WinSizeUniform, 1, WinSize);
+
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushMatrix();
@@ -55,6 +59,8 @@ Idle(void)
static void
Reshape(int width, int height)
{
+ WinSize[0] = width;
+ WinSize[1] = height;
glViewport(0, 0, width, height);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
@@ -140,6 +146,7 @@ MakeSphere(void)
glNewList(SphereList, GL_COMPILE);
gluSphere(obj, 2.0f, 30, 15);
glEndList();
+ gluDeleteQuadric(obj);
}
@@ -162,8 +169,10 @@ static void
Init(void)
{
static const char *fragShaderText =
+ "uniform ivec2 WinSize; \n"
"void main() {\n"
- " gl_FragColor = abs(dFdy(gl_TexCoord[0])) * 50.0;\n"
+ " vec2 d = dFdy(gl_TexCoord[0].xy) * vec2(WinSize); \n"
+ " gl_FragColor = vec4(d.x, d.y, 0.0, 1.0);\n"
" // gl_FragColor = gl_TexCoord[0];\n"
"}\n";
static const char *vertShaderText =
@@ -180,6 +189,7 @@ Init(void)
program = LinkShaders(vertShader, fragShader);
glUseProgram(program);
+ WinSizeUniform = glGetUniformLocation(program, "WinSize");
/*assert(glGetError() == 0);*/
@@ -219,8 +229,10 @@ ParseOptions(int argc, char *argv[])
int
main(int argc, char *argv[])
{
+ WinSize[0] = WinSize[1] = 200;
+
glutInit(&argc, argv);
- glutInitWindowSize(200, 200);
+ glutInitWindowSize(WinSize[0], WinSize[1]);
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
win = glutCreateWindow(argv[0]);
glewInit();