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)
100 GLint src
[3], dst
[3];
102 glClear(GL_COLOR_BUFFER_BIT
);
104 src
[0] = (int) ((windW
/ 2.0) - (image
->sizeX
/ 2.0));
105 src
[1] = (int) ((windH
/ 2.0) - (image
->sizeY
/ 2.0));
107 glWindowPos3ivARB(src
);
109 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
110 glPixelZoom(1.0, 1.0);
111 glDrawPixels(image
->sizeX
, image
->sizeY
, GL_RGB
, GL_UNSIGNED_BYTE
,
117 glWindowPos3ivARB(dst
);
119 glPixelZoom(zoom
, zoom
);
120 glCopyPixels(src
[0], src
[1],
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
) {
188 glutReshapeFunc(Reshape
);
189 glutKeyboardFunc(Key
);
190 glutMouseFunc(Mouse
);
191 glutDisplayFunc(Draw
);