#include #include #include #include #include #define WINDSIZEX 100 #define WINDSIZEY 100 #define SIZEW 4 #define TSIZE 4 // Draw function used by many test casses static void DrawTex () { glBegin (GL_QUADS); glTexCoord3f (0.0, 0.0, 0); glVertex2i (0, 0); glTexCoord3f (1.0, 0.0, 0); glVertex2i (0, 1); glTexCoord3f (1.0, 1.0, 0); glVertex2i (SIZEW, 1); glTexCoord3f (0.0, 1.0, 0); glVertex2i (SIZEW, 0); glEnd (); } void init (void) { glClearColor (1, 1, 1, 1); glClear (GL_COLOR_BUFFER_BIT); glShadeModel (GL_FLAT); glDisable (GL_DITHER); glBlendFunc (GL_ZERO, GL_SRC_ALPHA); } static void test (void) { GLfloat *buf; char cmd1[1024] = "!!ARBfp1.0\nOUTPUT tempout = result.color;\nTEX tempout.rb, fragment.texcoord.yxzw, texture, 1D;\n\nEND\n"; GLuint programName; GLfloat texImage1D[TSIZE]; int i; glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri (GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_CLAMP); //Make texture for (i = 0; i < TSIZE; i++) { texImage1D[i] = 0.6; //random(0.0, 1.0); } glTexImage1D (GL_TEXTURE_1D, 0, GL_RGBA, TSIZE, 0, GL_RGBA, GL_FLOAT, texImage1D); /////////////////////////////// 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); DrawTex (GL_TEXTURE_1D); buf = (GLfloat *) malloc (TSIZE * sizeof (GLfloat) * 3); glReadPixels (0, 0, TSIZE, 1, GL_RGB, GL_FLOAT, buf); printf ("draw pixel at (0, 0): %f %f %f\n", buf[0], buf[1], buf[2]); } 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; }