Brian Paul | 22f1ca0 | 2000-09-30 18:48:33 +0000 | [diff] [blame^] | 1 | /* $Id: texline.c,v 1.1 2000/09/30 18:48:33 brianp Exp $ */ |
| 2 | |
| 3 | /* |
| 4 | * Test textured lines. |
| 5 | * |
| 6 | * Brian Paul |
| 7 | * September 2000 |
| 8 | */ |
| 9 | |
| 10 | |
| 11 | #include <stdio.h> |
| 12 | #include <stdlib.h> |
| 13 | #include <math.h> |
| 14 | #include <GL/glut.h> |
| 15 | #include "../util/readtex.c" /* I know, this is a hack. */ |
| 16 | |
| 17 | #define TEXTURE_FILE "../images/girl.rgb" |
| 18 | |
| 19 | static GLboolean Antialias = GL_FALSE; |
| 20 | static GLboolean Animate = GL_TRUE; |
| 21 | static GLboolean Texture = GL_TRUE; |
| 22 | static GLfloat LineWidth = 1.0; |
| 23 | |
| 24 | static GLfloat Xrot = -60.0, Yrot = 0.0, Zrot = 0.0; |
| 25 | static GLfloat DYrot = 1.0; |
| 26 | |
| 27 | |
| 28 | static void Idle( void ) |
| 29 | { |
| 30 | if (Animate) { |
| 31 | Zrot += DYrot; |
| 32 | glutPostRedisplay(); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | |
| 37 | static void Display( void ) |
| 38 | { |
| 39 | GLfloat x, t; |
| 40 | |
| 41 | glClear( GL_COLOR_BUFFER_BIT ); |
| 42 | |
| 43 | glPushMatrix(); |
| 44 | glRotatef(Xrot, 1.0, 0.0, 0.0); |
| 45 | glRotatef(Yrot, 0.0, 1.0, 0.0); |
| 46 | glRotatef(Zrot, 0.0, 0.0, 1.0); |
| 47 | |
| 48 | glColor3f(1, 1, 1); |
| 49 | glBegin(GL_LINES); |
| 50 | for (t = 0.0; t <= 1.0; t += 0.0125) { |
| 51 | x = t * 2.0 - 1.0; |
| 52 | glTexCoord2f(t, 0.0); glVertex2f(x, -1.0); |
| 53 | glTexCoord2f(t, 1.0); glVertex2f(x, 1.0); |
| 54 | } |
| 55 | glEnd(); |
| 56 | |
| 57 | glPopMatrix(); |
| 58 | |
| 59 | glutSwapBuffers(); |
| 60 | } |
| 61 | |
| 62 | |
| 63 | static void Reshape( int width, int height ) |
| 64 | { |
| 65 | GLfloat ar = (float) width / height; |
| 66 | glViewport( 0, 0, width, height ); |
| 67 | glMatrixMode( GL_PROJECTION ); |
| 68 | glLoadIdentity(); |
| 69 | glFrustum( -ar, ar, -1.0, 1.0, 10.0, 100.0 ); |
| 70 | glMatrixMode( GL_MODELVIEW ); |
| 71 | glLoadIdentity(); |
| 72 | glTranslatef( 0.0, 0.0, -12.0 ); |
| 73 | } |
| 74 | |
| 75 | |
| 76 | static void Key( unsigned char key, int x, int y ) |
| 77 | { |
| 78 | (void) x; |
| 79 | (void) y; |
| 80 | switch (key) { |
| 81 | case 'a': |
| 82 | Antialias = !Antialias; |
| 83 | if (Antialias) { |
| 84 | glEnable(GL_LINE_SMOOTH); |
| 85 | glEnable(GL_BLEND); |
| 86 | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); |
| 87 | } |
| 88 | else { |
| 89 | glDisable(GL_LINE_SMOOTH); |
| 90 | glDisable(GL_BLEND); |
| 91 | } |
| 92 | break; |
| 93 | case 't': |
| 94 | Texture = !Texture; |
| 95 | if (Texture) |
| 96 | glEnable(GL_TEXTURE_2D); |
| 97 | else |
| 98 | glDisable(GL_TEXTURE_2D); |
| 99 | break; |
| 100 | case 'w': |
| 101 | LineWidth -= 0.25; |
| 102 | if (LineWidth < 0.25) |
| 103 | LineWidth = 0.25; |
| 104 | glLineWidth(LineWidth); |
| 105 | break; |
| 106 | case 'W': |
| 107 | LineWidth += 0.25; |
| 108 | if (LineWidth > 8.0) |
| 109 | LineWidth = 8.0; |
| 110 | glLineWidth(LineWidth); |
| 111 | break; |
| 112 | case ' ': |
| 113 | Animate = !Animate; |
| 114 | if (Animate) |
| 115 | glutIdleFunc(Idle); |
| 116 | else |
| 117 | glutIdleFunc(NULL); |
| 118 | break; |
| 119 | case 27: |
| 120 | exit(0); |
| 121 | break; |
| 122 | } |
| 123 | printf("Width %f\n", LineWidth); |
| 124 | glutPostRedisplay(); |
| 125 | } |
| 126 | |
| 127 | |
| 128 | static void SpecialKey( int key, int x, int y ) |
| 129 | { |
| 130 | float step = 3.0; |
| 131 | (void) x; |
| 132 | (void) y; |
| 133 | |
| 134 | switch (key) { |
| 135 | case GLUT_KEY_UP: |
| 136 | Xrot += step; |
| 137 | break; |
| 138 | case GLUT_KEY_DOWN: |
| 139 | Xrot -= step; |
| 140 | break; |
| 141 | case GLUT_KEY_LEFT: |
| 142 | Yrot += step; |
| 143 | break; |
| 144 | case GLUT_KEY_RIGHT: |
| 145 | Yrot -= step; |
| 146 | break; |
| 147 | } |
| 148 | glutPostRedisplay(); |
| 149 | } |
| 150 | |
| 151 | |
| 152 | static void Init( int argc, char *argv[] ) |
| 153 | { |
| 154 | glEnable(GL_TEXTURE_2D); |
| 155 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); |
| 156 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); |
| 157 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); |
| 158 | glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); |
| 159 | |
| 160 | glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); |
| 161 | |
| 162 | glPixelStorei(GL_UNPACK_ALIGNMENT, 1); |
| 163 | if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) { |
| 164 | printf("Error: couldn't load texture image\n"); |
| 165 | exit(1); |
| 166 | } |
| 167 | |
| 168 | if (argc > 1 && strcmp(argv[1], "-info")==0) { |
| 169 | printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER)); |
| 170 | printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION)); |
| 171 | printf("GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR)); |
| 172 | printf("GL_EXTENSIONS = %s\n", (char *) glGetString(GL_EXTENSIONS)); |
| 173 | } |
| 174 | } |
| 175 | |
| 176 | |
| 177 | int main( int argc, char *argv[] ) |
| 178 | { |
| 179 | glutInit( &argc, argv ); |
| 180 | glutInitWindowSize( 400, 300 ); |
| 181 | |
| 182 | glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE ); |
| 183 | |
| 184 | glutCreateWindow(argv[0] ); |
| 185 | |
| 186 | Init(argc, argv); |
| 187 | |
| 188 | glutReshapeFunc( Reshape ); |
| 189 | glutKeyboardFunc( Key ); |
| 190 | glutSpecialFunc( SpecialKey ); |
| 191 | glutDisplayFunc( Display ); |
| 192 | glutIdleFunc( Idle ); |
| 193 | |
| 194 | glutMainLoop(); |
| 195 | return 0; |
| 196 | } |