17 #define IMAGE_FILE "../images/arch.rgb"
19 static int ImgWidth
, ImgHeight
;
20 static GLenum ImgFormat
;
21 static GLubyte
*Image
= NULL
;
23 static int WinWidth
= 800, WinHeight
= 800;
24 static int Xpos
, Ypos
;
25 static int Scissor
= 0;
26 static float Xzoom
, Yzoom
;
27 static GLboolean DrawFront
= GL_FALSE
;
28 static GLboolean Dither
= GL_TRUE
;
29 static GLboolean Invert
= GL_FALSE
;
32 static void Reset( void )
40 static void Display( void )
42 const int dx
= (WinWidth
- ImgWidth
) / 2;
43 const int dy
= (WinHeight
- ImgHeight
) / 2;
46 glDrawBuffer(GL_FRONT
);
47 glReadBuffer(GL_FRONT
);
50 glDrawBuffer(GL_BACK
);
51 glReadBuffer(GL_BACK
);
54 glClear( GL_COLOR_BUFFER_BIT
);
56 /* draw original image */
57 glWindowPos2iARB(dx
, dy
);
58 glDrawPixels(ImgWidth
, ImgHeight
, ImgFormat
, GL_UNSIGNED_BYTE
, Image
);
61 glEnable(GL_SCISSOR_TEST
);
64 glPixelTransferf(GL_RED_SCALE
, -1.0);
65 glPixelTransferf(GL_GREEN_SCALE
, -1.0);
66 glPixelTransferf(GL_BLUE_SCALE
, -1.0);
67 glPixelTransferf(GL_RED_BIAS
, 1.0);
68 glPixelTransferf(GL_GREEN_BIAS
, 1.0);
69 glPixelTransferf(GL_BLUE_BIAS
, 1.0);
73 glPixelZoom(Xzoom
, Yzoom
);
74 glWindowPos2iARB(Xpos
, Ypos
);
75 glCopyPixels(dx
, dy
, ImgWidth
, ImgHeight
, GL_COLOR
);
78 glDisable(GL_SCISSOR_TEST
);
81 glPixelTransferf(GL_RED_SCALE
, 1.0);
82 glPixelTransferf(GL_GREEN_SCALE
, 1.0);
83 glPixelTransferf(GL_BLUE_SCALE
, 1.0);
84 glPixelTransferf(GL_RED_BIAS
, 0.0);
85 glPixelTransferf(GL_GREEN_BIAS
, 0.0);
86 glPixelTransferf(GL_BLUE_BIAS
, 0.0);
96 static void Reshape( int width
, int height
)
101 glViewport( 0, 0, width
, height
);
102 glMatrixMode( GL_PROJECTION
);
104 glOrtho( 0.0, width
, 0.0, height
, 0.0, 2.0 );
105 glMatrixMode( GL_MODELVIEW
);
108 glScissor(width
/4, height
/4, width
/2, height
/2);
112 static void Key( unsigned char key
, int x
, int y
)
125 glDisable(GL_DITHER
);
146 DrawFront
= !DrawFront
;
147 printf("glDrawBuffer(%s)\n", DrawFront
? "GL_FRONT" : "GL_BACK");
157 static void SpecialKey( int key
, int x
, int y
)
159 const int step
= (glutGetModifiers() & GLUT_ACTIVE_SHIFT
) ? 10 : 1;
180 static void Init( GLboolean ciMode
, const char *filename
)
182 printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION
));
183 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
185 Image
= LoadRGBImage( filename
, &ImgWidth
, &ImgHeight
, &ImgFormat
);
187 printf("Couldn't read %s\n", filename
);
192 /* Convert RGB image to grayscale */
193 GLubyte
*indexImage
= (GLubyte
*) malloc( ImgWidth
* ImgHeight
);
195 for (i
=0; i
<ImgWidth
*ImgHeight
; i
++) {
196 int gray
= Image
[i
*3] + Image
[i
*3+1] + Image
[i
*3+2];
197 indexImage
[i
] = gray
/ 3;
201 ImgFormat
= GL_COLOR_INDEX
;
203 for (i
=0;i
<255;i
++) {
205 glutSetColor(i
, g
, g
, g
);
209 printf("Loaded %d by %d image\n", ImgWidth
, ImgHeight
);
211 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
212 glPixelStorei(GL_UNPACK_ROW_LENGTH
, ImgWidth
);
218 static void Usage(void)
221 printf(" SPACE Reset Parameters\n");
222 printf(" Up/Down Move image up/down (SHIFT for large step)\n");
223 printf(" Left/Right Move image left/right (SHIFT for large step)\n");
224 printf(" x Decrease X-axis PixelZoom\n");
225 printf(" X Increase X-axis PixelZoom\n");
226 printf(" y Decrease Y-axis PixelZoom\n");
227 printf(" Y Increase Y-axis PixelZoom\n");
228 printf(" s Toggle GL_SCISSOR_TEST\n");
229 printf(" f Toggle front/back buffer drawing\n");
230 printf(" ESC Exit\n");
234 int main( int argc
, char *argv
[] )
236 GLboolean ciMode
= GL_FALSE
;
237 const char *filename
= IMAGE_FILE
;
240 glutInitWindowSize( WinWidth
, WinHeight
);
241 glutInit( &argc
, argv
);
243 if (argc
> i
&& strcmp(argv
[i
], "-ci")==0) {
252 glutInitDisplayMode( GLUT_INDEX
| GLUT_DOUBLE
);
254 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
);
256 glutCreateWindow(argv
[0]);
259 Init(ciMode
, filename
);
262 glutReshapeFunc( Reshape
);
263 glutKeyboardFunc( Key
);
264 glutSpecialFunc( SpecialKey
);
265 glutDisplayFunc( Display
);