blob: 620db8dfa925d4be0360b88e693ecc18a927e05f [file] [log] [blame]
Keith Whitwella90909e2005-10-20 21:40:23 +00001/*
2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
3 *
4 * Permission to use, copy, modify, distribute, and sell this software and
5 * its documentation for any purpose is hereby granted without fee, provided
6 * that (i) the above copyright notices and this permission notice appear in
7 * all copies of the software and related documentation, and (ii) the name of
8 * Silicon Graphics may not be used in any advertising or
9 * publicity relating to the software without the specific, prior written
10 * permission of Silicon Graphics.
11 *
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
13 * ANY KIND,
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16 *
17 * IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR
18 * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20 * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21 * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22 * OF THIS SOFTWARE.
23 */
24
25#include <stdio.h>
26#include <string.h>
27#include <stdlib.h>
28#define GL_GLEXT_PROTOTYPES
29#include <GL/glut.h>
30#include "GL/gl.h"
31
32
33#define CI_OFFSET_1 16
34#define CI_OFFSET_2 32
35
36
37GLenum doubleBuffer;
38
39static void Init( void )
40{
41 static const char *modulate2D =
42 "!!ARBfp1.0\n"
43 "TEMP R0; \n"
44 "MUL R0, fragment.color, {3.14}.x; \n"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000045 "COS result.color.x, R0.x; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000046 "COS result.color.y, R0.y; \n"
Keith Whitwell3a09ea92005-10-21 10:27:37 +000047 "COS result.color.z, R0.z; \n"
Keith Whitwella90909e2005-10-20 21:40:23 +000048 "END"
49 ;
50 GLuint modulateProg;
51
52 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
53 printf("Error: GL_ARB_fragment_program not supported!\n");
54 exit(1);
55 }
56 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
57
58 /* Setup the fragment program */
59 glGenProgramsARB(1, &modulateProg);
60 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
61 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
62 strlen(modulate2D), (const GLubyte *)modulate2D);
63
64 printf("glGetError = 0x%x\n", (int) glGetError());
65 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
66 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
67
68 glEnable(GL_FRAGMENT_PROGRAM_ARB);
69
70 glClearColor(.3, .3, .3, 0);
71}
72
73static void Reshape(int width, int height)
74{
75
76 glViewport(0, 0, (GLint)width, (GLint)height);
77
78 glMatrixMode(GL_PROJECTION);
79 glLoadIdentity();
80 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
81 glMatrixMode(GL_MODELVIEW);
82}
83
84static void Key(unsigned char key, int x, int y)
85{
86
87 switch (key) {
88 case 27:
89 exit(1);
90 default:
91 return;
92 }
93
94 glutPostRedisplay();
95}
96
97static void Draw(void)
98{
99 glClear(GL_COLOR_BUFFER_BIT);
100
101 glBegin(GL_TRIANGLES);
102 glColor3f(0,0,1);
103 glVertex3f( 0.9, -0.9, -30.0);
104 glColor3f(1,0,0);
105 glVertex3f( 0.9, 0.9, -30.0);
106 glColor3f(0,1,0);
107 glVertex3f(-0.9, 0.0, -30.0);
108 glEnd();
109
110 glFlush();
111
112 if (doubleBuffer) {
113 glutSwapBuffers();
114 }
115}
116
117static GLenum Args(int argc, char **argv)
118{
119 GLint i;
120
121 doubleBuffer = GL_FALSE;
122
123 for (i = 1; i < argc; i++) {
124 if (strcmp(argv[i], "-sb") == 0) {
125 doubleBuffer = GL_FALSE;
126 } else if (strcmp(argv[i], "-db") == 0) {
127 doubleBuffer = GL_TRUE;
128 } else {
129 fprintf(stderr, "%s (Bad option).\n", argv[i]);
130 return GL_FALSE;
131 }
132 }
133 return GL_TRUE;
134}
135
136int main(int argc, char **argv)
137{
138 GLenum type;
139
140 glutInit(&argc, argv);
141
142 if (Args(argc, argv) == GL_FALSE) {
143 exit(1);
144 }
145
146 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
147
148 type = GLUT_RGB;
149 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
150 glutInitDisplayMode(type);
151
152 if (glutCreateWindow("First Tri") == GL_FALSE) {
153 exit(1);
154 }
155
156 Init();
157
158 glutReshapeFunc(Reshape);
159 glutKeyboardFunc(Key);
160 glutDisplayFunc(Draw);
161 glutMainLoop();
162 return 0;
163}