2 * Test XOR emulation with blending.
13 #define IMAGE_FILE "../images/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 static const GLfloat red
[4] = {1.0, 0.2, 0.2, 1.0};
34 static const GLfloat green
[4] = {0.2, 1.0, 0.2, 1.0};
35 static const GLfloat blue
[4] = {0.2, 0.2, 1.0, 1.0};
39 PrintString(const char *s
)
42 glutBitmapCharacter(GLUT_BITMAP_8_BY_13
, (int) *s
);
51 glClear(GL_COLOR_BUFFER_BIT
);
53 glWindowPos2i((Width
- ImgWidth
) / 2, (Height
- ImgHeight
) / 2);
54 glDrawPixels(ImgWidth
, ImgHeight
, ImgFormat
, GL_UNSIGNED_BYTE
, Image
);
61 glWindowPos2i(100, Height
- 20);
62 PrintString("XOR LogicOp:");
64 glEnable(GL_COLOR_LOGIC_OP
);
65 glRecti(100, 30, 250, Height
- 30);
66 glDisable(GL_COLOR_LOGIC_OP
);
68 glWindowPos2i(Width
/2 + 10, Height
- 20);
69 PrintString("Invert Blending:");
70 glBlendFunc(GL_ONE
, GL_ONE
);
71 glBlendEquation(GL_FUNC_SUBTRACT
);
73 glRecti(Width
/ 2, 30, Width
/ 2 + 150, Height
- 30);
81 Reshape(int width
, int height
)
85 glViewport(0, 0, width
, height
);
86 glMatrixMode(GL_PROJECTION
);
88 glOrtho(0, Width
, 0, Height
, -1, 1);
89 glMatrixMode(GL_MODELVIEW
);
95 Key(unsigned char key
, int x
, int y
)
109 glutDestroyWindow(Win
);
118 SpecialKey(int key
, int x
, int y
)
137 MouseMotion(int x
, int y
)
148 MouseButton(int button
, int state
, int x
, int y
)
150 if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_DOWN
) {
151 ButtonDown
= GL_TRUE
;
152 NewRect
.x0
= NewRect
.x1
= x
;
153 NewRect
.y0
= NewRect
.y1
= y
;
156 else if (button
== GLUT_LEFT_BUTTON
&& state
== GLUT_UP
) {
157 ButtonDown
= GL_FALSE
;
166 * Load image and scale if needed.
168 Image
= LoadRGBImage(IMAGE_FILE
, &ImgWidth
, &ImgHeight
, &ImgFormat
);
170 printf("Couldn't read %s\n", IMAGE_FILE
);
174 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
175 glPixelStorei(GL_PACK_ALIGNMENT
, 1);
180 main(int argc
, char *argv
[])
182 glutInit(&argc
, argv
);
183 glutInitWindowSize(Width
, Height
);
184 glutInitDisplayMode(GLUT_RGB
| GLUT_DOUBLE
);
185 Win
= glutCreateWindow(argv
[0]);
187 glutReshapeFunc(Reshape
);
188 glutKeyboardFunc(Key
);
189 glutSpecialFunc(SpecialKey
);
190 glutMotionFunc(MouseMotion
);
191 glutMouseFunc(MouseButton
);
192 glutDisplayFunc(Draw
);