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.

tri-cos.c 2.2KB

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