blob: 6437062900e5bfad764d198caf173f82bb557321 [file] [log] [blame]
Karl Rasche4814d792003-11-23 17:44:02 +00001
2#include <assert.h>
3#include <string.h>
4#include <stdio.h>
5#include <stdlib.h>
6#include <math.h>
7#define GL_GLEXT_PROTOTYPES
8#include <GL/glut.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
Brian Paulfb879762006-04-21 01:02:27 +000018 glEnable(GL_VERTEX_PROGRAM_ARB);
Karl Rasche4814d792003-11-23 17:44:02 +000019
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 errno;
82 GLuint prognum;
83
84 static const char *prog1 =
85 "!!ARBvp1.0\n"
Brian Paulfb879762006-04-21 01:02:27 +000086 "MOV result.color, vertex.attrib[3];\n"
Karl Rasche4814d792003-11-23 17:44:02 +000087
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 errno = glGetError();
102 printf("glGetError = %d\n", errno);
103 if (errno != GL_NO_ERROR)
104 {
105 GLint errorpos;
106
107 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
108 printf("errorpos: %d\n", errorpos);
Alan Hourihane29b2ced2004-01-28 16:28:53 +0000109 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
Karl Rasche4814d792003-11-23 17:44:02 +0000110 }
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 glutReshapeFunc( Reshape );
122 glutKeyboardFunc( Key );
123 glutDisplayFunc( Display );
124 Init();
125 glutMainLoop();
126 return 0;
127}