point-sprite.c revision 32001f49
1/*
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#include <GL/glew.h>
29#include "glut_wrap.h"
30
31
32static void
33Init(void)
34{
35   fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
36   fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
37   fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
38   fflush(stderr);
39
40   if (!glutExtensionSupported("GL_ARB_point_sprite")) {
41      printf("GL_ARB_point_sprite not supported\n");
42      exit(1);
43   }
44
45#define SIZE 16
46   {
47      GLubyte tex2d[SIZE][SIZE][3];
48      GLint s, t;
49
50      for (s = 0; s < SIZE; s++) {
51         for (t = 0; t < SIZE; t++) {
52#if 1
53            tex2d[t][s][0] = (s < SIZE / 2) ? 0 : 255;
54            tex2d[t][s][1] = (t < SIZE / 2) ? 0 : 255;
55            tex2d[t][s][2] = 0;
56#else
57            tex2d[t][s][0] = s * 255 / (SIZE - 1);
58            tex2d[t][s][1] = t * 255 / (SIZE - 1);
59            tex2d[t][s][2] = 0;
60#endif
61         }
62      }
63
64      glTexEnvi(GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE);
65      glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
66      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
67      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
68      glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
69
70      glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
71      glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0,
72                   GL_RGB, GL_UNSIGNED_BYTE, tex2d);
73      glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
74      glEnable(GL_TEXTURE_2D);
75   }
76
77   glEnable(GL_POINT_SPRITE);
78
79   glClearColor(0.0, 0.0, 1.0, 0.0);
80}
81
82
83static void
84Reshape(int width, int height)
85{
86   glViewport(0, 0, (GLint) width, (GLint) height);
87   glMatrixMode(GL_PROJECTION);
88   glLoadIdentity();
89   glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
90   glMatrixMode(GL_MODELVIEW);
91}
92
93
94static void
95Key(unsigned char key, int x, int y)
96{
97   if (key == 27)
98      exit(1);
99
100   glutPostRedisplay();
101}
102
103
104static void
105Draw(void)
106{
107   glClear(GL_COLOR_BUFFER_BIT);
108
109   glPointSize(32.0);
110
111   glBegin(GL_POINTS);
112   glColor3f(1, 1, 1);
113   glVertex3f(0.0, 0.0, -30.0);
114   glEnd();
115
116   glutSwapBuffers();
117}
118
119
120int
121main(int argc, char **argv)
122{
123   glutInit(&argc, argv);
124   glutInitWindowSize(250, 250);
125   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
126   if (glutCreateWindow(*argv) == GL_FALSE) {
127      exit(1);
128   }
129   Init();
130   glutReshapeFunc(Reshape);
131   glutKeyboardFunc(Key);
132   glutDisplayFunc(Draw);
133   glutMainLoop();
134   return 0;
135}
136