blob: 7ea24532189136eae5c5ee883cd46a41f0a24e51 [file] [log] [blame]
Keith Whitwella90909e2005-10-20 21:40:23 +00001
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
Keith Whitwella90909e2005-10-20 21:40:23 +000010
11static void Init( void )
12{
13 static const char *modulate2D =
14 "!!ARBfp1.0\n"
15 "TEMP R0; \n"
16 "MUL R0, fragment.color, {3.14}.x; \n"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000017 "COS result.color.x, R0.x; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000018 "COS result.color.y, R0.y; \n"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000019 "COS result.color.z, R0.z; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000020 "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
45static 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
56static 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
69static void Draw(void)
70{
71 glClear(GL_COLOR_BUFFER_BIT);
72
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();
81
82 glFlush();
83
Keith Whitwellf28cbb62005-10-21 18:33:53 +000084
Keith Whitwella90909e2005-10-20 21:40:23 +000085}
86
Keith Whitwella90909e2005-10-20 21:40:23 +000087
Keith Whitwella90909e2005-10-20 21:40:23 +000088
89int main(int argc, char **argv)
90{
91 GLenum type;
92
93 glutInit(&argc, argv);
94
Keith Whitwella90909e2005-10-20 21:40:23 +000095
96 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
97
98 type = GLUT_RGB;
Keith Whitwellf28cbb62005-10-21 18:33:53 +000099 type |= GLUT_SINGLE;
Keith Whitwella90909e2005-10-20 21:40:23 +0000100 glutInitDisplayMode(type);
101
102 if (glutCreateWindow("First Tri") == GL_FALSE) {
103 exit(1);
104 }
105
106 Init();
107
108 glutReshapeFunc(Reshape);
109 glutKeyboardFunc(Key);
110 glutDisplayFunc(Draw);
111 glutMainLoop();
112 return 0;
113}