vp-array-int.c revision 7ec3b29a
1/* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
2
3#include <assert.h>
4#include <string.h>
5#include <stdio.h>
6#include <stdlib.h>
7#include <math.h>
8#include <GL/glew.h>
9#include "glut_wrap.h"
10
11GLint verts[][4] = {
12   {  1, -1, 0, 1 },
13   {  1,  1, 0, 1 },
14   { -1,  1, 0, 1 },
15   { -1, -1, 0, 1 },
16};
17
18GLubyte color[][4] = {
19   { 0x00, 0x00, 0xff, 0x00 },
20   { 0x00, 0xff, 0x00, 0x00 },
21   { 0xff, 0x00, 0x00, 0x00 },
22   { 0xff, 0xff, 0xff, 0x00 },
23};
24
25GLuint indices[] = { 0, 1, 2, 3 };
26
27static void Init( void )
28{
29   GLint errnum;
30   GLuint prognum;
31
32   static const char *prog1 =
33      "!!ARBvp1.0\n"
34      "MOV  result.color, vertex.color;\n"
35      "MOV  result.position, vertex.position;\n"
36      "END\n";
37
38   glGenProgramsARB(1, &prognum);
39   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
40   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
41		      strlen(prog1), (const GLubyte *) prog1);
42
43   assert(glIsProgramARB(prognum));
44   errnum = glGetError();
45   printf("glGetError = %d\n", errnum);
46   if (errnum != GL_NO_ERROR)
47   {
48      GLint errorpos;
49
50      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
51      printf("errorpos: %d\n", errorpos);
52      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
53   }
54
55
56   glEnableClientState( GL_VERTEX_ARRAY );
57   glEnableClientState( GL_COLOR_ARRAY );
58   glVertexPointer( 3, GL_INT, sizeof(verts[0]), verts );
59   glColorPointer( 4, GL_UNSIGNED_BYTE, 0, color );
60
61}
62
63
64
65static void Display( void )
66{
67   glClearColor(0.3, 0.3, 0.3, 1);
68   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
69
70   glEnable(GL_VERTEX_PROGRAM_NV);
71   glDrawElements( GL_TRIANGLES, 3, GL_UNSIGNED_INT, indices );
72
73   glFlush();
74}
75
76
77static void Reshape( int width, int height )
78{
79   glViewport( 0, 0, width, height );
80   glMatrixMode( GL_PROJECTION );
81   glLoadIdentity();
82   glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
83   glMatrixMode( GL_MODELVIEW );
84   glLoadIdentity();
85   /*glTranslatef( 0.0, 0.0, -15.0 );*/
86}
87
88
89static void Key( unsigned char key, int x, int y )
90{
91   (void) x;
92   (void) y;
93   switch (key) {
94      case 27:
95         exit(0);
96         break;
97   }
98   glutPostRedisplay();
99}
100
101
102
103
104int main( int argc, char *argv[] )
105{
106   glutInit( &argc, argv );
107   glutInitWindowPosition( 0, 0 );
108   glutInitWindowSize( 250, 250 );
109   glutInitDisplayMode( GLUT_RGB | GLUT_SINGLE | GLUT_DEPTH );
110   glutCreateWindow(argv[0]);
111   glewInit();
112   glutReshapeFunc( Reshape );
113   glutKeyboardFunc( Key );
114   glutDisplayFunc( Display );
115   Init();
116   glutMainLoop();
117   return 0;
118}
119