Mesa (master): progs/glsl: updates to deriv.c test

Brian Paul brianp at kemper.freedesktop.org
Mon Dec 7 08:04:40 PST 2009


Module: Mesa
Branch: master
Commit: 0311d9ccf4b717300a99355a02eff23935b4c08a
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=0311d9ccf4b717300a99355a02eff23935b4c08a

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Dec  7 09:03:39 2009 -0700

progs/glsl: updates to deriv.c test

Pass window size into the shader so scaling the window doesn't effect
the colors.

---

 progs/glsl/deriv.c |   15 +++++++++++++--
 1 files changed, 13 insertions(+), 2 deletions(-)

diff --git a/progs/glsl/deriv.c b/progs/glsl/deriv.c
index 30f2b75..588246b 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();
@@ -163,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 =
@@ -181,6 +189,7 @@ Init(void)
    program = LinkShaders(vertShader, fragShader);
 
    glUseProgram(program);
+   WinSizeUniform = glGetUniformLocation(program, "WinSize");
 
    /*assert(glGetError() == 0);*/
 
@@ -220,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();



More information about the mesa-commit mailing list