2 * Test glTexSubImage mid-way through a frame.
4 * The same texture is used for both quads but it gets redefined
5 * with glTexSubImage (or glTexImage) after the first quad.
15 static GLuint Window = 0;
16 static GLboolean Anim = GL_FALSE;
17 static GLfloat Angle = 0.0f;
24 static int width=8, height=8;
25 static GLubyte tex1[] = {
26 0, 0, 0, 0, 0, 0, 0, 0,
27 0, 0, 0, 0, 1, 0, 0, 0,
28 0, 0, 0, 1, 1, 0, 0, 0,
29 0, 0, 0, 0, 1, 0, 0, 0,
30 0, 0, 0, 0, 1, 0, 0, 0,
31 0, 0, 0, 0, 1, 0, 0, 0,
32 0, 0, 0, 1, 1, 1, 0, 0,
33 0, 0, 0, 0, 0, 0, 0, 0 };
39 for (i=0;i<height;i++) {
40 for (j=0;j<width;j++) {
42 if (tex1[(height-i-1)*width+j]) {
43 tex[p][0] = 255; tex[p][1] = 0; tex[p][2] = 0;
46 tex[p][0] = 255; tex[p][1] = 255; tex[p][2] = 255;
51 glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0,
52 GL_RGB, GL_UNSIGNED_BYTE, tex );
59 static int width=8, height=8;
61 static GLubyte tex2[] = {
62 0, 0, 0, 0, 0, 0, 0, 0,
63 0, 0, 0, 2, 2, 0, 0, 0,
64 0, 0, 2, 0, 0, 2, 0, 0,
65 0, 0, 0, 0, 0, 2, 0, 0,
66 0, 0, 0, 0, 2, 0, 0, 0,
67 0, 0, 0, 2, 0, 0, 0, 0,
68 0, 0, 2, 2, 2, 2, 0, 0,
69 0, 0, 0, 0, 0, 0, 0, 0 };
75 for (i=0;i<height;i++) {
76 for (j=0;j<width;j++) {
78 if (tex2[(height-i-1)*width+j]) {
79 tex[p][0] = 0; tex[p][1] = 255; tex[p][2] = 0;
82 tex[p][0] = 0; tex[p][1] = 0; tex[p][2] = 255;
87 glTexImage2D( GL_TEXTURE_2D, 0, 3, width, height, 0,
88 GL_RGB, GL_UNSIGNED_BYTE, tex );
90 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
91 GL_RGB, GL_UNSIGNED_BYTE, tex );
97 static void draw( void )
99 glClear( GL_COLOR_BUFFER_BIT );
101 glColor3f( 1.0, 1.0, 1.0 );
103 /* draw first polygon */
105 glTranslatef( -1.0, 0.0, 0.0 );
106 glRotatef( Angle, 0.0, 0.0, 1.0 );
110 glBegin( GL_POLYGON );
111 glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
112 glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
113 glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
114 glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
118 /* draw second polygon */
120 glTranslatef( 1.0, 0.0, 0.0 );
121 glRotatef( Angle-90.0, 0.0, 1.0, 0.0 );
125 glBegin( GL_POLYGON );
126 glTexCoord2f( 0.0, 0.0 ); glVertex2f( -1.0, -1.0 );
127 glTexCoord2f( 1.0, 0.0 ); glVertex2f( 1.0, -1.0 );
128 glTexCoord2f( 1.0, 1.0 ); glVertex2f( 1.0, 1.0 );
129 glTexCoord2f( 0.0, 1.0 ); glVertex2f( -1.0, 1.0 );
138 static void idle( void )
140 static double t0 = -1.;
141 double dt, t = glutGet(GLUT_ELAPSED_TIME) / 1000.0;
152 /* change view Angle, exit upon ESC */
153 static void key(unsigned char k, int x, int y)
161 glutIdleFunc( idle );
163 glutIdleFunc( NULL );
166 glutDestroyWindow(Window);
173 /* new window size or exposure */
174 static void reshape( int width, int height )
176 glViewport(0, 0, (GLint)width, (GLint)height);
177 glMatrixMode(GL_PROJECTION);
179 /* glOrtho( -3.0, 3.0, -3.0, 3.0, -10.0, 10.0 );*/
180 glFrustum( -2.0, 2.0, -2.0, 2.0, 6.0, 20.0 );
181 glMatrixMode(GL_MODELVIEW);
183 glTranslatef( 0.0, 0.0, -8.0 );
187 static void init( void )
189 /* Setup texturing */
190 glEnable( GL_TEXTURE_2D );
191 glTexEnvi( GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL );
194 glBindTexture( GL_TEXTURE_2D, 0 );
195 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
196 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
197 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT );
198 glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT );
203 int main( int argc, char *argv[] )
205 glutInit(&argc, argv);
206 glutInitWindowPosition(0, 0);
207 glutInitWindowSize(300, 300);
208 glutInitDisplayMode( GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE );
210 Window = glutCreateWindow("Texture Objects");
218 glutReshapeFunc( reshape );
219 glutKeyboardFunc( key );
221 glutIdleFunc( idle );
222 glutDisplayFunc( draw );