Merge branch 'master' of git+ssh://znh@git.freedesktop.org/git/mesa/mesa into 965...
[mesa.git] / progs / samples / blendxor.c
index a46920d234564c0e3a96b194f258531c797978ec..5bc4aa9bea47801aeb43469f9f30ed4c5156b844 100644 (file)
 #include <unistd.h>
 #endif
 #include <stdlib.h>
+#ifdef _WIN32
+#include <windows.h>
+#endif
+#define GL_GLEXT_LEGACY
+#define GL_GLEXT_PROTOTYPES
 #include <GL/glut.h>
+#include <GL/glext.h>
 
 
 GLenum doubleBuffer;
 int dithering = 0;
+int use11ops = 0;
+int supportlogops = 0;
 GLint windW, windH;
 
 static void Init(void)
@@ -46,6 +54,13 @@ static void Key(unsigned char key, int x, int y)
       case 'd':
        dithering = !dithering;
        break;
+      case 'l':
+        if (supportlogops == 3)
+           use11ops = (!use11ops);
+        if (use11ops)
+           printf("Using GL 1.1 color logic ops.\n");
+        else printf("Using GL_EXT_blend_logic_op.\n");
+        break;
       default:
        return;
     }
@@ -58,6 +73,8 @@ static void Draw(void)
     int i;
 
     glDisable(GL_BLEND);
+    if (supportlogops & 2)
+       glDisable(GL_COLOR_LOGIC_OP);
 
     (dithering) ? glEnable(GL_DITHER) : glDisable(GL_DITHER);
 
@@ -79,7 +96,10 @@ static void Draw(void)
     glEnd();
 
     glEnable(GL_BLEND);
-    glBlendEquationEXT(GL_LOGIC_OP);
+    if (!use11ops)
+       glBlendEquationEXT(GL_LOGIC_OP);
+    else
+       glEnable(GL_COLOR_LOGIC_OP);
     glLogicOp(GL_XOR);
 
     /* Draw a set of rectangles across the window */
@@ -138,6 +158,7 @@ int main(int argc, char **argv)
     GLenum type;
     char *s;
     char *extName = "GL_EXT_blend_logic_op";
+    char *version;
 
     glutInit(&argc, argv);
 
@@ -157,10 +178,21 @@ int main(int argc, char **argv)
 
     /* Make sure blend_logic_op extension is there. */
     s = (char *) glGetString(GL_EXTENSIONS);
+    version = (char*) glGetString(GL_VERSION);
     if (!s)
        exit(1);
-    if (strstr(s,extName) == 0) {
-       printf("Blend_logic_op extension is not present.\n");
+    if (strstr(s,extName)) {
+       supportlogops = 1;
+        use11ops = 0;
+        printf("blend_logic_op extension available.\n");
+    }
+    if (strncmp(version,"1.1",3)>=0) {
+       supportlogops += 2;
+        use11ops = 1;
+       printf("1.1 color logic ops available.\n");
+    }
+    if (supportlogops == 0) {
+       printf("Blend_logic_op extension and GL 1.1 not present.\n");
        exit(1);
     }