132001f49Smrg 232001f49Smrg/* Copyright (c) Mark J. Kilgard, 1994. */ 332001f49Smrg 432001f49Smrg/* 532001f49Smrg * (c) Copyright 1993, Silicon Graphics, Inc. 632001f49Smrg * ALL RIGHTS RESERVED 732001f49Smrg * Permission to use, copy, modify, and distribute this software for 832001f49Smrg * any purpose and without fee is hereby granted, provided that the above 932001f49Smrg * copyright notice appear in all copies and that both the copyright notice 1032001f49Smrg * and this permission notice appear in supporting documentation, and that 1132001f49Smrg * the name of Silicon Graphics, Inc. not be used in advertising 1232001f49Smrg * or publicity pertaining to distribution of the software without specific, 1332001f49Smrg * written prior permission. 1432001f49Smrg * 1532001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" 1632001f49Smrg * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1732001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1832001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1932001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 2032001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY 2132001f49Smrg * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, 2232001f49Smrg * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF 2332001f49Smrg * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN 2432001f49Smrg * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON 2532001f49Smrg * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE 2632001f49Smrg * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE. 2732001f49Smrg * 2832001f49Smrg * US Government Users Restricted Rights 2932001f49Smrg * Use, duplication, or disclosure by the Government is subject to 3032001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 3132001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3232001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor 3332001f49Smrg * clauses in the FAR or the DOD or NASA FAR Supplement. 3432001f49Smrg * Unpublished-- rights reserved under the copyright laws of the 3532001f49Smrg * United States. Contractor/manufacturer is Silicon Graphics, 3632001f49Smrg * Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311. 3732001f49Smrg * 3832001f49Smrg * OpenGL(TM) is a trademark of Silicon Graphics, Inc. 3932001f49Smrg */ 4032001f49Smrg/* mipmap.c 4132001f49Smrg * This program demonstrates using mipmaps for texture maps. 4232001f49Smrg * To overtly show the effect of mipmaps, each mipmap reduction 4332001f49Smrg * level has a solidly colored, contrasting texture image. 4432001f49Smrg * Thus, the quadrilateral which is drawn is drawn with several 4532001f49Smrg * different colors. 4632001f49Smrg */ 4732001f49Smrg#include <stdlib.h> 4832001f49Smrg#include "glut_wrap.h" 4932001f49Smrg 5032001f49SmrgGLubyte mipmapImage32[32][32][3]; 5132001f49SmrgGLubyte mipmapImage16[16][16][3]; 5232001f49SmrgGLubyte mipmapImage8[8][8][3]; 5332001f49SmrgGLubyte mipmapImage4[4][4][3]; 5432001f49SmrgGLubyte mipmapImage2[2][2][3]; 5532001f49SmrgGLubyte mipmapImage1[1][1][3]; 5632001f49Smrg 5732001f49Smrgstatic void makeImages(void) 5832001f49Smrg{ 5932001f49Smrg int i, j; 6032001f49Smrg 6132001f49Smrg for (i = 0; i < 32; i++) { 6232001f49Smrg for (j = 0; j < 32; j++) { 6332001f49Smrg mipmapImage32[i][j][0] = 255; 6432001f49Smrg mipmapImage32[i][j][1] = 255; 6532001f49Smrg mipmapImage32[i][j][2] = 0; 6632001f49Smrg } 6732001f49Smrg } 6832001f49Smrg for (i = 0; i < 16; i++) { 6932001f49Smrg for (j = 0; j < 16; j++) { 7032001f49Smrg mipmapImage16[i][j][0] = 255; 7132001f49Smrg mipmapImage16[i][j][1] = 0; 7232001f49Smrg mipmapImage16[i][j][2] = 255; 7332001f49Smrg } 7432001f49Smrg } 7532001f49Smrg for (i = 0; i < 8; i++) { 7632001f49Smrg for (j = 0; j < 8; j++) { 7732001f49Smrg mipmapImage8[i][j][0] = 255; 7832001f49Smrg mipmapImage8[i][j][1] = 0; 7932001f49Smrg mipmapImage8[i][j][2] = 0; 8032001f49Smrg } 8132001f49Smrg } 8232001f49Smrg for (i = 0; i < 4; i++) { 8332001f49Smrg for (j = 0; j < 4; j++) { 8432001f49Smrg mipmapImage4[i][j][0] = 0; 8532001f49Smrg mipmapImage4[i][j][1] = 255; 8632001f49Smrg mipmapImage4[i][j][2] = 0; 8732001f49Smrg } 8832001f49Smrg } 8932001f49Smrg for (i = 0; i < 2; i++) { 9032001f49Smrg for (j = 0; j < 2; j++) { 9132001f49Smrg mipmapImage2[i][j][0] = 0; 9232001f49Smrg mipmapImage2[i][j][1] = 0; 9332001f49Smrg mipmapImage2[i][j][2] = 255; 9432001f49Smrg } 9532001f49Smrg } 9632001f49Smrg mipmapImage1[0][0][0] = 255; 9732001f49Smrg mipmapImage1[0][0][1] = 255; 9832001f49Smrg mipmapImage1[0][0][2] = 255; 9932001f49Smrg} 10032001f49Smrg 10132001f49Smrgstatic void myinit(void) 10232001f49Smrg{ 10332001f49Smrg glEnable(GL_DEPTH_TEST); 10432001f49Smrg glDepthFunc(GL_LESS); 10532001f49Smrg glShadeModel(GL_FLAT); 10632001f49Smrg 10732001f49Smrg glTranslatef(0.0, 0.0, -3.6); 10832001f49Smrg makeImages(); 10932001f49Smrg glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 11032001f49Smrg glTexImage2D(GL_TEXTURE_2D, 0, 3, 32, 32, 0, 11132001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage32[0][0][0]); 11232001f49Smrg glTexImage2D(GL_TEXTURE_2D, 1, 3, 16, 16, 0, 11332001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage16[0][0][0]); 11432001f49Smrg glTexImage2D(GL_TEXTURE_2D, 2, 3, 8, 8, 0, 11532001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage8[0][0][0]); 11632001f49Smrg glTexImage2D(GL_TEXTURE_2D, 3, 3, 4, 4, 0, 11732001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage4[0][0][0]); 11832001f49Smrg glTexImage2D(GL_TEXTURE_2D, 4, 3, 2, 2, 0, 11932001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage2[0][0][0]); 12032001f49Smrg glTexImage2D(GL_TEXTURE_2D, 5, 3, 1, 1, 0, 12132001f49Smrg GL_RGB, GL_UNSIGNED_BYTE, &mipmapImage1[0][0][0]); 12232001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 12332001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 12432001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); 12532001f49Smrg glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 12632001f49Smrg GL_NEAREST_MIPMAP_NEAREST); 12732001f49Smrg glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); 12832001f49Smrg glEnable(GL_TEXTURE_2D); 12932001f49Smrg} 13032001f49Smrg 13132001f49Smrgstatic void display(void) 13232001f49Smrg{ 13332001f49Smrg glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 13432001f49Smrg glBegin(GL_QUADS); 13532001f49Smrg glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0); 13632001f49Smrg glTexCoord2f(0.0, 8.0); glVertex3f(-2.0, 1.0, 0.0); 13732001f49Smrg glTexCoord2f(8.0, 8.0); glVertex3f(2000.0, 1.0, -6000.0); 13832001f49Smrg glTexCoord2f(8.0, 0.0); glVertex3f(2000.0, -1.0, -6000.0); 13932001f49Smrg glEnd(); 14032001f49Smrg glFlush(); 14132001f49Smrg} 14232001f49Smrg 14332001f49Smrgstatic void myReshape(int w, int h) 14432001f49Smrg{ 14532001f49Smrg glViewport(0, 0, w, h); 14632001f49Smrg glMatrixMode(GL_PROJECTION); 14732001f49Smrg glLoadIdentity(); 14832001f49Smrg gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0); 14932001f49Smrg glMatrixMode(GL_MODELVIEW); 15032001f49Smrg glLoadIdentity(); 15132001f49Smrg} 15232001f49Smrg 15332001f49Smrgstatic void 15432001f49Smrgkey(unsigned char k, int x, int y) 15532001f49Smrg{ 15632001f49Smrg switch (k) { 15732001f49Smrg case 27: /* Escape */ 15832001f49Smrg exit(0); 15932001f49Smrg break; 16032001f49Smrg default: 16132001f49Smrg return; 16232001f49Smrg } 16332001f49Smrg glutPostRedisplay(); 16432001f49Smrg} 16532001f49Smrg 16632001f49Smrgint main(int argc, char** argv) 16732001f49Smrg{ 16832001f49Smrg glutInit(&argc, argv); 16932001f49Smrg glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 17032001f49Smrg glutInitWindowSize (500, 500); 17132001f49Smrg glutCreateWindow (argv[0]); 17232001f49Smrg myinit(); 17332001f49Smrg glutReshapeFunc (myReshape); 17432001f49Smrg glutDisplayFunc(display); 17532001f49Smrg glutKeyboardFunc(key); 17632001f49Smrg glutMainLoop(); 17732001f49Smrg return 0; /* ANSI C requires main to return int. */ 17832001f49Smrg} 179