2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
42 static void Init(void)
45 glClearColor(0.0, 0.0, 0.0, 0.0);
52 static void Reshape(int width
, int height
)
56 windH
= (GLint
)height
;
58 glViewport(0, 0, windW
, windH
);
60 glMatrixMode(GL_PROJECTION
);
62 gluOrtho2D(0, windW
, 0, windH
);
63 glMatrixMode(GL_MODELVIEW
);
66 static void Key(unsigned char key
, int x
, int y
)
88 static void Mouse(int button
, int state
, int mouseX
, int mouseY
)
90 if (state
!= GLUT_DOWN
)
98 static void Draw(void)
101 glClear(GL_COLOR_BUFFER_BIT
);
103 point
[0] = (windW
/ 2) - (image
->sizeX
/ 2);
104 point
[1] = (windH
/ 2) - (image
->sizeY
/ 2);
106 glRasterPos3fv(point
);
108 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
109 glPixelZoom(1.0, 1.0);
110 glDrawPixels(image
->sizeX
, image
->sizeY
, GL_RGB
, GL_UNSIGNED_BYTE
,
114 point
[1] = windH
- (float)y
;
116 glRasterPos3fv(point
);
118 glPixelZoom(zoom
, zoom
);
119 glCopyPixels((windW
/2)-(image
->sizeX
/2),
120 (windH
/2)-(image
->sizeY
/2),
121 image
->sizeX
, image
->sizeY
, GL_COLOR
);
130 static GLenum
Args(int argc
, char **argv
)
134 doubleBuffer
= GL_FALSE
;
136 for (i
= 1; i
< argc
; i
++) {
137 if (strcmp(argv
[i
], "-sb") == 0) {
138 doubleBuffer
= GL_FALSE
;
139 } else if (strcmp(argv
[i
], "-db") == 0) {
140 doubleBuffer
= GL_TRUE
;
141 } else if (strcmp(argv
[i
], "-f") == 0) {
142 if (i
+1 >= argc
|| argv
[i
+1][0] == '-') {
143 printf("-f (No file name).\n");
146 fileName
= argv
[++i
];
149 printf("%s (Bad option).\n", argv
[i
]);
156 int main(int argc
, char **argv
)
160 glutInit(&argc
, argv
);
162 if (Args(argc
, argv
) == GL_FALSE
) {
167 printf("No image file.\n");
171 image
= LoadPPM(fileName
);
175 glutInitWindowPosition(0, 0); glutInitWindowSize( windW
, windH
);
178 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
179 glutInitDisplayMode(type
);
181 if (glutCreateWindow("Copy Test") == GL_FALSE
) {
187 glutReshapeFunc(Reshape
);
188 glutKeyboardFunc(Key
);
189 glutMouseFunc(Mouse
);
190 glutDisplayFunc(Draw
);