2 * Copyright (c) 1991, 1992, 1993 Silicon Graphics, Inc.
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.
12 * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF
14 * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15 * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
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
29 #define GL_GLEXT_PROTOTYPES
35 #define TEXTURE_FILE "../images/girl.rgb"
40 static void Init( void )
42 static const char *modulate2D
=
44 "TEX result.color, fragment.color, texture[0], 2D; \n"
50 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
51 printf("Error: GL_ARB_fragment_program not supported!\n");
54 printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER
));
56 /* Setup the fragment program */
57 glGenProgramsARB(1, &modulateProg
);
58 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, modulateProg
);
59 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
60 strlen(modulate2D
), (const GLubyte
*)modulate2D
);
62 printf("glGetError = 0x%x\n", (int) glGetError());
63 printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
64 (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
65 assert(glIsProgramARB(modulateProg
));
67 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
70 glGenTextures(1, &Texture
);
71 glBindTexture(GL_TEXTURE_2D
, Texture
);
72 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
73 glTexParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_LINEAR
);
74 glPixelStorei(GL_UNPACK_ALIGNMENT
, 1);
75 if (!LoadRGBMipmaps(TEXTURE_FILE
, GL_RGB
)) {
76 printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE
);
79 /* XXX this enable shouldn't really be needed!!! */
80 glEnable(GL_TEXTURE_2D
);
82 glClearColor(.3, .3, .3, 0);
85 static void Reshape(int width
, int height
)
88 glViewport(0, 0, (GLint
)width
, (GLint
)height
);
90 glMatrixMode(GL_PROJECTION
);
92 glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
93 glMatrixMode(GL_MODELVIEW
);
96 static void Key(unsigned char key
, int x
, int y
)
109 static void Draw(void)
111 glClear(GL_COLOR_BUFFER_BIT
);
113 glBegin(GL_TRIANGLES
);
115 /* glTexCoord2f(1, 0); */
116 glVertex3f( 0.9, -0.9, -30.0);
118 /* glTexCoord2f(1, 1); */
119 glVertex3f( 0.9, 0.9, -30.0);
121 /* glTexCoord2f(0, .5); */
122 glVertex3f(-0.9, 0.0, -30.0);
132 static GLenum
Args(int argc
, char **argv
)
136 doubleBuffer
= GL_FALSE
;
138 for (i
= 1; i
< argc
; i
++) {
139 if (strcmp(argv
[i
], "-sb") == 0) {
140 doubleBuffer
= GL_FALSE
;
141 } else if (strcmp(argv
[i
], "-db") == 0) {
142 doubleBuffer
= GL_TRUE
;
144 fprintf(stderr
, "%s (Bad option).\n", argv
[i
]);
151 int main(int argc
, char **argv
)
155 glutInit(&argc
, argv
);
157 if (Args(argc
, argv
) == GL_FALSE
) {
161 glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
164 type
|= (doubleBuffer
) ? GLUT_DOUBLE
: GLUT_SINGLE
;
165 glutInitDisplayMode(type
);
167 if (glutCreateWindow("First Tri") == GL_FALSE
) {
173 glutReshapeFunc(Reshape
);
174 glutKeyboardFunc(Key
);
175 glutDisplayFunc(Draw
);