132001f49Smrg/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
232001f49Smrg
332001f49Smrg#include <assert.h>
432001f49Smrg#include <string.h>
532001f49Smrg#include <stdio.h>
632001f49Smrg#include <stdlib.h>
732001f49Smrg#include <math.h>
832001f49Smrg#include <GL/glew.h>
932001f49Smrg#include "glut_wrap.h"
1032001f49Smrg
1132001f49Smrgstatic float Zrot = 0.0;
1232001f49Smrg
1332001f49Smrg
1432001f49Smrgstatic void Display( void )
1532001f49Smrg{
1632001f49Smrg   glClearColor(0.3, 0.3, 0.3, 1);
1732001f49Smrg   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
1832001f49Smrg
1932001f49Smrg   glEnable(GL_VERTEX_PROGRAM_NV);
2032001f49Smrg
2132001f49Smrg   glLoadIdentity();
2232001f49Smrg   glRotatef(Zrot, 0, 0, 1);
2332001f49Smrg
2432001f49Smrg   glTrackMatrixNV(GL_VERTEX_PROGRAM_NV, 0, GL_MODELVIEW, GL_IDENTITY_NV);
2532001f49Smrg   glPushMatrix();
2632001f49Smrg
2732001f49Smrg   glVertexAttrib3fNV(3, 1, 0.5, 0.25);
2832001f49Smrg   glBegin(GL_TRIANGLES);
2932001f49Smrg#if 1
3032001f49Smrg   glVertexAttrib3fNV(3, 1.0, 0.0, 0.0);
3132001f49Smrg   glVertexAttrib2fNV(0, -0.5, -0.5);
3232001f49Smrg   glVertexAttrib3fNV(3, 0.0, 1.0, 0.0);
3332001f49Smrg   glVertexAttrib2fNV(0, 0.5, -0.5);
3432001f49Smrg   glVertexAttrib3fNV(3, 0.0, 0.0, 1.0);
3532001f49Smrg   glVertexAttrib2fNV(0, 0,  0.5);
3632001f49Smrg#else
3732001f49Smrg   glVertex2f( -1, -1);
3832001f49Smrg   glVertex2f( 1, -1);
3932001f49Smrg   glVertex2f( 0,  1);
4032001f49Smrg#endif
4132001f49Smrg   glEnd();
4232001f49Smrg
4332001f49Smrg   glPopMatrix();
4432001f49Smrg
4532001f49Smrg   glutSwapBuffers();
4632001f49Smrg}
4732001f49Smrg
4832001f49Smrg
4932001f49Smrgstatic void Reshape( int width, int height )
5032001f49Smrg{
5132001f49Smrg   glViewport( 0, 0, width, height );
5232001f49Smrg   glMatrixMode( GL_PROJECTION );
5332001f49Smrg   glLoadIdentity();
5432001f49Smrg   /*   glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );*/
5532001f49Smrg   glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0 );
5632001f49Smrg   glMatrixMode( GL_MODELVIEW );
5732001f49Smrg   glLoadIdentity();
5832001f49Smrg   /*glTranslatef( 0.0, 0.0, -15.0 );*/
5932001f49Smrg}
6032001f49Smrg
6132001f49Smrg
6232001f49Smrgstatic void Key( unsigned char key, int x, int y )
6332001f49Smrg{
6432001f49Smrg   (void) x;
6532001f49Smrg   (void) y;
6632001f49Smrg   switch (key) {
6732001f49Smrg      case 'z':
6832001f49Smrg         Zrot -= 5.0;
6932001f49Smrg         break;
7032001f49Smrg      case 'Z':
7132001f49Smrg         Zrot += 5.0;
7232001f49Smrg         break;
7332001f49Smrg      case 27:
7432001f49Smrg         exit(0);
7532001f49Smrg         break;
7632001f49Smrg   }
7732001f49Smrg   glutPostRedisplay();
7832001f49Smrg}
7932001f49Smrg
8032001f49Smrg
8132001f49Smrgstatic void Init( void )
8232001f49Smrg{
8332001f49Smrg   static const char *prog1 =
8432001f49Smrg      "!!VP1.0\n"
8532001f49Smrg      "MOV  o[COL0], v[COL0];\n"
8632001f49Smrg#if 0
8732001f49Smrg      "MOV   o[HPOS], v[OPOS];\n"
8832001f49Smrg#else
8932001f49Smrg      "DP4  o[HPOS].x, v[OPOS], c[0];\n"
9032001f49Smrg      "DP4  o[HPOS].y, v[OPOS], c[1];\n"
9132001f49Smrg      "DP4  o[HPOS].z, v[OPOS], c[2];\n"
9232001f49Smrg      "DP4  o[HPOS].w, v[OPOS], c[3];\n"
9332001f49Smrg#endif
9432001f49Smrg      "END\n";
9532001f49Smrg
9632001f49Smrg   if (!glutExtensionSupported("GL_NV_vertex_program")) {
9732001f49Smrg      printf("Sorry, this program requires GL_NV_vertex_program\n");
9832001f49Smrg      exit(1);
9932001f49Smrg   }
10032001f49Smrg
10132001f49Smrg   glLoadProgramNV(GL_VERTEX_PROGRAM_NV, 1,
10232001f49Smrg                   strlen(prog1),
10332001f49Smrg                   (const GLubyte *) prog1);
10432001f49Smrg   assert(glIsProgramNV(1));
10532001f49Smrg
10632001f49Smrg   glBindProgramNV(GL_VERTEX_PROGRAM_NV, 1);
10732001f49Smrg
10832001f49Smrg   printf("glGetError = %d\n", (int) glGetError());
10932001f49Smrg}
11032001f49Smrg
11132001f49Smrg
11232001f49Smrgint main( int argc, char *argv[] )
11332001f49Smrg{
11432001f49Smrg   glutInit( &argc, argv );
11532001f49Smrg   glutInitWindowPosition( 0, 0 );
11632001f49Smrg   glutInitWindowSize( 250, 250 );
11732001f49Smrg   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
11832001f49Smrg   glutCreateWindow(argv[0]);
11932001f49Smrg   glewInit();
12032001f49Smrg   glutReshapeFunc( Reshape );
12132001f49Smrg   glutKeyboardFunc( Key );
12232001f49Smrg   glutDisplayFunc( Display );
12332001f49Smrg   Init();
12432001f49Smrg   glutMainLoop();
12532001f49Smrg   return 0;
12632001f49Smrg}
127