5 #define GL_GLEXT_PROTOTYPES
10 static void Init( void )
12 static const char *modulate2D
=
15 "SUB R0, {0.5}.x, fragment.color; \n"
16 "CMP result.color, R0, fragment.color, {0.0}.x; \n"
21 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
22 printf("Error: GL_ARB_fragment_program not supported!\n");
25 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
27 /* Setup the fragment program */
28 glGenProgramsARB(1, &modulateProg
);
29 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
30 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
31 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
33 printf("glGetError = 0x%x\n", (int) glGetError());
34 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
35 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
37 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
39 glClearColor(.3, .3, .3, 0);
42 static void Reshape(int width
, int height
)
45 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
47 glMatrixMode(GL_PROJECTION
);
49 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
50 glMatrixMode(GL_MODELVIEW
);
53 static void Key(unsigned char key
, int x
, int y
)
66 static void Draw(void)
68 glClear(GL_COLOR_BUFFER_BIT
);
70 glBegin(GL_TRIANGLES
);
72 glVertex3f( 0.9, -0.9, -30.0);
74 glVertex3f( 0.9, 0.9, -30.0);
76 glVertex3f(-0.9, 0.0, -30.0);
86 int main(int argc
, char **argv
)
90 glutInit(&argc
, argv
);
93 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
97 glutInitDisplayMode(type
);
99 if (glutCreateWindow("First Tri") == GL_FALSE
) {
105 glutReshapeFunc(Reshape
);
106 glutKeyboardFunc(Key
);
107 glutDisplayFunc(Draw
);