chmod a-x **/glslnoise.c
[mesa-demos.git] / src / fp / tri-depthwrite2.c
blob5547092ec9be6beb4464915af861497ed96460fa
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #define GL_GLEXT_PROTOTYPES
6 #include <GL/glut.h>
9 static void Init(void)
11 static const char *modulate2D =
12 "!!ARBfp1.0\n"
13 "MUL result.depth.z, fragment.color.z, {.1}.x; \n"
14 "MOV result.color, fragment.color.z; \n"
15 "END"
17 GLuint modulateProg;
19 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
20 printf("Error: GL_ARB_fragment_program not supported!\n");
21 exit(1);
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);
46 glLoadIdentity();
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)
54 switch (key) {
55 case 27:
56 exit(1);
57 default:
58 return;
61 glutPostRedisplay();
64 static void Draw(void)
66 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
67 glEnable(GL_DEPTH_TEST);
70 glBegin(GL_TRIANGLES);
71 glColor4f(.8,0,.5,0);
72 glVertex3f( 0.9, -0.9, -30.0);
73 glVertex3f( 0.9, 0.9, -30.0);
74 glVertex3f(-0.9, 0.0, -30.0);
76 glColor4f(0,.8,.7,0);
77 glVertex3f(-0.9, -0.9, -40.0);
78 glColor4f(0,.8,.7,0);
79 glVertex3f(-0.9, 0.9, -40.0);
80 glColor4f(0,.8,.3,0);
81 glVertex3f( 0.9, 0.0, -40.0);
82 glEnd();
84 glFlush();
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) {
97 exit(1);
100 Init();
102 glutReshapeFunc(Reshape);
103 glutKeyboardFunc(Key);
104 glutDisplayFunc(Draw);
105 glutMainLoop();
106 return 0;