132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-1997, Silicon Graphics, Inc. 332001f49Smrg * ALL RIGHTS RESERVED 432001f49Smrg * Permission to use, copy, modify, and distribute this software for 532001f49Smrg * any purpose and without fee is hereby granted, provided that the above 632001f49Smrg * copyright notice appear in all copies and that both the copyright notice 732001f49Smrg * and this permission notice appear in supporting documentation, and that 832001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 932001f49Smrg * or publicity pertaining to distribution of the software without specific, 1032001f49Smrg * written prior permission. 1132001f49Smrg * 1232001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1332001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1432001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1532001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1632001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1732001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 1832001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 1932001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2032001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2132001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2232001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2332001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2432001f49Smrg * 2532001f49Smrg * US Government Users Restricted Rights 2632001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2732001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2832001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 2932001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3032001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3132001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3232001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3332001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3432001f49Smrg * 3532001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 3632001f49Smrg */ 3732001f49Smrg 3832001f49Smrg/* image.c 3932001f49Smrg * This program demonstrates drawing pixels and shows the effect 4032001f49Smrg * of glDrawPixels(), glCopyPixels(), and glPixelZoom(). 4132001f49Smrg * Interaction: moving the mouse while pressing the mouse button 4232001f49Smrg * will copy the image in the lower-left corner of the window 4332001f49Smrg * to the mouse position, using the current pixel zoom factors. 4432001f49Smrg * There is no attempt to prevent you from drawing over the original 4532001f49Smrg * image. If you press the 'r' key, the original image and zoom 4632001f49Smrg * factors are reset. If you press the 'z' or 'Z' keys, you change 4732001f49Smrg * the zoom factors. 4832001f49Smrg */ 4932001f49Smrg#include "glut_wrap.h" 5032001f49Smrg#include <stdlib.h> 5132001f49Smrg#include <stdio.h> 5232001f49Smrg 5332001f49Smrg/* Create checkerboard image */ 5432001f49Smrg#define checkImageWidth 64 5532001f49Smrg#define checkImageHeight 64 5632001f49SmrgGLubyte checkImage[checkImageHeight][checkImageWidth][3]; 5732001f49Smrg 5832001f49Smrgstatic GLdouble zoomFactor = 1.0; 5932001f49Smrgstatic GLint height; 6032001f49Smrg 6132001f49Smrgstatic void makeCheckImage(void) 6232001f49Smrg{ 6332001f49Smrg int i, j, c; 6432001f49Smrg 6532001f49Smrg for (i = 0; i < checkImageHeight; i++) { 6632001f49Smrg for (j = 0; j < checkImageWidth; j++) { 6732001f49Smrg c = (((i&0x8)==0)^((j&0x8)==0))*255; 6832001f49Smrg checkImage[i][j][0] = (GLubyte) c; 6932001f49Smrg checkImage[i][j][1] = (GLubyte) c; 7032001f49Smrg checkImage[i][j][2] = (GLubyte) c; 7132001f49Smrg } 7232001f49Smrg } 7332001f49Smrg} 7432001f49Smrg 7532001f49Smrgstatic void init(void) 7632001f49Smrg{ 7732001f49Smrg glClearColor (0.0, 0.0, 0.0, 0.0); 7832001f49Smrg glShadeModel(GL_FLAT); 7932001f49Smrg makeCheckImage(); 8032001f49Smrg glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 8132001f49Smrg} 8232001f49Smrg 8332001f49Smrgstatic void display(void) 8432001f49Smrg{ 8532001f49Smrg glClear(GL_COLOR_BUFFER_BIT); 8632001f49Smrg glRasterPos2i(0, 0); 8732001f49Smrg glDrawPixels(checkImageWidth, checkImageHeight, GL_RGB, 8832001f49Smrg GL_UNSIGNED_BYTE, checkImage); 8932001f49Smrg glFlush(); 9032001f49Smrg} 9132001f49Smrg 9232001f49Smrgstatic void reshape(int w, int h) 9332001f49Smrg{ 9432001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 9532001f49Smrg height = (GLint) h; 9632001f49Smrg glMatrixMode(GL_PROJECTION); 9732001f49Smrg glLoadIdentity(); 9832001f49Smrg gluOrtho2D(0.0, (GLdouble) w, 0.0, (GLdouble) h); 9932001f49Smrg glMatrixMode(GL_MODELVIEW); 10032001f49Smrg glLoadIdentity(); 10132001f49Smrg} 10232001f49Smrg 10332001f49Smrgstatic void motion(int x, int y) 10432001f49Smrg{ 10532001f49Smrg static GLint screeny; 10632001f49Smrg 10732001f49Smrg screeny = height - (GLint) y; 10832001f49Smrg glRasterPos2i (x, screeny); 10932001f49Smrg glPixelZoom (zoomFactor, zoomFactor); 11032001f49Smrg glCopyPixels (0, 0, checkImageWidth, checkImageHeight, GL_COLOR); 11132001f49Smrg glPixelZoom (1.0, 1.0); 11232001f49Smrg glFlush (); 11332001f49Smrg} 11432001f49Smrg 11532001f49Smrg/* ARGSUSED1 */ 11632001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 11732001f49Smrg{ 11832001f49Smrg switch (key) { 11932001f49Smrg case 'r': 12032001f49Smrg case 'R': 12132001f49Smrg zoomFactor = 1.0; 12232001f49Smrg glutPostRedisplay(); 12332001f49Smrg printf ("zoomFactor reset to 1.0\n"); 12432001f49Smrg break; 12532001f49Smrg case 'z': 12632001f49Smrg zoomFactor += 0.5; 12732001f49Smrg if (zoomFactor >= 3.0) 12832001f49Smrg zoomFactor = 3.0; 12932001f49Smrg printf ("zoomFactor is now %4.1f\n", zoomFactor); 13032001f49Smrg break; 13132001f49Smrg case 'Z': 13232001f49Smrg zoomFactor -= 0.5; 13332001f49Smrg if (zoomFactor <= 0.5) 13432001f49Smrg zoomFactor = 0.5; 13532001f49Smrg printf ("zoomFactor is now %4.1f\n", zoomFactor); 13632001f49Smrg break; 13732001f49Smrg case 27: 13832001f49Smrg exit(0); 13932001f49Smrg break; 14032001f49Smrg default: 14132001f49Smrg break; 14232001f49Smrg } 14332001f49Smrg} 14432001f49Smrg 14532001f49Smrgint main(int argc, char** argv) 14632001f49Smrg{ 14732001f49Smrg glutInit(&argc, argv); 14832001f49Smrg glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); 14932001f49Smrg glutInitWindowSize(250, 250); 15032001f49Smrg glutInitWindowPosition(100, 100); 15132001f49Smrg glutCreateWindow(argv[0]); 15232001f49Smrg init(); 15332001f49Smrg glutDisplayFunc(display); 15432001f49Smrg glutReshapeFunc(reshape); 15532001f49Smrg glutKeyboardFunc(keyboard); 15632001f49Smrg glutMotionFunc(motion); 15732001f49Smrg glutMainLoop(); 15832001f49Smrg return 0; 15932001f49Smrg} 160