Clone of mesa.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

tri-sin.c 2.3KB

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