2 * Test XOR emulation with blending.
10 #include "glut_wrap.h"
13 #define IMAGE_FILE DEMOS_DATA_DIR "arch.rgb"
15 static int ImgWidth
, ImgHeight
;
16 static GLenum ImgFormat
;
17 static GLubyte
*Image
= NULL
;
20 static int Width
= 600, Height
= 600;
27 static struct rect OldRect
, NewRect
;
29 static GLboolean ButtonDown
= GL_FALSE
;
30 static GLboolean LogicOp
= 0*GL_TRUE
;
33 PrintString(const char *s
)
36 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
45 glClear(GL_COLOR_BUFFER_BIT
);
47 glWindowPos2i((Width
- ImgWidth
) / 2, (Height
- ImgHeight
) / 2);
48 glDrawPixels(ImgWidth
, ImgHeight
, ImgFormat
, GL_UNSIGNED_BYTE
, Image
);
55 glWindowPos2i(100, Height
- 20);
56 PrintString("XOR LogicOp:");
58 glEnable(GL_COLOR_LOGIC_OP
);
59 glRecti(100, 30, 250, Height
- 30);
60 glDisable(GL_COLOR_LOGIC_OP
);
62 glWindowPos2i(Width
/2 + 10, Height
- 20);
63 PrintString("Invert Blending:");
64 glBlendFunc(GL_ONE
, GL_ONE
);
65 glBlendEquation(GL_FUNC_SUBTRACT
);
67 glRecti(Width
/ 2, 30, Width
/ 2 + 150, Height
- 30);
75 Reshape(int width
, int height
)
79 glViewport(0, 0, width
, height
);
80 glMatrixMode(GL_PROJECTION
);
82 glOrtho(0, Width
, 0, Height
, -1, 1);
83 glMatrixMode(GL_MODELVIEW
);
89 Key(unsigned char key
, int x
, int y
)
103 glutDestroyWindow(Win
);
112 SpecialKey(int key
, int x
, int y
)
131 MouseMotion(int x
, int y
)
142 MouseButton(int button
, int state
, int x
, int y
)
144 if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_DOWN
) {
145 ButtonDown
= GL_TRUE
;
146 NewRect
.x0
= NewRect
.x1
= x
;
147 NewRect
.y0
= NewRect
.y1
= y
;
150 else if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_UP
) {
151 ButtonDown
= GL_FALSE
;
160 * Load image and scale if needed.
162 Image
= LoadRGBImage(IMAGE_FILE
, &ImgWidth
, &ImgHeight
, &ImgFormat
);
164 printf("Couldn't read %s\n", IMAGE_FILE
);
168 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
169 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
174 main(int argc
, char *argv
[])
176 glutInit(&argc
, argv
);
177 glutInitWindowSize(Width
, Height
);
178 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
179 Win
= glutCreateWindow(argv
[0]);
181 glutReshapeFunc(Reshape
);
182 glutKeyboardFunc(Key
);
183 glutSpecialFunc(SpecialKey
);
184 glutMotionFunc(MouseMotion
);
185 glutMouseFunc(MouseButton
);
186 glutDisplayFunc(Draw
);