132001f49Smrg/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
232001f49Smrg
332001f49Smrg#include <stdio.h>
432001f49Smrg#include <assert.h>
532001f49Smrg#include <string.h>
632001f49Smrg#include <stdlib.h>
732001f49Smrg#include <math.h>
832001f49Smrg#include <GL/glew.h>
932001f49Smrg#include "glut_wrap.h"
1032001f49Smrg
1132001f49Smrg
1232001f49Smrg
1332001f49SmrgGLenum doubleBuffer;
1432001f49Smrg
1532001f49Smrgstatic void Init(void)
1632001f49Smrg{
177ec3b29aSmrg   GLint errnum;
1832001f49Smrg   GLuint prognum;
1932001f49Smrg
2032001f49Smrg   static const char *prog1 =
2132001f49Smrg      "!!ARBvp1.0\n"
2232001f49Smrg      "PARAM Emission = state.material.emission; \n"
2332001f49Smrg      "PARAM Ambient = state.material.ambient; \n"
2432001f49Smrg      "PARAM Diffuse = state.material.diffuse; \n"
2532001f49Smrg      "PARAM Specular = state.material.specular; \n"
2632001f49Smrg      "DP4  result.position.x, Ambient, vertex.position;\n"
2732001f49Smrg      "DP4  result.position.y, Diffuse, vertex.position;\n"
2832001f49Smrg      "DP4  result.position.z, Specular, vertex.position;\n"
2932001f49Smrg      "DP4  result.position.w, Emission, vertex.position;\n"
3032001f49Smrg      "MOV  result.color, vertex.color;\n"
3132001f49Smrg      "END\n";
3232001f49Smrg
3332001f49Smrg   const float Ambient[4] = { 0.0, 1.0, 0.0, 0.0 };
3432001f49Smrg   const float Diffuse[4] = { 1.0, 0.0, 0.0, 0.0 };
3532001f49Smrg   const float Specular[4] = { 0.0, 0.0, 1.0, 0.0 };
3632001f49Smrg   const float Emission[4] = { 0.0, 0.0, 0.0, 1.0 };
3732001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, Ambient);
3832001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, Diffuse);
3932001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, Specular);
4032001f49Smrg   glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, Emission);
4132001f49Smrg
4232001f49Smrg
4332001f49Smrg   glGenProgramsARB(1, &prognum);
4432001f49Smrg
4532001f49Smrg   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
4632001f49Smrg   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
4732001f49Smrg		      strlen(prog1), (const GLubyte *) prog1);
4832001f49Smrg
4932001f49Smrg   assert(glIsProgramARB(prognum));
507ec3b29aSmrg   errnum = glGetError();
517ec3b29aSmrg   printf("glGetError = %d\n", errnum);
527ec3b29aSmrg   if (errnum != GL_NO_ERROR)
5332001f49Smrg   {
5432001f49Smrg      GLint errorpos;
5532001f49Smrg
5632001f49Smrg      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
5732001f49Smrg      printf("errorpos: %d\n", errorpos);
5832001f49Smrg      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
5932001f49Smrg   }
6032001f49Smrg
6132001f49Smrg   glEnable(GL_VERTEX_PROGRAM_NV);
6232001f49Smrg
6332001f49Smrg}
6432001f49Smrg
6532001f49Smrg
6632001f49Smrgstatic void Reshape(int width, int height)
6732001f49Smrg{
6832001f49Smrg
6932001f49Smrg    glViewport(0, 0, (GLint)width, (GLint)height);
7032001f49Smrg
7132001f49Smrg    glMatrixMode(GL_PROJECTION);
7232001f49Smrg    glLoadIdentity();
7332001f49Smrg/*     glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
7432001f49Smrg    glMatrixMode(GL_MODELVIEW);
7532001f49Smrg}
7632001f49Smrg
7732001f49Smrgstatic void Key(unsigned char key, int x, int y)
7832001f49Smrg{
7932001f49Smrg
8032001f49Smrg    switch (key) {
8132001f49Smrg      case 27:
8232001f49Smrg	exit(1);
8332001f49Smrg      default:
8432001f49Smrg	break;
8532001f49Smrg    }
8632001f49Smrg
8732001f49Smrg    glutPostRedisplay();
8832001f49Smrg}
8932001f49Smrg
9032001f49Smrgstatic void Draw(void)
9132001f49Smrg{
9232001f49Smrg   glClear(GL_COLOR_BUFFER_BIT);
9332001f49Smrg
9432001f49Smrg   glBegin(GL_TRIANGLES);
9532001f49Smrg   glColor3f(0,0,.7);
9632001f49Smrg   glVertex3f( 0.9, -0.9, -0.0);
9732001f49Smrg   glColor3f(.8,0,0);
9832001f49Smrg   glVertex3f( 0.9,  0.9, -0.0);
9932001f49Smrg   glColor3f(0,.9,0);
10032001f49Smrg   glVertex3f(-0.9,  0.0, -0.0);
10132001f49Smrg   glEnd();
10232001f49Smrg
10332001f49Smrg   glFlush();
10432001f49Smrg
10532001f49Smrg   if (doubleBuffer) {
10632001f49Smrg      glutSwapBuffers();
10732001f49Smrg   }
10832001f49Smrg}
10932001f49Smrg
11032001f49Smrgstatic GLenum Args(int argc, char **argv)
11132001f49Smrg{
11232001f49Smrg    GLint i;
11332001f49Smrg
11432001f49Smrg    doubleBuffer = GL_FALSE;
11532001f49Smrg
11632001f49Smrg    for (i = 1; i < argc; i++) {
11732001f49Smrg        if (strcmp(argv[i], "-sb") == 0) {
11832001f49Smrg	    doubleBuffer = GL_FALSE;
11932001f49Smrg	} else if (strcmp(argv[i], "-db") == 0) {
12032001f49Smrg	    doubleBuffer = GL_TRUE;
12132001f49Smrg	} else {
12232001f49Smrg	    fprintf(stderr, "%s (Bad option).\n", argv[i]);
12332001f49Smrg	    return GL_FALSE;
12432001f49Smrg	}
12532001f49Smrg    }
12632001f49Smrg    return GL_TRUE;
12732001f49Smrg}
12832001f49Smrg
12932001f49Smrgint main(int argc, char **argv)
13032001f49Smrg{
13132001f49Smrg    GLenum type;
13232001f49Smrg
13332001f49Smrg    glutInit(&argc, argv);
13432001f49Smrg
13532001f49Smrg    if (Args(argc, argv) == GL_FALSE) {
13632001f49Smrg	exit(1);
13732001f49Smrg    }
13832001f49Smrg
13932001f49Smrg    glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
14032001f49Smrg
14132001f49Smrg    type = GLUT_RGB | GLUT_ALPHA;
14232001f49Smrg    type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
14332001f49Smrg    glutInitDisplayMode(type);
14432001f49Smrg
14532001f49Smrg    if (glutCreateWindow(*argv) == GL_FALSE) {
14632001f49Smrg	exit(1);
14732001f49Smrg    }
14832001f49Smrg
14932001f49Smrg    glewInit();
15032001f49Smrg
15132001f49Smrg    Init();
15232001f49Smrg
15332001f49Smrg    glutReshapeFunc(Reshape);
15432001f49Smrg    glutKeyboardFunc(Key);
15532001f49Smrg    glutDisplayFunc(Draw);
15632001f49Smrg    glutMainLoop();
15732001f49Smrg    return 0;
15832001f49Smrg}
159