1 /* GL_ARB_fragment_program texture test */
14 #define TEXTURE_FILE DEMOS_DATA_DIR "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);
30 glColor4f(1.0, 1.0, 1.0, 1); glTexCoord4f(0, 0, 0, Q
); glVertex2f(-1, -1);
31 glColor4f(0.2, 0.2, 1.0, 1); glTexCoord4f(1, 0, 0, Q
); glVertex2f( 1, -1);
32 glColor4f(0.2, 1.0, 0.2, 1); glTexCoord4f(1, 1, 0, Q
); glVertex2f( 1, 1);
33 glColor4f(1.0, 0.2, 0.2, 1); glTexCoord4f(0, 1, 0, Q
); 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 "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
97 "MUL result.color, R0, fragment.color; \n"
103 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
104 printf("Error: GL_ARB_fragment_program not supported!\n");
107 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
109 /* Setup the fragment program */
110 glGenProgramsARB(1, &modulateProg
);
111 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
112 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
113 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
115 printf("glGetError = 0x%x\n", (int) glGetError());
116 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
117 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
118 assert(glIsProgramARB(modulateProg
));
120 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
123 glGenTextures(1, &Texture
);
124 glBindTexture(GL_TEXTURE_2D
, Texture
);
125 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
126 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
127 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
128 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
129 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE
);
132 /* XXX this enable shouldn't really be needed!!! */
133 glEnable(GL_TEXTURE_2D
);
135 glClearColor(.3, .3, .3, 0);
139 int main( int argc
, char *argv
[] )
141 glutInit( &argc
, argv
);
142 glutInitWindowPosition( 0, 0 );
143 glutInitWindowSize( 250, 250 );
144 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
145 glutCreateWindow(argv
[0]);
147 glutReshapeFunc( Reshape
);
148 glutKeyboardFunc( Key
);
149 glutSpecialFunc( SpecialKey
);
150 glutDisplayFunc( Display
);