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