1
/* GL_NV_fragment_program texture test */
8
#define GL_GLEXT_PROTOTYPES
11
#include "../util/readtex.c"
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 =
94
"TEX R0, f[TEX0], TEX0, 2D; \n"
95
"MUL o[COLR], R0, f[COL0]; \n"
101
if (!glutExtensionSupported("GL_NV_fragment_program")) {
102
printf("Error: GL_NV_fragment_program not supported!\n");
105
printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
107
/* Setup the fragment program */
108
glGenProgramsNV(1, &modulateProg);
109
glLoadProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg,
111
(const GLubyte *) modulate2D);
112
printf("glGetError = 0x%x\n", (int) glGetError());
113
printf("glError(GL_PROGRAM_ERROR_STRING_NV) = %s\n",
114
(char *) glGetString(GL_PROGRAM_ERROR_STRING_NV));
115
assert(glIsProgramNV(modulateProg));
117
glBindProgramNV(GL_FRAGMENT_PROGRAM_NV, modulateProg);
118
glEnable(GL_FRAGMENT_PROGRAM_NV);
121
glGenTextures(1, &Texture);
122
glBindTexture(GL_TEXTURE_2D, Texture);
123
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
124
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
125
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
126
if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
127
printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
130
/* XXX this enable shouldn't really be needed!!! */
131
glEnable(GL_TEXTURE_2D);
133
glClearColor(.3, .3, .3, 0);
137
int main( int argc, char *argv[] )
139
glutInit( &argc, argv );
140
glutInitWindowPosition( 0, 0 );
141
glutInitWindowSize( 250, 250 );
142
glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
143
glutCreateWindow(argv[0]);
144
glutReshapeFunc( Reshape );
145
glutKeyboardFunc( Key );
146
glutSpecialFunc( SpecialKey );
147
glutDisplayFunc( Display );