~ubuntu-branches/ubuntu/oneiric/mesa-demos/oneiric

« back to all changes in this revision

Viewing changes to src/tests/mipgen.c

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2010-09-27 16:18:27 UTC
  • Revision ID: james.westby@ubuntu.com-20100927161827-1yfgolc1oy9sjhi8
Tags: upstream-8.0.1
ImportĀ upstreamĀ versionĀ 8.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Test GL_TEXTURE_BASE_LEVEL and GL_TEXTURE_MAX_LEVEL
 
2
 * Brian Paul
 
3
 * 10 May 2006
 
4
 */
 
5
 
 
6
 
 
7
/* Copyright (c) Mark J. Kilgard, 1994. */
 
8
 
 
9
/*
 
10
 * (c) Copyright 1993, Silicon Graphics, Inc.
 
11
 * ALL RIGHTS RESERVED
 
12
 * Permission to use, copy, modify, and distribute this software for
 
13
 * any purpose and without fee is hereby granted, provided that the above
 
14
 * copyright notice appear in all copies and that both the copyright notice
 
15
 * and this permission notice appear in supporting documentation, and that
 
16
 * the name of Silicon Graphics, Inc. not be used in advertising
 
17
 * or publicity pertaining to distribution of the software without specific,
 
18
 * written prior permission.
 
19
 *
 
20
 * THE MATERIAL EMBODIED ON THIS SOFTWARE IS PROVIDED TO YOU "AS-IS"
 
21
 * AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE,
 
22
 * INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR
 
23
 * FITNESS FOR A PARTICULAR PURPOSE.  IN NO EVENT SHALL SILICON
 
24
 * GRAPHICS, INC.  BE LIABLE TO YOU OR ANYONE ELSE FOR ANY DIRECT,
 
25
 * SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY
 
26
 * KIND, OR ANY DAMAGES WHATSOEVER, INCLUDING WITHOUT LIMITATION,
 
27
 * LOSS OF PROFIT, LOSS OF USE, SAVINGS OR REVENUE, OR THE CLAIMS OF
 
28
 * THIRD PARTIES, WHETHER OR NOT SILICON GRAPHICS, INC.  HAS BEEN
 
29
 * ADVISED OF THE POSSIBILITY OF SUCH LOSS, HOWEVER CAUSED AND ON
 
30
 * ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE
 
31
 * POSSESSION, USE OR PERFORMANCE OF THIS SOFTWARE.
 
32
 *
 
33
 * US Government Users Restricted Rights
 
34
 * Use, duplication, or disclosure by the Government is subject to
 
35
 * restrictions set forth in FAR 52.227.19(c)(2) or subparagraph
 
36
 * (c)(1)(ii) of the Rights in Technical Data and Computer Software
 
37
 * clause at DFARS 252.227-7013 and/or in similar or successor
 
38
 * clauses in the FAR or the DOD or NASA FAR Supplement.
 
39
 * Unpublished-- rights reserved under the copyright laws of the
 
40
 * United States.  Contractor/manufacturer is Silicon Graphics,
 
41
 * Inc., 2011 N.  Shoreline Blvd., Mountain View, CA 94039-7311.
 
42
 *
 
43
 * OpenGL(TM) is a trademark of Silicon Graphics, Inc.
 
44
 */
 
45
 
 
46
#include <stdlib.h>
 
47
#include <stdio.h>
 
48
#include <GL/glew.h>
 
49
#include <GL/glut.h>
 
50
 
 
51
 
 
52
static GLfloat LodBias = 6.0;   /* make smallest miplevel visible */
 
53
static GLuint texImage;
 
54
 
 
55
#define WIDTH 2
 
56
#define HEIGHT 2
 
57
 
 
58
static void
 
59
InitValues(void)
 
60
{
 
61
   LodBias = 6.0;               /* make smallest miplevel visible */
 
62
}
 
63
 
 
64
 
 
65
static void MakeImage(void)
 
66
{
 
67
   const GLubyte color0[4] = { 0xff, 0x80, 0x20, 0xff };
 
68
   const GLubyte color1[4] = { 0x10, 0x20, 0x40, 0xff };
 
69
 
 
70
   GLubyte img[WIDTH*HEIGHT*3];
 
71
   int i, j;
 
72
   for (i = 0; i < HEIGHT; i++) {
 
73
      for (j = 0; j < WIDTH; j++) {
 
74
         int k = (i * WIDTH + j) * 3;
 
75
         int p = ((i+j)%2);
 
76
         if (p == 0) {
 
77
            img[k + 0] = color0[0];
 
78
            img[k + 1] = color0[1];
 
79
            img[k + 2] = color0[2];
 
80
         }
 
81
         else {
 
82
            img[k + 0] = color1[0];
 
83
            img[k + 1] = color1[1];
 
84
            img[k + 2] = color1[2];
 
85
         }
 
86
      }
 
87
   }
 
88
   
 
89
   glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_TRUE);
 
90
   glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, WIDTH, HEIGHT, 0,
 
91
                GL_RGB, GL_UNSIGNED_BYTE, img);
 
92
   glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP_SGIS, GL_FALSE);
 
93
}
 
94
 
 
95
 
 
96
 
 
97
static void myinit(void)
 
98
{
 
99
   InitValues();
 
100
 
 
101
   glShadeModel(GL_FLAT);
 
102
 
 
103
   glTranslatef(0.0, 0.0, -3.6);
 
104
 
 
105
   glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
 
106
   glGenTextures(1, &texImage);
 
107
   glBindTexture(GL_TEXTURE_2D, texImage);
 
108
   MakeImage();
 
109
 
 
110
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
 
111
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
 
112
   glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
 
113
   glEnable(GL_TEXTURE_2D);
 
114
 
 
115
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
 
116
   glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 1);
 
117
 
 
118
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_LOD, -1);
 
119
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_LOD, 1);
 
120
 
 
121
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
 
122
   glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
 
123
                   GL_NEAREST_MIPMAP_NEAREST);
 
124
}
 
125
 
 
126
 
 
127
 
 
128
static void display(void)
 
129
{
 
130
   GLfloat tcm = 1.0;
 
131
   glBindTexture(GL_TEXTURE_2D, texImage);
 
132
 
 
133
   printf("Bias=%.2g\n", LodBias);
 
134
   fflush(stdout);
 
135
 
 
136
   glTexEnvf(GL_TEXTURE_FILTER_CONTROL_EXT, GL_TEXTURE_LOD_BIAS_EXT, LodBias);
 
137
 
 
138
   glClear(GL_COLOR_BUFFER_BIT);
 
139
   glBegin(GL_QUADS);
 
140
   glTexCoord2f(0.0, 0.0); glVertex3f(-2.0, -1.0, 0.0);
 
141
   glTexCoord2f(0.0, tcm); glVertex3f(-2.0, 1.0, 0.0);
 
142
   glTexCoord2f(tcm * 3000.0, tcm); glVertex3f(3000.0, 1.0, -6000.0);
 
143
   glTexCoord2f(tcm * 3000.0, 0.0); glVertex3f(3000.0, -1.0, -6000.0);
 
144
   glEnd();
 
145
   glFlush();
 
146
}
 
147
 
 
148
static void myReshape(int w, int h)
 
149
{
 
150
   glViewport(0, 0, w, h);
 
151
   glMatrixMode(GL_PROJECTION);
 
152
   glLoadIdentity();
 
153
   gluPerspective(60.0, 1.0*(GLfloat)w/(GLfloat)h, 1.0, 30000.0);
 
154
   glMatrixMode(GL_MODELVIEW);
 
155
   glLoadIdentity();
 
156
}
 
157
 
 
158
static void
 
159
key(unsigned char k, int x, int y)
 
160
{
 
161
  (void) x;
 
162
  (void) y;
 
163
  switch (k) {
 
164
  case 'l':
 
165
     LodBias -= 0.25;
 
166
     break;
 
167
  case 'L':
 
168
     LodBias += 0.25;
 
169
     break;
 
170
  case ' ':
 
171
     InitValues();
 
172
     break;
 
173
  case 27:  /* Escape */
 
174
    exit(0);
 
175
    break;
 
176
  default:
 
177
    return;
 
178
  }
 
179
  glutPostRedisplay();
 
180
}
 
181
 
 
182
 
 
183
static void usage(void)
 
184
{
 
185
   printf("usage:\n");
 
186
   printf("  l/L    decrease/increase GL_TEXTURE_LOD_BIAS\n");
 
187
   printf("  SPACE  reset values\n");
 
188
}
 
189
 
 
190
 
 
191
int main(int argc, char** argv)
 
192
{
 
193
    glutInit(&argc, argv);
 
194
    glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB );
 
195
    glutInitWindowSize (600, 600);
 
196
    glutCreateWindow (argv[0]);
 
197
    glewInit();
 
198
    myinit();
 
199
    glutReshapeFunc (myReshape);
 
200
    glutDisplayFunc(display);
 
201
    glutKeyboardFunc(key);
 
202
    usage();
 
203
    glutMainLoop();
 
204
    return 0;             /* ANSI C requires main to return int. */
 
205
}