1
2#include <assert.h>
3#include <string.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <math.h>
7#include <GL/glew.h>
8#include "glut_wrap.h"
9
10static float Zrot = 0.0;
11
12
13static void Display( void )
14{
15   glClearColor(0.3, 0.3, 0.3, 1);
16   glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
17
18   glEnable(GL_VERTEX_PROGRAM_ARB);
19
20   glLoadIdentity();
21   glRotatef(Zrot, 0, 0, 1);
22
23   glPushMatrix();
24
25   glVertexAttrib3fARB(3, 1, 0.5, 0.25);
26   glBegin(GL_TRIANGLES);
27#if 1
28   glVertexAttrib3fARB(3, 1.0, 0.0, 0.0);
29   glVertexAttrib2fARB(0, -0.5, -0.5);
30   glVertexAttrib3fARB(3, 0.0, 1.0, 0.0);
31   glVertexAttrib2fARB(0, 0.5, -0.5);
32   glVertexAttrib3fARB(3, 0.0, 0.0, 1.0);
33   glVertexAttrib2fARB(0, 0,  0.5);
34#else
35   glVertex2f( -1, -1);
36   glVertex2f( 1, -1);
37   glVertex2f( 0,  1);
38#endif
39   glEnd();
40
41   glPopMatrix();
42
43   glutSwapBuffers();
44}
45
46
47static void Reshape( int width, int height )
48{
49   glViewport( 0, 0, width, height );
50   glMatrixMode( GL_PROJECTION );
51   glLoadIdentity();
52   /*   glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );*/
53   glOrtho(-2.0, 2.0, -2.0, 2.0, -2.0, 2.0 );
54   glMatrixMode( GL_MODELVIEW );
55   glLoadIdentity();
56   /*glTranslatef( 0.0, 0.0, -15.0 );*/
57}
58
59
60static void Key( unsigned char key, int x, int y )
61{
62   (void) x;
63   (void) y;
64   switch (key) {
65      case 'z':
66         Zrot -= 5.0;
67         break;
68      case 'Z':
69         Zrot += 5.0;
70         break;
71      case 27:
72         exit(0);
73         break;
74   }
75   glutPostRedisplay();
76}
77
78
79static void Init( void )
80{
81   GLint errnum;
82   GLuint prognum;
83
84   static const char *prog1 =
85      "!!ARBvp1.0\n"
86      "MOV  result.color, vertex.attrib[3];\n"
87
88      "DP4  result.position.x, vertex.position, state.matrix.modelview.row[0];\n"
89      "DP4  result.position.y, vertex.position, state.matrix.modelview.row[1];\n"
90      "DP4  result.position.z, vertex.position, state.matrix.modelview.row[2];\n"
91      "DP4  result.position.w, vertex.position, state.matrix.modelview.row[3];\n"
92      "END\n";
93
94   glGenProgramsARB(1, &prognum);
95
96   glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
97   glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
98                        strlen(prog1), (const GLubyte *) prog1);
99
100   assert(glIsProgramARB(prognum));
101   errnum = glGetError();
102   printf("glGetError = %d\n", errnum);
103   if (errnum != GL_NO_ERROR)
104   {
105      GLint errorpos;
106
107      glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
108      printf("errorpos: %d\n", errorpos);
109      printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
110   }
111}
112
113
114int main( int argc, char *argv[] )
115{
116   glutInit( &argc, argv );
117   glutInitWindowPosition( 0, 0 );
118   glutInitWindowSize( 250, 250 );
119   glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
120   glutCreateWindow(argv[0]);
121   glewInit();
122   glutReshapeFunc( Reshape );
123   glutKeyboardFunc( Key );
124   glutDisplayFunc( Display );
125   Init();
126   glutMainLoop();
127   return 0;
128}
129