chmod a-x **/glslnoise.c
[mesa-demos.git] / src / fp / tri-cos.c
blob7ea24532189136eae5c5ee883cd46a41f0a24e51
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"
11 static void Init( void )
13 static const char *modulate2D =
14 "!!ARBfp1.0\n"
15 "TEMP R0; \n"
16 "MUL R0, fragment.color, {3.14}.x; \n"
17 "COS result.color.x, R0.x; \n"
18 "COS result.color.y, R0.y; \n"
19 "COS result.color.z, R0.z; \n"
20 "END"
22 GLuint modulateProg;
24 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
25 printf("Error: GL_ARB_fragment_program not supported!\n");
26 exit(1);
28 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
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);
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));
40 glEnable(GL_FRAGMENT_PROGRAM_ARB);
42 glClearColor(.3, .3, .3, 0);
45 static void Reshape(int width, int height)
48 glViewport(0, 0, (GLint)width, (GLint)height);
50 glMatrixMode(GL_PROJECTION);
51 glLoadIdentity();
52 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
53 glMatrixMode(GL_MODELVIEW);
56 static void Key(unsigned char key, int x, int y)
59 switch (key) {
60 case 27:
61 exit(1);
62 default:
63 return;
66 glutPostRedisplay();
69 static void Draw(void)
71 glClear(GL_COLOR_BUFFER_BIT);
73 glBegin(GL_TRIANGLES);
74 glColor3f(0,0,1);
75 glVertex3f( 0.9, -0.9, -30.0);
76 glColor3f(1,0,0);
77 glVertex3f( 0.9, 0.9, -30.0);
78 glColor3f(0,1,0);
79 glVertex3f(-0.9, 0.0, -30.0);
80 glEnd();
82 glFlush();
89 int main(int argc, char **argv)
91 GLenum type;
93 glutInit(&argc, argv);
96 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
98 type = GLUT_RGB;
99 type |= GLUT_SINGLE;
100 glutInitDisplayMode(type);
102 if (glutCreateWindow("First Tri") == GL_FALSE) {
103 exit(1);
106 Init();
108 glutReshapeFunc(Reshape);
109 glutKeyboardFunc(Key);
110 glutDisplayFunc(Draw);
111 glutMainLoop();
112 return 0;