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.

arbvptest3.c 2.9KB

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