2 /* Exercise 1D textures
13 static GLuint Window
= 0;
14 static GLuint TexObj
[2];
15 static GLfloat Angle
= 0.0f
;
18 static void draw( void )
20 glClear( GL_COLOR_BUFFER_BIT
);
22 glColor3f( 1.0, 1.0, 1.0 );
24 /* draw first polygon */
26 glTranslatef( -1.0, 0.0, 0.0 );
27 glRotatef( Angle
, 0.0, 0.0, 1.0 );
28 glBindTexture( GL_TEXTURE_1D
, TexObj
[0] );
29 glBegin( GL_POLYGON
);
30 glTexCoord1f( 0.0 ); glVertex2f( -1.0, -1.0 );
31 glTexCoord1f( 1.0 ); glVertex2f( 1.0, -1.0 );
32 glTexCoord1f( 1.0 ); glVertex2f( 1.0, 1.0 );
33 glTexCoord1f( 0.0 ); glVertex2f( -1.0, 1.0 );
42 static void idle( void )
50 /* change view Angle, exit upon ESC */
51 static void key(unsigned char k
, int x
, int y
)
63 /* new window size or exposure */
64 static void reshape( int width
, int height
)
66 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
67 glMatrixMode(GL_PROJECTION
);
69 /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
70 glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
71 glMatrixMode(GL_MODELVIEW
);
73 glTranslatef( 0.0, 0.0, -8.0 );
77 static void init( void )
83 glDisable( GL_DITHER
);
86 glEnable( GL_TEXTURE_1D
);
87 glTexEnvi( GL_TEXTURE_ENV
, GL_TEXTURE_ENV_MODE
, GL_DECAL
);
90 /* generate texture object IDs */
91 glGenTextures( 2, TexObj
);
93 /* setup first texture object */
94 glBindTexture( GL_TEXTURE_1D
, TexObj
[0] );
97 for (i
= 0; i
< 256; i
++) {
100 /* map 0..255 to -PI .. PI */
101 f
= ((i
/ 255.0) - .5) * (3.141592 * 2);
105 /* map -1..1 to 0..255 */
106 tex
[i
][0] = (f
+1.0)/2.0 * 255.0;
111 glTexImage1D( GL_TEXTURE_1D
, 0, 3, 256, 0, GL_RGB
, GL_UNSIGNED_BYTE
, tex
);
112 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
113 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
114 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
115 glTexParameteri( GL_TEXTURE_1D
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
120 int main( int argc
, char *argv
[] )
122 glutInit(&argc
, argv
);
123 glutInitWindowPosition(0, 0);
124 glutInitWindowSize(300, 300);
125 glutInitDisplayMode( GLUT_RGB
| GLUT_DEPTH
| GLUT_DOUBLE
);
127 Window
= glutCreateWindow("Texture Objects");
135 glutReshapeFunc( reshape
);
136 glutKeyboardFunc( key
);
137 /* glutIdleFunc( idle ); */
138 glutDisplayFunc( draw
);