2 * To demo that specular color gets lost someplace after vertex
3 * program completion and fragment program startup
12 #include "glut_wrap.h"
14 static float Xrot
= 0.0, Yrot
= 0.0, Zrot
= 0.0;
15 static GLboolean Anim
= GL_TRUE
;
18 static void Idle( void )
27 static void Display( void )
29 glClear( GL_COLOR_BUFFER_BIT
| GL_DEPTH_BUFFER_BIT
);
32 glRotatef(Xrot
, 1, 0, 0);
33 glRotatef(Yrot
, 0, 1, 0);
34 glRotatef(Zrot
, 0, 0, 1);
35 glutSolidTorus(0.75, 2.0, 10, 20);
42 static void Reshape( int width
, int height
)
44 glViewport( 0, 0, width
, height
);
45 glMatrixMode( GL_PROJECTION
);
47 glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );
48 glMatrixMode( GL_MODELVIEW
);
50 glTranslatef( 0.0, 0.0, -12.0 );
54 static void Key( unsigned char key
, int x
, int y
)
60 Xrot
= Yrot
= Zrot
= 0;
83 static void SpecialKey( int key
, int x
, int y
)
85 const GLfloat step
= 3.0;
106 static void Init( void )
109 GLuint prognum
, fprognum
;
111 static const char prog
[] =
113 "DP4 result.position.x, state.matrix.mvp.row[0], vertex.position ;\n"
114 "DP4 result.position.y, state.matrix.mvp.row[1], vertex.position ;\n"
115 "DP4 result.position.z, state.matrix.mvp.row[2], vertex.position ;\n"
116 "DP4 result.position.w, state.matrix.mvp.row[3], vertex.position ;\n"
117 "MOV result.color.front.primary, {.5, .5, .5, 1};\n"
118 "MOV result.color.front.secondary, {1, 1, 1, 1};\n"
121 static const char fprog
[] =
123 "MOV result.color, fragment.color.secondary;\n"
126 if (!glutExtensionSupported("GL_ARB_vertex_program")) {
127 printf("Sorry, this program requires GL_ARB_vertex_program");
131 if (!glutExtensionSupported("GL_ARB_fragment_program")) {
132 printf("Sorry, this program requires GL_ARB_fragment_program");
136 glGenProgramsARB(1, &prognum
);
137 glGenProgramsARB(1, &fprognum
);
139 glBindProgramARB(GL_VERTEX_PROGRAM_ARB
, prognum
);
140 glProgramStringARB(GL_VERTEX_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
141 strlen(prog
), (const GLubyte
*) prog
);
143 assert(glIsProgramARB(prognum
));
144 errno
= glGetError();
145 printf("glGetError = %d\n", errno
);
146 if (errno
!= GL_NO_ERROR
)
150 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorpos
);
151 printf("errorpos: %d\n", errorpos
);
152 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
155 glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB
, fprognum
);
156 glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB
, GL_PROGRAM_FORMAT_ASCII_ARB
,
157 strlen(fprog
), (const GLubyte
*) fprog
);
158 errno
= glGetError();
159 printf("glGetError = %d\n", errno
);
160 if (errno
!= GL_NO_ERROR
)
164 glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB
, &errorpos
);
165 printf("errorpos: %d\n", errorpos
);
166 printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB
));
169 glEnable(GL_VERTEX_PROGRAM_ARB
);
170 glEnable(GL_FRAGMENT_PROGRAM_ARB
);
171 glEnable(GL_DEPTH_TEST
);
172 glClearColor(0.3, 0.3, 0.3, 1);
176 int main( int argc
, char *argv
[] )
178 glutInit( &argc
, argv
);
179 glutInitWindowPosition( 0, 0 );
180 glutInitWindowSize( 250, 250 );
181 glutInitDisplayMode( GLUT_RGB
| GLUT_DOUBLE
| GLUT_DEPTH
);
182 glutCreateWindow(argv
[0]);
184 glutReshapeFunc( Reshape
);
185 glutKeyboardFunc( Key
);
186 glutSpecialFunc( SpecialKey
);
187 glutDisplayFunc( Display
);