5 #define GL_GLEXT_PROTOTYPES
11 static const char *modulate2D
=
13 "MUL result.depth.z, fragment.color.z, {.1}.x; \n"
14 "MOV result.color.xy, fragment.color; \n"
19 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
20 printf("Error: GL_ARB_fragment_program not supported!\n");
23 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
25 /* Setup the fragment program */
26 glGenProgramsARB(1, &modulateProg
);
27 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
28 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
29 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
31 printf("glGetError = 0x%x\n", (int) glGetError());
32 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
33 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
35 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
37 glClearColor(.3, .3, .3, 0);
40 static void Reshape(int width
, int height
)
43 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
45 glMatrixMode(GL_PROJECTION
);
47 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
48 glMatrixMode(GL_MODELVIEW
);
51 static void Key(unsigned char key
, int x
, int y
)
64 static void Draw(void)
66 glClear(GL_COLOR_BUFFER_BIT
|GL_DEPTH_BUFFER_BIT
);
67 glEnable(GL_DEPTH_TEST
);
70 glBegin(GL_TRIANGLES
);
72 glVertex3f( 0.9, -0.9, -30.0);
73 glVertex3f( 0.9, 0.9, -30.0);
74 glVertex3f(-0.9, 0.0, -30.0);
77 glVertex3f(-0.9, -0.9, -40.0);
79 glVertex3f(-0.9, 0.9, -40.0);
81 glVertex3f( 0.9, 0.0, -40.0);
88 int main(int argc
, char **argv
)
90 glutInit(&argc
, argv
);
92 glutInitWindowPosition(0, 0); glutInitWindowSize( 300, 300);
94 glutInitDisplayMode(GLUT_DEPTH
| GLUT_RGB
| GLUT_SINGLE
);
96 if (glutCreateWindow("Depth Test") == GL_FALSE
) {
102 glutReshapeFunc(Reshape
);
103 glutKeyboardFunc(Key
);
104 glutDisplayFunc(Draw
);