Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

vp-tri-invariant.c 2.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <math.h>
  6. #include <GL/glew.h>
  7. #include <GL/glut.h>
  8. #define CI_OFFSET_1 16
  9. #define CI_OFFSET_2 32
  10. GLenum doubleBuffer;
  11. static void Init(void)
  12. {
  13. GLint errno;
  14. GLuint prognum;
  15. static const char *prog1 =
  16. "!!ARBvp1.0\n"
  17. "OPTION ARB_position_invariant ;"
  18. "MOV result.color, vertex.color;\n"
  19. "END\n";
  20. glGenProgramsARB(1, &prognum);
  21. glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
  22. glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  23. strlen(prog1), (const GLubyte *) prog1);
  24. errno = glGetError();
  25. printf("glGetError = %d\n", errno);
  26. if (errno != GL_NO_ERROR)
  27. {
  28. GLint errorpos;
  29. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  30. printf("errorpos: %d\n", errorpos);
  31. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  32. }
  33. fprintf(stderr, "GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  34. fprintf(stderr, "GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  35. fprintf(stderr, "GL_VENDOR = %s\n", (char *) glGetString(GL_VENDOR));
  36. fflush(stderr);
  37. glClearColor(0.0, 0.0, 1.0, 0.0);
  38. }
  39. static void Reshape(int width, int height)
  40. {
  41. glViewport(0, 0, (GLint)width, (GLint)height);
  42. glMatrixMode(GL_PROJECTION);
  43. glLoadIdentity();
  44. /* glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0); */
  45. glMatrixMode(GL_MODELVIEW);
  46. }
  47. static void Key(unsigned char key, int x, int y)
  48. {
  49. switch (key) {
  50. case 27:
  51. exit(1);
  52. default:
  53. break;
  54. }
  55. glutPostRedisplay();
  56. }
  57. static void Draw(void)
  58. {
  59. glClear(GL_COLOR_BUFFER_BIT);
  60. glEnable(GL_VERTEX_PROGRAM_ARB);
  61. glBegin(GL_TRIANGLES);
  62. glColor3f(0,0,.7);
  63. glVertex3f( 0.9, -0.9, -0.0);
  64. glColor3f(.8,0,0);
  65. glVertex3f( 0.9, 0.9, -0.0);
  66. glColor3f(0,.9,0);
  67. glVertex3f(-0.9, 0.0, -0.0);
  68. glEnd();
  69. glFlush();
  70. if (doubleBuffer) {
  71. glutSwapBuffers();
  72. }
  73. }
  74. static GLenum Args(int argc, char **argv)
  75. {
  76. GLint i;
  77. doubleBuffer = GL_FALSE;
  78. for (i = 1; i < argc; i++) {
  79. if (strcmp(argv[i], "-sb") == 0) {
  80. doubleBuffer = GL_FALSE;
  81. } else if (strcmp(argv[i], "-db") == 0) {
  82. doubleBuffer = GL_TRUE;
  83. } else {
  84. fprintf(stderr, "%s (Bad option).\n", argv[i]);
  85. return GL_FALSE;
  86. }
  87. }
  88. return GL_TRUE;
  89. }
  90. int main(int argc, char **argv)
  91. {
  92. GLenum type;
  93. glutInit(&argc, argv);
  94. if (Args(argc, argv) == GL_FALSE) {
  95. exit(1);
  96. }
  97. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  98. type = GLUT_RGB | GLUT_ALPHA;
  99. type |= (doubleBuffer) ? GLUT_DOUBLE : GLUT_SINGLE;
  100. glutInitDisplayMode(type);
  101. if (glutCreateWindow(*argv) == GL_FALSE) {
  102. exit(1);
  103. }
  104. glewInit();
  105. Init();
  106. glutReshapeFunc(Reshape);
  107. glutKeyboardFunc(Key);
  108. glutDisplayFunc(Draw);
  109. glutMainLoop();
  110. return 0;
  111. }