1/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
2
3#include <stdio.h>
4#include <string.h>
5#include <stdlib.h>
6#include <math.h>
7#include <GL/glew.h>
8#include "glut_wrap.h"
9
10
11#define CI_OFFSET_1 16
12#define CI_OFFSET_2 32
13
14
15GLenum doubleBuffer;
16
17static void Init(void)
18{
19   GLint errnum;
20   GLuint prognum;
21
22   static const char *prog1 =
23      "!!ARBvp1.0\n"
24      "OPTION ARB_position_invariant ;"
25      "MOV  result.color, vertex.color;\n"
26      "END\n";
27
28
29   glGenProgramsARB(1, &prognum);
30
31   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
32   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
33		      strlen(prog1), (const GLubyte *) prog1);
34
35   errnum = glGetError();
36   printf("glGetError = %d\n", errnum);
37   if (errnum != GL_NO_ERROR)
38   {
39      GLint errorpos;
40
41      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
42      printf("errorpos: %d\n", errorpos);
43      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
44   }
45
46   fprintf(stderr, "GL_RENDERER   = %s\n", (char *) glGetString(GL_RENDERER));
47   fprintf(stderr, "GL_VERSION    = %s\n", (char *) glGetString(GL_VERSION));
48   fprintf(stderr, "GL_VENDOR     = %s\n", (char *) glGetString(GL_VENDOR));
49   fflush(stderr);
50
51    glClearColor(0.0, 0.0, 1.0, 0.0);
52}
53
54static void Reshape(int width, int height)
55{
56
57    glViewport(0, 0, (GLint)width, (GLint)height);
58
59    glMatrixMode(GL_PROJECTION);
60    glLoadIdentity();
61/*     glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
62    glMatrixMode(GL_MODELVIEW);
63}
64
65static void Key(unsigned char key, int x, int y)
66{
67
68    switch (key) {
69      case 27:
70	exit(1);
71      default:
72	break;
73    }
74
75    glutPostRedisplay();
76}
77
78static void Draw(void)
79{
80   glClear(GL_COLOR_BUFFER_BIT);
81
82   glEnable(GL_VERTEX_PROGRAM_ARB);
83
84   glBegin(GL_TRIANGLES);
85   glColor3f(0,0,.7);
86   glVertex3f( 0.9, -0.9, -0.0);
87   glColor3f(.8,0,0);
88   glVertex3f( 0.9,  0.9, -0.0);
89   glColor3f(0,.9,0);
90   glVertex3f(-0.9,  0.0, -0.0);
91   glEnd();
92
93   glFlush();
94
95   if (doubleBuffer) {
96      glutSwapBuffers();
97   }
98}
99
100static GLenum Args(int argc, char **argv)
101{
102    GLint i;
103
104    doubleBuffer = GL_FALSE;
105
106    for (i = 1; i < argc; i++) {
107        if (strcmp(argv[i], "-sb") == 0) {
108	    doubleBuffer = GL_FALSE;
109	} else if (strcmp(argv[i], "-db") == 0) {
110	    doubleBuffer = GL_TRUE;
111	} else {
112	    fprintf(stderr, "%s (Bad option).\n", argv[i]);
113	    return GL_FALSE;
114	}
115    }
116    return GL_TRUE;
117}
118
119int main(int argc, char **argv)
120{
121    GLenum type;
122
123    glutInit(&argc, argv);
124
125    if (Args(argc, argv) == GL_FALSE) {
126	exit(1);
127    }
128
129    glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
130
131    type = GLUT_RGB | GLUT_ALPHA;
132    type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
133    glutInitDisplayMode(type);
134
135    if (glutCreateWindow(*argv) == GL_FALSE) {
136	exit(1);
137    }
138
139    glewInit();
140    Init();
141
142    glutReshapeFunc(Reshape);
143    glutKeyboardFunc(Key);
144    glutDisplayFunc(Draw);
145    glutMainLoop();
146	return 0;
147}
148