#include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init(void) { glDisable(GL_DITHER); glClearColor(0.0, 0.0, 0.0, 1.0); } static void TextureTest() { unsigned char t[] = {127, 63}; GLuint texID; glGenTextures(1, &texID); glBindTexture(GL_TEXTURE_1D, texID); glEnable(GL_TEXTURE_1D); glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER); glTexParameteri(GL_TEXTURE_1D, GL_DEPTH_TEXTURE_MODE, GL_ALPHA);//GL_LUMINANCE glTexImage1D(GL_TEXTURE_1D, 0, GL_DEPTH_COMPONENT, 2, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, (void*)t); glBegin(GL_QUAD_STRIP); glTexCoord2f(0.25, 0.25); glVertex2i(25, 25); glTexCoord2f(0.25, 0.75); glVertex2i(25, 75); glTexCoord2f(0.75, 0.25); glVertex2i(75, 25); glTexCoord2f(0.75, 0.75); glVertex2i(75, 75); glEnd(); glDisable(GL_TEXTURE_1D); } static void test(void) { GLfloat buf[4]; glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0, 1.0, 1.0); TextureTest(); glReadPixels(35, 50, 1, 1, GL_RGBA, GL_FLOAT, buf); printf("draw pixel at (35, 50): %f %f %f %f, the alpha component should be 0.5\n", buf[0], buf[1], buf[2], buf[3]); glReadPixels(65, 50, 1, 1, GL_RGBA, GL_FLOAT, buf); printf("draw pixel at (65, 50): %f %f %f %f, the alpha component should be 0.25\n", buf[0], buf[1], buf[2], buf[3]); } void display(void) { glViewport(0, 0, WINDSIZEX, WINDSIZEY); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, WINDSIZEX, 0, WINDSIZEY); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); test(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); // | GLUT_DEPTH); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }