1 /* GL_ARB_fragment_program texture test */
8 #define GL_GLEXT_PROTOTYPES
14 #define TEXTURE_FILE "../images/girl.rgb"
16 static GLfloat Xrot
= 0.0, Yrot
= 0.0, Zrot
= 0.0;
20 static void Display( void )
22 glClear( GL_COLOR_BUFFER_BIT
);
25 glRotatef(Xrot
, 1.0, 0.0, 0.0);
26 glRotatef(Yrot
, 0.0, 1.0, 0.0);
27 glRotatef(Zrot
, 0.0, 0.0, 1.0);
30 glTexCoord2f(-PI
, 0); glVertex2f(-1, -1);
31 glTexCoord2f(PI
, 0); glVertex2f( 1, -1);
32 glTexCoord2f(PI
, 1); glVertex2f( 1, 1);
33 glTexCoord2f(-PI
, 1); glVertex2f(-1, 1);
42 static void Reshape( int width
, int height
)
44 glViewport( 0, 0, width
, height
);
45 glMatrixMode( GL_PROJECTION
);
47 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
48 glMatrixMode( GL_MODELVIEW
);
50 glTranslatef( 0.0, 0.0, -8.0 );
54 static void SpecialKey( int key
, int x
, int y
)
78 static void Key( unsigned char key
, int x
, int y
)
91 static void Init( void )
93 static const char *modulate2D
=
96 "MOV R0, {0,0,0,1};\n"
97 "SCS R0, fragment.texcoord[0].x; \n"
98 "ADD R0, R0, {1.0}.x;\n"
99 "MUL R0, R0, {0.5}.x;\n"
100 "MOV result.color, R0; \n"
106 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
107 printf("Error: GL_ARB_fragment_program not supported!\n");
110 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
112 /* Setup the fragment program */
113 glGenProgramsARB(1, &modulateProg
);
114 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
115 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
116 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
118 printf("glGetError = 0x%x\n", (int) glGetError());
119 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
120 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
121 assert(glIsProgramARB(modulateProg
));
123 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
126 glGenTextures(1, &Texture
);
127 glBindTexture(GL_TEXTURE_2D
, Texture
);
128 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
129 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
130 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
131 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
132 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE
);
135 /* XXX this enable shouldn't really be needed!!! */
136 glEnable(GL_TEXTURE_2D
);
138 glClearColor(.3, .3, .3, 0);
142 int main( int argc
, char *argv
[] )
144 glutInit( &argc
, argv
);
145 glutInitWindowPosition( 0, 0 );
146 glutInitWindowSize( 250, 250 );
147 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
148 glutCreateWindow(argv
[0]);
149 glutReshapeFunc( Reshape
);
150 glutKeyboardFunc( Key
);
151 glutSpecialFunc( SpecialKey
);
152 glutDisplayFunc( Display
);