Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

arbfpspec.c 4.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /*
  2. * To demo that specular color gets lost someplace after vertex
  3. * program completion and fragment program startup
  4. */
  5. #include <assert.h>
  6. #include <string.h>
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #define GL_GLEXT_PROTOTYPES
  11. #include <GL/glut.h>
  12. static float Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
  13. static GLboolean Anim = GL_TRUE;
  14. static void Idle( void )
  15. {
  16. Xrot += .3;
  17. Yrot += .4;
  18. Zrot += .2;
  19. glutPostRedisplay();
  20. }
  21. static void Display( void )
  22. {
  23. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  24. glPushMatrix();
  25. glRotatef(Xrot, 1, 0, 0);
  26. glRotatef(Yrot, 0, 1, 0);
  27. glRotatef(Zrot, 0, 0, 1);
  28. glutSolidTorus(0.75, 2.0, 10, 20);
  29. glPopMatrix();
  30. glutSwapBuffers();
  31. }
  32. static void Reshape( int width, int height )
  33. {
  34. glViewport( 0, 0, width, height );
  35. glMatrixMode( GL_PROJECTION );
  36. glLoadIdentity();
  37. glFrustum( -2.0, 2.0, -2.0, 2.0, 5.0, 25.0 );
  38. glMatrixMode( GL_MODELVIEW );
  39. glLoadIdentity();
  40. glTranslatef( 0.0, 0.0, -12.0 );
  41. }
  42. static void Key( unsigned char key, int x, int y )
  43. {
  44. (void) x;
  45. (void) y;
  46. switch (key) {
  47. case ' ':
  48. Xrot = Yrot = Zrot = 0;
  49. break;
  50. case 'a':
  51. Anim = !Anim;
  52. if (Anim)
  53. glutIdleFunc(Idle);
  54. else
  55. glutIdleFunc(NULL);
  56. break;
  57. case 'z':
  58. Zrot -= 5.0;
  59. break;
  60. case 'Z':
  61. Zrot += 5.0;
  62. break;
  63. case 27:
  64. exit(0);
  65. break;
  66. }
  67. glutPostRedisplay();
  68. }
  69. static void SpecialKey( int key, int x, int y )
  70. {
  71. const GLfloat step = 3.0;
  72. (void) x;
  73. (void) y;
  74. switch (key) {
  75. case GLUT_KEY_UP:
  76. Xrot -= step;
  77. break;
  78. case GLUT_KEY_DOWN:
  79. Xrot += step;
  80. break;
  81. case GLUT_KEY_LEFT:
  82. Yrot -= step;
  83. break;
  84. case GLUT_KEY_RIGHT:
  85. Yrot += step;
  86. break;
  87. }
  88. glutPostRedisplay();
  89. }
  90. static void Init( void )
  91. {
  92. GLint errno;
  93. GLuint prognum, fprognum;
  94. static const char prog[] =
  95. "!!ARBvp1.0\n"
  96. "DP4 result.position.x, state.matrix.mvp.row[0], vertex.position ;\n"
  97. "DP4 result.position.y, state.matrix.mvp.row[1], vertex.position ;\n"
  98. "DP4 result.position.z, state.matrix.mvp.row[2], vertex.position ;\n"
  99. "DP4 result.position.w, state.matrix.mvp.row[3], vertex.position ;\n"
  100. "MOV result.color.front.primary, {.5, .5, .5, 1};\n"
  101. "MOV result.color.front.secondary, {1, 1, 1, 1};\n"
  102. "END";
  103. static const char fprog[] =
  104. "!!ARBfp1.0\n"
  105. "MOV result.color, fragment.color.secondary;\n"
  106. "END";
  107. if (!glutExtensionSupported("GL_ARB_vertex_program")) {
  108. printf("Sorry, this program requires GL_ARB_vertex_program");
  109. exit(1);
  110. }
  111. if (!glutExtensionSupported("GL_ARB_fragment_program")) {
  112. printf("Sorry, this program requires GL_ARB_fragment_program");
  113. exit(1);
  114. }
  115. glGenProgramsARB(1, &prognum);
  116. glGenProgramsARB(1, &fprognum);
  117. glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
  118. glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  119. strlen(prog), (const GLubyte *) prog);
  120. assert(glIsProgramARB(prognum));
  121. errno = glGetError();
  122. printf("glGetError = %d\n", errno);
  123. if (errno != GL_NO_ERROR)
  124. {
  125. GLint errorpos;
  126. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  127. printf("errorpos: %d\n", errorpos);
  128. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  129. }
  130. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, fprognum);
  131. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  132. strlen(fprog), (const GLubyte *) fprog);
  133. errno = glGetError();
  134. printf("glGetError = %d\n", errno);
  135. if (errno != GL_NO_ERROR)
  136. {
  137. GLint errorpos;
  138. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  139. printf("errorpos: %d\n", errorpos);
  140. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  141. }
  142. glEnable(GL_VERTEX_PROGRAM_ARB);
  143. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  144. glEnable(GL_DEPTH_TEST);
  145. glClearColor(0.3, 0.3, 0.3, 1);
  146. }
  147. int main( int argc, char *argv[] )
  148. {
  149. glutInit( &argc, argv );
  150. glutInitWindowPosition( 0, 0 );
  151. glutInitWindowSize( 250, 250 );
  152. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  153. glutCreateWindow(argv[0]);
  154. glutReshapeFunc( Reshape );
  155. glutKeyboardFunc( Key );
  156. glutSpecialFunc( SpecialKey );
  157. glutDisplayFunc( Display );
  158. if (Anim)
  159. glutIdleFunc(Idle);
  160. Init();
  161. glutMainLoop();
  162. return 0;
  163. }