132001f49Smrg/* 232001f49Smrg * Copyright (c) 1993-2003, Silicon Graphics, Inc. 332001f49Smrg * All Rights Reserved 432001f49Smrg * 532001f49Smrg * Permission to use, copy, modify, and distribute this software for any 632001f49Smrg * purpose and without fee is hereby granted, provided that the above 732001f49Smrg * copyright notice appear in all copies and that both the copyright 832001f49Smrg * notice and this permission notice appear in supporting documentation, 932001f49Smrg * and that the name of Silicon Graphics, Inc. not be used in 1032001f49Smrg * advertising or publicity pertaining to distribution of the software 1132001f49Smrg * without specific, written prior permission. 1232001f49Smrg * 1332001f49Smrg * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS" AND 1432001f49Smrg * WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, 1532001f49Smrg * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR 1632001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 1732001f49Smrg * GRAPHICS, INC. BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT, 1832001f49Smrg * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, 1932001f49Smrg * OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION, LOSS OF 2032001f49Smrg * PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF THIRD 2132001f49Smrg * PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC. HAS BEEN ADVISED OF 2232001f49Smrg * THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON ANY THEORY OF 2332001f49Smrg * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE POSSESSION, USE 2432001f49Smrg * OR PERFORMANCE OF THIS SOFTWARE. 2532001f49Smrg * 2632001f49Smrg * US Government Users Restricted Rights 2732001f49Smrg * Use, duplication, or disclosure by the Government is subject to 2832001f49Smrg * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph 2932001f49Smrg * (c)(1)(ii) of the Rights in Technical Data and Computer Software 3032001f49Smrg * clause at DFARS 252.227-7013 and/or in similar or successor clauses 3132001f49Smrg * in the FAR or the DOD or NASA FAR Supplement. Unpublished - rights 3232001f49Smrg * reserved under the copyright laws of the United States. 3332001f49Smrg * 3432001f49Smrg * Contractor/manufacturer is: 3532001f49Smrg * Silicon Graphics, Inc. 3632001f49Smrg * 1500 Crittenden Lane 3732001f49Smrg * Mountain View, CA 94043 3832001f49Smrg * United State of America 3932001f49Smrg * 4032001f49Smrg * OpenGL(R) is a registered trademark of Silicon Graphics, Inc. 4132001f49Smrg */ 4232001f49Smrg 4332001f49Smrg/* multitex.c 4432001f49Smrg */ 4532001f49Smrg#include <GL/glew.h> 4632001f49Smrg#include "glut_wrap.h" 4732001f49Smrg#include <stdlib.h> 4832001f49Smrg#include <stdio.h> 4932001f49Smrg 5032001f49Smrg 5132001f49Smrgstatic GLubyte texels0[32][32][4]; 5232001f49Smrgstatic GLubyte texels1[16][16][4]; 5332001f49Smrg 5432001f49Smrgstatic void makeCheckImages(void) 5532001f49Smrg{ 5632001f49Smrg int i, j; 5732001f49Smrg 5832001f49Smrg for (i = 0; i < 32; i++) { 5932001f49Smrg for (j = 0; j < 32; j++) { 6032001f49Smrg texels0[i][j][0] = (GLubyte) (255 * i / 31); 6132001f49Smrg texels0[i][j][1] = (GLubyte) (255 * j / 31); 6232001f49Smrg texels0[i][j][2] = (GLubyte) (i*j)/255; 6332001f49Smrg texels0[i][j][3] = (GLubyte) 255; 6432001f49Smrg } 6532001f49Smrg } 6632001f49Smrg 6732001f49Smrg for (i = 0; i < 16; i++) { 6832001f49Smrg for (j = 0; j < 16; j++) { 6932001f49Smrg texels1[i][j][0] = (GLubyte) 255; 7032001f49Smrg texels1[i][j][1] = (GLubyte) (255 * i / 15); 7132001f49Smrg texels1[i][j][2] = (GLubyte) (255 * j / 15); 7232001f49Smrg texels1[i][j][3] = (GLubyte) 255; 7332001f49Smrg } 7432001f49Smrg } 7532001f49Smrg} 7632001f49Smrg 7732001f49Smrgstatic void init(void) 7832001f49Smrg{ 7932001f49Smrg GLuint texNames[2]; 8032001f49Smrg 8132001f49Smrg glClearColor (0.0, 0.0, 0.0, 0.0); 8232001f49Smrg glShadeModel(GL_FLAT); 8332001f49Smrg glEnable(GL_DEPTH_TEST); 8432001f49Smrg 8532001f49Smrg makeCheckImages(); 8632001f49Smrg glPixelStorei(GL_UNPACK_ALIGNMENT, 1); 8732001f49Smrg 8832001f49Smrg glGenTextures(2, texNames); 8932001f49Smrg glBindTexture(GL_TEXTURE_2D, texNames[0]); 9032001f49Smrg glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 32, 32, 0, GL_RGBA, 9132001f49Smrg GL_UNSIGNED_BYTE, texels0); 9232001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, 9332001f49Smrg GL_NEAREST); 9432001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, 9532001f49Smrg GL_NEAREST); 9632001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); 9732001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 9832001f49Smrg 9932001f49Smrg glBindTexture(GL_TEXTURE_2D, texNames[1]); 10032001f49Smrg glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, 10132001f49Smrg GL_UNSIGNED_BYTE, texels1); 10232001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 10332001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); 10432001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); 10532001f49Smrg glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); 10632001f49Smrg /* Use the two texture objects to define two texture units 10732001f49Smrg * for use in multitexturing */ 10832001f49Smrg glActiveTextureARB (GL_TEXTURE0_ARB); 10932001f49Smrg glEnable(GL_TEXTURE_2D); 11032001f49Smrg glBindTexture(GL_TEXTURE_2D, texNames[0]); 11132001f49Smrg glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); 11232001f49Smrg glMatrixMode (GL_TEXTURE); 11332001f49Smrg glLoadIdentity(); 11432001f49Smrg glTranslatef(0.5f, 0.5f, 0.0f); 11532001f49Smrg glRotatef(45.0f, 0.0f, 0.0f, 1.0f); 11632001f49Smrg glTranslatef(-0.5f, -0.5f, 0.0f); 11732001f49Smrg glMatrixMode (GL_MODELVIEW); 11832001f49Smrg glActiveTextureARB (GL_TEXTURE1_ARB); 11932001f49Smrg glEnable(GL_TEXTURE_2D); 12032001f49Smrg glBindTexture(GL_TEXTURE_2D, texNames[1]); 12132001f49Smrg glTexEnvi (GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); 12232001f49Smrg} 12332001f49Smrg 12432001f49Smrgstatic void display(void) 12532001f49Smrg{ 12632001f49Smrg glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 12732001f49Smrg glBegin(GL_TRIANGLES); 12832001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 0.0, 0.0); 12932001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0, 0.0); 13032001f49Smrg glVertex2f(0.0, 0.0); 13132001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 0.5, 1.0); 13232001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 0.5, 0.0); 13332001f49Smrg glVertex2f(50.0, 100.0); 13432001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE0_ARB, 1.0, 0.0); 13532001f49Smrg glMultiTexCoord2fARB (GL_TEXTURE1_ARB, 1.0, 1.0); 13632001f49Smrg glVertex2f(100.0, 0.0); 13732001f49Smrg glEnd(); 13832001f49Smrg glFlush(); 13932001f49Smrg} 14032001f49Smrg 14132001f49Smrgstatic void reshape(int w, int h) 14232001f49Smrg{ 14332001f49Smrg glViewport(0, 0, (GLsizei) w, (GLsizei) h); 14432001f49Smrg glMatrixMode(GL_PROJECTION); 14532001f49Smrg glLoadIdentity(); 14632001f49Smrg if (w <= h) 14732001f49Smrg gluOrtho2D(0.0, 100.0, 0.0, 100.0 * (GLdouble)h/(GLdouble)w); 14832001f49Smrg else 14932001f49Smrg gluOrtho2D(0.0, 100.0 * (GLdouble)w/(GLdouble)h, 0.0, 100.0); 15032001f49Smrg glMatrixMode(GL_MODELVIEW); 15132001f49Smrg glLoadIdentity(); 15232001f49Smrg} 15332001f49Smrg 15432001f49Smrgstatic void keyboard(unsigned char key, int x, int y) 15532001f49Smrg{ 15632001f49Smrg switch (key) { 15732001f49Smrg case 27: 15832001f49Smrg exit(0); 15932001f49Smrg break; 16032001f49Smrg } 16132001f49Smrg} 16232001f49Smrg 16332001f49Smrgint main(int argc, char** argv) 16432001f49Smrg{ 16532001f49Smrg glutInit(&argc, argv); 16632001f49Smrg glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); 16732001f49Smrg glutInitWindowSize(250, 250); 16832001f49Smrg glutInitWindowPosition(100, 100); 16932001f49Smrg glutCreateWindow(argv[0]); 17032001f49Smrg glewInit(); 17132001f49Smrg init(); 17232001f49Smrg glutReshapeFunc(reshape); 17332001f49Smrg glutDisplayFunc(display); 17432001f49Smrg glutKeyboardFunc (keyboard); 17532001f49Smrg glutMainLoop(); 17632001f49Smrg return 0; 17732001f49Smrg} 178