blob: 772903e4b232dc61de51ea3af96dd9c207ab8949 [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"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000015 "TEMP R0; \n"
16 "MUL R0, fragment.color, {3.14}.x; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000017 "MOV result.color, {0.0}.x; \n"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000018 "SIN result.color.x, R0.x; \n"
19 "SIN result.color.y, R0.y; \n"
20 "SIN result.color.z, R0.z; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000021 "END"
22 ;
23 GLuint modulateProg;
24
25 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
26 printf("Error: GL_ARB_fragment_program not supported!\n");
27 exit(1);
28 }
29 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
30
31 /* Setup the fragment program */
32 glGenProgramsARB(1, &modulateProg);
33 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
34 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
35 strlen(modulate2D), (const GLubyte *)modulate2D);
36
37 printf("glGetError = 0x%x\n", (int) glGetError());
38 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
39 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
40
41 glEnable(GL_FRAGMENT_PROGRAM_ARB);
42
43 glClearColor(.3, .3, .3, 0);
44}
45
46static void Reshape(int width, int height)
47{
48
49 glViewport(0, 0, (GLint)width, (GLint)height);
50
51 glMatrixMode(GL_PROJECTION);
52 glLoadIdentity();
53 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
54 glMatrixMode(GL_MODELVIEW);
55}
56
57static void Key(unsigned char key, int x, int y)
58{
59
60 switch (key) {
61 case 27:
62 exit(1);
63 default:
64 return;
65 }
66
67 glutPostRedisplay();
68}
69
70static void Draw(void)
71{
72 glClear(GL_COLOR_BUFFER_BIT);
73
74 glBegin(GL_TRIANGLES);
75 glColor3f(0,0,1);
76 glVertex3f( 0.9, -0.9, -30.0);
77 glColor3f(1,0,0);
78 glVertex3f( 0.9, 0.9, -30.0);
79 glColor3f(0,1,0);
80 glVertex3f(-0.9, 0.0, -30.0);
81 glEnd();
82
83 glFlush();
84
Keith Whitwellf28cbb62005-10-21 18:33:53 +000085
Keith Whitwella90909e2005-10-20 21:40:23 +000086}
87
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 Whitwellf28cbb62005-10-21 18:33:53 +000095
Keith Whitwella90909e2005-10-20 21:40:23 +000096
97 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
98
99 type = GLUT_RGB;
Keith Whitwellf28cbb62005-10-21 18:33:53 +0000100 type |= GLUT_SINGLE;
Keith Whitwella90909e2005-10-20 21:40:23 +0000101 glutInitDisplayMode(type);
102
103 if (glutCreateWindow("First Tri") == GL_FALSE) {
104 exit(1);
105 }
106
107 Init();
108
109 glutReshapeFunc(Reshape);
110 glutKeyboardFunc(Key);
111 glutDisplayFunc(Draw);
112 glutMainLoop();
113 return 0;
114}