While I can texture an polygon using a texture object with the traditional approach: glBegin(GL_TRIANGLE_STRIP)....glEnd(), Mesa 3.1b3 gets it wrong when I use a texture object with an equivalent glVertexArray approach as shown in the attached program (press any key but ESC to toggle between modes). -- Scott McMillan mailto:[EMAIL PROTECTED] Cambridge Research Associates http://www.cambridge.com 1430 Spring Hill Road, Ste. 200 Voice: (703) 790-0505 x7235 McLean, VA 22102 Fax: (703) 790-0370
#include <GL/gl.h> #include <GL/glu.h> #include <GL/glut.h> #include <stdlib.h> #include <stdio.h> #define checkImageSize 64 static GLubyte checkImage[checkImageSize][checkImageSize][4]; static GLuint texName; int vertex_arrays_flag = 1; void makeCheckImage(void) { int i,j; GLubyte c; for (i=0; i<checkImageSize; i++) { for (j=0; j<checkImageSize; j++) { c = 255; if ((i&0x8) != (j&0x8)) c = 100; checkImage[i][j][0] = c; checkImage[i][j][1] = c; checkImage[i][j][2] = c; checkImage[i][j][3] = 255; } } } void init(void) { glClearColor(0.0, 0.0, 0.0, 0.0); makeCheckImage(); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); /* Changing wrap modes alters vertex array rendering */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, checkImageSize, checkImageSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); glEnable(GL_TEXTURE_2D); } GLfloat vertices[4][3] = {{-2, 2, -10}, {-2,-2, -10}, { 2, 2, -10}, { 2,-2, -10}}; GLfloat texcoords[4][2] = {{0, 1}, {0, 0}, {1, 1}, {1, 0}}; void display(void) { int i; glClear(GL_COLOR_BUFFER_BIT); if (vertex_arrays_flag == 0) { glBegin(GL_TRIANGLE_STRIP); for (i=0; i<4; i++) { glTexCoord2fv(texcoords[i]); glVertex3fv(vertices[i]); } glEnd(); } else { glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glVertexPointer(3, GL_FLOAT, 0, vertices); glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); glDisableClientState(GL_TEXTURE_COORD_ARRAY); } glutSwapBuffers(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei)w, (GLsizei)h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, (GLfloat)w/(GLfloat)h, 1.0, 100.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: vertex_arrays_flag = 1 - vertex_arrays_flag; fprintf(stderr, "Using vertex arrays: %d\n", vertex_arrays_flag); break; } } int main(int argc, char *argv[]) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize(500,500); glutInitWindowPosition(50,50); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutIdleFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }