2 * A lit, rotating torus via vertex program
11 #include "glut_wrap.h"
13 static float Xrot
= 0.0, Yrot
= 0.0, Zrot
= 0.0;
14 static GLboolean Anim
= GL_TRUE
;
17 static void Idle( void )
26 static void Display( void )
28 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
31 glRotatef(Xrot
, 1, 0, 0);
32 glRotatef(Yrot
, 0, 1, 0);
33 glRotatef(Zrot
, 0, 0, 1);
34 glutSolidTorus(0.75, 2.0, 10, 20);
41 static void Reshape( int width
, int height
)
43 glViewport( 0, 0, width
, height
);
44 glMatrixMode( GL_PROJECTION
);
46 glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );
47 glMatrixMode( GL_MODELVIEW
);
49 glTranslatef( 0.0, 0.0, -12.0 );
53 static void Key( unsigned char key
, int x
, int y
)
59 Xrot
= Yrot
= Zrot
= 0;
82 static void SpecialKey( int key
, int x
, int y
)
84 const GLfloat step
= 3.0;
105 static void Init( void )
107 /* borrowed from an nvidia demo:
108 * c[0..3] = modelview matrix
109 * c[4..7] = inverse modelview matrix
111 * c[35] = diffuse color
113 static const char prog
[] =
115 "#Simple transform and diffuse lighting\n"
117 "DP4 o[HPOS].x, c[0], v[OPOS] ; # object x MVP -> clip\n"
118 "DP4 o[HPOS].y, c[1], v[OPOS] ;\n"
119 "DP4 o[HPOS].z, c[2], v[OPOS] ;\n"
120 "DP4 o[HPOS].w, c[3], v[OPOS] ;\n"
122 "DP3 R1.x, c[4], v[NRML] ; # normal x MV-1T -> lighting normal\n"
123 "DP3 R1.y, c[5], v[NRML] ;\n"
124 "DP3 R1.z, c[6], v[NRML] ;\n"
126 "DP3 R0, c[32], R1 ; # L.N\n"
127 "MUL o[COL0].xyz, R0, c[35] ; # col = L.N * diffuse\n"
128 "MOV o[TEX0], v[TEX0];\n"
131 if (!glutExtensionSupported("GL_NV_vertex_program")) {
132 printf("Sorry, this program requires GL_NV_vertex_program");
136 glLoadProgramNV(GL_VERTEX_PROGRAM_NV
, 1,
137 strlen(prog
), (const GLubyte
*) prog
);
138 assert(glIsProgramNV(1));
139 glBindProgramNV(GL_VERTEX_PROGRAM_NV
, 1);
141 /* Load the program registers */
142 glTrackMatrixNV(GL_VERTEX_PROGRAM_NV
, 0, GL_MODELVIEW_PROJECTION_NV
, GL_IDENTITY_NV
);
143 glTrackMatrixNV(GL_VERTEX_PROGRAM_NV
, 4, GL_MODELVIEW
, GL_INVERSE_TRANSPOSE_NV
);
146 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 32, 2, 2, 4, 1);
147 /* Diffuse material color */
148 glProgramParameter4fNV(GL_VERTEX_PROGRAM_NV
, 35, 0.25, 0, 0.25, 1);
150 glEnable(GL_VERTEX_PROGRAM_NV
);
151 glEnable(GL_DEPTH_TEST
);
152 glClearColor(0.3, 0.3, 0.3, 1);
154 printf("glGetError = %d\n", (int) glGetError());
158 int main( int argc
, char *argv
[] )
160 glutInit( &argc
, argv
);
161 glutInitWindowPosition( 0, 0 );
162 glutInitWindowSize( 250, 250 );
163 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
164 glutCreateWindow(argv
[0]);
166 glutReshapeFunc( Reshape
);
167 glutKeyboardFunc( Key
);
168 glutSpecialFunc( SpecialKey
);
169 glutDisplayFunc( Display
);