#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define SIZEW 4 #define SIZEH 4 static GLfloat pricol[] = {0.4, 0.2, 0.6, 0.8};//{0.3, 0.5, 0.7, 0.9 }; // Draw function used by many test casses static void Draw() { glBegin(GL_QUADS); glVertex2i(0,0); glVertex2i(0,SIZEH); glVertex2i(SIZEW, SIZEH); glVertex2i(SIZEW,0); glEnd(); } void init(void) { glClearColor (1,1,1,1); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable (GL_DITHER); } static void test(void) { GLfloat *buf; char cmd1[1024] = "!!ARBfp1.0\nPARAM const1 = {0.1, 0.4,-0.6, 0.8};\n ATTRIB pricol = fragment.color;\nOUTPUT outcolor = result.color;\n MOV outcolor, {0.2, 0.1, 0.4, 0.7};\nKIL +const1;\nMOV outcolor, const1;\n\nEND\0"; //char cmd1[1024] = "!!ARBfp1.0\nATTRIB color2 = fragment.color.secondary;\nOUTPUT outcolor = result.color;\nABS outcolor,-color2;\n\nEND\0"; GLuint programName; glColor4fv(pricol); glGenProgramsARB(1, &programName); // bind a program to the name glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, programName); /////////////////////////////////////// glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB, (GLint) strlen(cmd1), cmd1); if(glGetError() == GL_INVALID_OPERATION) { printf("\nError loading program: check the error\n%s", glGetString(GL_PROGRAM_ERROR_STRING_ARB)); exit(1); } glEnable(GL_FRAGMENT_PROGRAM_ARB); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); Draw(); /////////////////////////////////////// buf = (GLfloat *)malloc(SIZEW * SIZEH *sizeof(GLfloat) * 4); glReadPixels(0, 0, SIZEW, SIZEH, GL_RGBA, GL_FLOAT, buf); printf("draw pixel at (0, 0): %f %f %f %f\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); glutInitWindowSize(WINDSIZEX, WINDSIZEY); glutInitWindowPosition(100, 100); glutCreateWindow(argv[0]); init(); glutDisplayFunc(display); glutMainLoop(); return 0; }