Original Post
Hi there, I am quite new to OpneGL and I am trying example 9-1 (the checkimage) from 'OpenGL Programming Guide (2nd)' but there is something strange after I modified it a little. I found that the square drawn on the screen by GL_QUADS was smaller than the one by GL_LINE_LOOP, even they were drawn with the same size (64 * 64). The result was the one by GL_QUADS was actually 63 * 63, while the one by GL_LINE_LOOP was actually 64 * 64, and I checked the screen shot with GIMP. I searched a lot on Google, but found little help. Could you please give me some clue about what's the matter here? Thanks in advance. My box is with Mobility Radeon 7500, running Mandriva Linux 2009.0 (OpenGL 1.3, Mesa 7.04). I compiled the program with 'g++ gl.cpp -ogl -lGL -lglut'. The complete code is as below: --------------------------------------------------------------------------------------- #include #include #include #include #include /* Create checkerboard texture */ #define checkImageWidth 64 #define checkImageHeight 64 static GLubyte checkImage[checkImageHeight][checkImageWidth][4]; static GLuint texName; void makeCheckImage(void) { int i, j, c; for (i = 0; i < checkImageHeight; i++) { for (j = 0; j < checkImageWidth; j++) { c = ((((i&0x8)==0)^((j&0x8))==0))*255; checkImage[j][0] = (GLubyte) c; checkImage[j][1] = (GLubyte) c; checkImage[j][2] = (GLubyte) c; checkImage[j][3] = (GLubyte) 255; } } } void init(void) { glClearColor (0.5, 0.5, 0.5, 0.0); glShadeModel(GL_FLAT); glEnable(GL_DEPTH_TEST); makeCheckImage(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); glGenTextures(1, &texName); glBindTexture(GL_TEXTURE_2D, texName); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); 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, checkImageWidth, checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, checkImage); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glEnable(GL_TEXTURE_2D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL); glBindTexture(GL_TEXTURE_2D, texName); glBegin(GL_QUADS); glTexCoord2i(0, 0); glVertex2i( 10, 10); glTexCoord2i(0, 1); glVertex2i( 10, 73); glTexCoord2i(1, 1); glVertex2i( 73, 73); glTexCoord2i(1, 0); glVertex2i( 73, 10); glEnd(); glDisable(GL_TEXTURE_2D); glPolygonMode(GL_FRONT, GL_LINE); glBegin(GL_LINE_LOOP); glVertex2i( 90, 90); glVertex2i( 90, 153); glVertex2i( 153, 153); glVertex2i( 153, 90); glEnd(); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, w, 0, h, 1, -1); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void keyboard (unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; default: break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize(250, 250); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc(keyboard); glutMainLoop(); return 0; }