Merge branch 'nouveau-import'
[mesa.git] / progs / fp / tri-depth2.c
1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #define GL_GLEXT_PROTOTYPES
6 #include <GL/glut.h>
7 #include "GL/gl.h"
8
9
10
11 static void Init( void )
12 {
13 /* scale of 10.0 gives me a visible result on nv hardware.
14 */
15 static const char *modulate2D =
16 "!!ARBfp1.0\n"
17 "TEMP R0;\n"
18 "MUL R0, fragment.position.z, {10.0}.x;\n"
19 "MOV result.color, R0; \n"
20 "END"
21 ;
22 GLuint modulateProg;
23
24 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
25 printf("Error: GL_ARB_fragment_program not supported!\n");
26 exit(1);
27 }
28 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
29
30 /* Setup the fragment program */
31 glGenProgramsARB(1, &modulateProg);
32 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
33 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
34 strlen(modulate2D), (const GLubyte *)modulate2D);
35
36 printf("glGetError = 0x%x\n", (int) glGetError());
37 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
38 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
39
40 glEnable(GL_FRAGMENT_PROGRAM_ARB);
41
42 glClearColor(.3, .3, .3, 0);
43 }
44
45 static void Reshape(int width, int height)
46 {
47
48 glViewport(0, 0, (GLint)width, (GLint)height);
49
50 glMatrixMode(GL_PROJECTION);
51 glLoadIdentity();
52 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
53 glMatrixMode(GL_MODELVIEW);
54 }
55
56 static void Key(unsigned char key, int x, int y)
57 {
58
59 switch (key) {
60 case 27:
61 exit(1);
62 default:
63 return;
64 }
65
66 glutPostRedisplay();
67 }
68
69 static void Draw(void)
70 {
71 glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
72 glEnable(GL_DEPTH_TEST);
73
74 glBegin(GL_TRIANGLES);
75 glColor3f(0,0,1);
76 glVertex3f( 0.9, -0.9, -30.0);
77 glVertex3f( 0.9, 0.9, -30.0);
78 glVertex3f(-0.9, 0.0, -30.0);
79 glColor3f(0,1,0);
80 glVertex3f(-0.9, -0.9, -40.0);
81 glVertex3f(-0.9, 0.9, -40.0);
82 glVertex3f( 0.9, 0.0, -25.0);
83 glEnd();
84
85 glFlush();
86
87
88 }
89
90
91 int main(int argc, char **argv)
92 {
93 GLenum type;
94
95 glutInit(&argc, argv);
96
97
98
99 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
100
101 type = GLUT_RGB | GLUT_DEPTH;
102 type |= GLUT_SINGLE;
103 glutInitDisplayMode(type);
104
105 if (glutCreateWindow("First Tri") == GL_FALSE) {
106 exit(1);
107 }
108
109 Init();
110
111 glutReshapeFunc(Reshape);
112 glutKeyboardFunc(Key);
113 glutDisplayFunc(Draw);
114 glutMainLoop();
115 return 0;
116 }