blob: ec83804a68f7154809aa219fb49f9278e742cdb9 [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"
45 "SIN result.color.x, R0.x; \n"
46 "COS result.color.y, R0.y; \n"
47 "END"
48 ;
49 GLuint modulateProg;
50
51 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
52 printf("Error: GL_ARB_fragment_program not supported!\n");
53 exit(1);
54 }
55 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
56
57 /* Setup the fragment program */
58 glGenProgramsARB(1, &modulateProg);
59 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
60 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
61 strlen(modulate2D), (const GLubyte *)modulate2D);
62
63 printf("glGetError = 0x%x\n", (int) glGetError());
64 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
65 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
66
67 glEnable(GL_FRAGMENT_PROGRAM_ARB);
68
69 glClearColor(.3, .3, .3, 0);
70}
71
72static void Reshape(int width, int height)
73{
74
75 glViewport(0, 0, (GLint)width, (GLint)height);
76
77 glMatrixMode(GL_PROJECTION);
78 glLoadIdentity();
79 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
80 glMatrixMode(GL_MODELVIEW);
81}
82
83static void Key(unsigned char key, int x, int y)
84{
85
86 switch (key) {
87 case 27:
88 exit(1);
89 default:
90 return;
91 }
92
93 glutPostRedisplay();
94}
95
96static void Draw(void)
97{
98 glClear(GL_COLOR_BUFFER_BIT);
99
100 glBegin(GL_TRIANGLES);
101 glColor3f(0,0,1);
102 glVertex3f( 0.9, -0.9, -30.0);
103 glColor3f(1,0,0);
104 glVertex3f( 0.9, 0.9, -30.0);
105 glColor3f(0,1,0);
106 glVertex3f(-0.9, 0.0, -30.0);
107 glEnd();
108
109 glFlush();
110
111 if (doubleBuffer) {
112 glutSwapBuffers();
113 }
114}
115
116static GLenum Args(int argc, char **argv)
117{
118 GLint i;
119
120 doubleBuffer = GL_FALSE;
121
122 for (i = 1; i < argc; i++) {
123 if (strcmp(argv[i], "-sb") == 0) {
124 doubleBuffer = GL_FALSE;
125 } else if (strcmp(argv[i], "-db") == 0) {
126 doubleBuffer = GL_TRUE;
127 } else {
128 fprintf(stderr, "%s (Bad option).\n", argv[i]);
129 return GL_FALSE;
130 }
131 }
132 return GL_TRUE;
133}
134
135int main(int argc, char **argv)
136{
137 GLenum type;
138
139 glutInit(&argc, argv);
140
141 if (Args(argc, argv) == GL_FALSE) {
142 exit(1);
143 }
144
145 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
146
147 type = GLUT_RGB;
148 type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
149 glutInitDisplayMode(type);
150
151 if (glutCreateWindow("First Tri") == GL_FALSE) {
152 exit(1);
153 }
154
155 Init();
156
157 glutReshapeFunc(Reshape);
158 glutKeyboardFunc(Key);
159 glutDisplayFunc(Draw);
160 glutMainLoop();
161 return 0;
162}