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

tri-add.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #define GL_GLEXT_PROTOTYPES
  5. #include <GL/glut.h>
  6. static void Init( void )
  7. {
  8. static const char *modulate2D =
  9. "!!ARBfp1.0\n"
  10. "TEMP R0;\n"
  11. "ADD R0, fragment.color, fragment.color; \n"
  12. "ADD result.color, R0, R0; \n"
  13. "END"
  14. ;
  15. GLuint modulateProg;
  16. if (!glutExtensionSupported("GL_ARB_fragment_program")) {
  17. printf("Error: GL_ARB_fragment_program not supported!\n");
  18. exit(1);
  19. }
  20. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  21. /* Setup the fragment program */
  22. glGenProgramsARB(1, &modulateProg);
  23. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
  24. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  25. strlen(modulate2D), (const GLubyte *)modulate2D);
  26. printf("glGetError = 0x%x\n", (int) glGetError());
  27. printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
  28. (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  29. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  30. glClearColor(.3, .3, .3, 0);
  31. }
  32. static void Reshape(int width, int height)
  33. {
  34. glViewport(0, 0, (GLint)width, (GLint)height);
  35. glMatrixMode(GL_PROJECTION);
  36. glLoadIdentity();
  37. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  38. glMatrixMode(GL_MODELVIEW);
  39. }
  40. static void Key(unsigned char key, int x, int y)
  41. {
  42. switch (key) {
  43. case 27:
  44. exit(1);
  45. default:
  46. return;
  47. }
  48. glutPostRedisplay();
  49. }
  50. static void Draw(void)
  51. {
  52. glClear(GL_COLOR_BUFFER_BIT);
  53. glBegin(GL_TRIANGLES);
  54. glColor3f(0,0,1);
  55. glVertex3f( 0.9, -0.9, -30.0);
  56. glColor3f(1,0,0);
  57. glVertex3f( 0.9, 0.9, -30.0);
  58. glColor3f(0,1,0);
  59. glVertex3f(-0.9, 0.0, -30.0);
  60. glEnd();
  61. glFlush();
  62. }
  63. int main(int argc, char **argv)
  64. {
  65. GLenum type;
  66. glutInit(&argc, argv);
  67. glutInitWindowPosition(0, 0); glutInitWindowSize( 250, 250);
  68. type = GLUT_RGB;
  69. type |= GLUT_SINGLE;
  70. glutInitDisplayMode(type);
  71. if (glutCreateWindow("First Tri") == GL_FALSE) {
  72. exit(1);
  73. }
  74. Init();
  75. glutReshapeFunc(Reshape);
  76. glutKeyboardFunc(Key);
  77. glutDisplayFunc(Draw);
  78. glutMainLoop();
  79. return 0;
  80. }