Merge branch 'mesa_7_6_branch'
[mesa.git] / progs / fp / point-position.c
1
2 #include <stdio.h>
3 #include <string.h>
4 #include <stdlib.h>
5 #include <GL/glew.h>
6 #include <GL/glut.h>
7
8
9
10 static void Init( void )
11 {
12 static const char *modulate2D =
13 "!!ARBfp1.0\n"
14 "MUL result.color, fragment.position, {.005}.x; \n"
15 "END"
16 ;
17 GLuint modulateProg;
18
19 if (!GLEW_ARB_fragment_program) {
20 printf("Error: GL_ARB_fragment_program not supported!\n");
21 exit(1);
22 }
23 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
24
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);
30
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));
34
35 glEnable(GL_FRAGMENT_PROGRAM_ARB);
36
37 glClearColor(.3, .3, .3, 0);
38 }
39
40 static void Reshape(int width, int height)
41 {
42
43 glViewport(0, 0, (GLint)width, (GLint)height);
44
45 glMatrixMode(GL_PROJECTION);
46 glLoadIdentity();
47 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
48 glMatrixMode(GL_MODELVIEW);
49 }
50
51 static void Key(unsigned char key, int x, int y)
52 {
53
54 switch (key) {
55 case 27:
56 exit(1);
57 default:
58 return;
59 }
60
61 glutPostRedisplay();
62 }
63
64 static void Draw(void)
65 {
66 glClear(GL_COLOR_BUFFER_BIT);
67
68 #if 0
69 glBegin(GL_QUADS);
70 glTexCoord2f(1,0);
71 glVertex3f( 0.9, -0.9, -30.0);
72 glTexCoord2f(1,1);
73 glVertex3f( 0.9, 0.9, -30.0);
74 glTexCoord2f(0,1);
75 glVertex3f(-0.9, 0.9, -30.0);
76 glTexCoord2f(0,0);
77 glVertex3f(-0.9, -0.9, -30.0);
78 glEnd();
79 #else
80 glPointSize(100);
81 glBegin(GL_POINTS);
82 glColor3f(0,0,1);
83 glVertex3f( 0, 0, -30.0);
84 glEnd();
85 #endif
86
87 glFlush();
88
89
90 }
91
92
93 int main(int argc, char **argv)
94 {
95 GLenum type;
96
97 glutInit(&argc, argv);
98
99
100
101 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
102
103 type = GLUT_RGB;
104 type |= GLUT_SINGLE;
105 glutInitDisplayMode(type);
106
107 if (glutCreateWindow("First Tri") == GL_FALSE) {
108 exit(1);
109 }
110
111 glewInit();
112
113 Init();
114
115 glutReshapeFunc(Reshape);
116 glutKeyboardFunc(Key);
117 glutDisplayFunc(Draw);
118 glutMainLoop();
119 return 0;
120 }