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;
19 static void Display( void )
21 glClear( GL_COLOR_BUFFER_BIT
);
24 glRotatef(Xrot
, 1.0, 0.0, 0.0);
25 glRotatef(Yrot
, 0.0, 1.0, 0.0);
26 glRotatef(Zrot
, 0.0, 0.0, 1.0);
29 glColor4f(1.0, 1.0, 1.0, 1); glTexCoord2f(0, 0); glVertex2f(-1, -1);
30 glColor4f(0.2, 0.2, 1.0, 1); glTexCoord2f(1, 0); glVertex2f( 1, -1);
31 glColor4f(0.2, 1.0, 0.2, 1); glTexCoord2f(1, 1); glVertex2f( 1, 1);
32 glColor4f(1.0, 0.2, 0.2, 1); glTexCoord2f(0, 1); glVertex2f(-1, 1);
41 static void Reshape( int width
, int height
)
43 glViewport( 0, 0, width
, height
);
44 glMatrixMode( GL_PROJECTION
);
46 glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
47 glMatrixMode( GL_MODELVIEW
);
49 glTranslatef( 0.0, 0.0, -8.0 );
53 static void SpecialKey( int key
, int x
, int y
)
77 static void Key( unsigned char key
, int x
, int y
)
90 static void Init( void )
92 static const char *modulate2D
=
95 "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
96 "MUL result.color, R0, fragment.color; \n"
102 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
103 printf("Error: GL_ARB_fragment_program not supported!\n");
106 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
108 /* Setup the fragment program */
109 glGenProgramsARB(1, &modulateProg
);
110 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
111 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
112 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
114 printf("glGetError = 0x%x\n", (int) glGetError());
115 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
116 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
117 assert(glIsProgramARB(modulateProg
));
119 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
122 glGenTextures(1, &Texture
);
123 glBindTexture(GL_TEXTURE_2D
, Texture
);
124 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
125 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
126 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
127 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
128 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE
);
131 /* XXX this enable shouldn't really be needed!!! */
132 glEnable(GL_TEXTURE_2D
);
134 glClearColor(.3, .3, .3, 0);
138 int main( int argc
, char *argv
[] )
140 glutInit( &argc
, argv
);
141 glutInitWindowPosition( 0, 0 );
142 glutInitWindowSize( 250, 250 );
143 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
144 glutCreateWindow(argv
[0]);
145 glutReshapeFunc( Reshape
);
146 glutKeyboardFunc( Key
);
147 glutSpecialFunc( SpecialKey
);
148 glutDisplayFunc( Display
);