#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 void init (void) { glClearColor (0.0, 0.0, 0.0, 1.0); glDisable (GL_DITHER); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(-4.0, 4.0, -4.0, 4.0, 0.0, 1.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glDrawBuffer(GL_FRONT); glReadBuffer(GL_FRONT); } static void test (void) { const GLfloat VertColor[4] = { 0.25, 0.75, 0.5, 0.25 }; const GLfloat Param0[4] = { 0.0, 0.0, 0.0, 0.0 }; const GLfloat Param2[4] = { -1.0, 0.0, 0.25, -0.5 }; GLuint progID; int i; char progString[] = "!!ARBvp1.0\n" "PARAM p0 = program.local[0]; \n" "PARAM p2 = program.local[2]; \n" "MOV result.position, vertex.position; \n" "SLT result.color, p2, p0; \n" "END \n"; glGenProgramsARB(1, &progID); glBindProgramARB(GL_VERTEX_PROGRAM_ARB, progID); glEnable(GL_VERTEX_PROGRAM_ARB); glColor4fv(VertColor); glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 0, Param0); glProgramLocalParameter4fvARB(GL_VERTEX_PROGRAM_ARB, 2, Param2); glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, strlen(progString), (const GLubyte *) progString); GLfloat r = 0.25; glDisable(GL_DEPTH_TEST); glClear(GL_COLOR_BUFFER_BIT); glBegin(GL_POLYGON); glTexCoord2f(0, 0); glVertex2f(-r, -r); glTexCoord2f(1, 0); glVertex2f( r, -r); glTexCoord2f(1, 1); glVertex2f( r, r); glTexCoord2f(0, 1); glVertex2f(-r, r); glEnd(); GLfloat pixel[4]; GLfloat expect[4] = {1, 0, 0, 1}; glReadPixels(WINDSIZEX / 2, WINDSIZEY / 2, 1, 1, GL_RGBA, GL_FLOAT, pixel); for (i=0; i<4; i++) { printf("pixel[%d] = %f, should be %f\n", i, pixel[i], expect[i]); } } void display (void) { glMatrixMode (GL_PROJECTION); glLoadIdentity (); gluOrtho2D (0, WINDSIZEX, 0, WINDSIZEX); test (); } int main (int argc, char **argv) { glutInit (&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB); glutInitWindowSize (WINDSIZEX, WINDSIZEY); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc (display); glutMainLoop (); return 0; }