Clone of mesa.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

arbfptrig.c 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* GL_ARB_fragment_program texture test */
  2. #include <assert.h>
  3. #include <string.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #define GL_GLEXT_PROTOTYPES
  8. #include <GL/glut.h>
  9. #include "readtex.c"
  10. #define TEXTURE_FILE "../images/girl.rgb"
  11. static GLfloat Xrot = 0.0, Yrot = 0.0, Zrot = 0.0;
  12. #define PI 3.141592
  13. static void Display( void )
  14. {
  15. glClear( GL_COLOR_BUFFER_BIT );
  16. glPushMatrix();
  17. glRotatef(Xrot, 1.0, 0.0, 0.0);
  18. glRotatef(Yrot, 0.0, 1.0, 0.0);
  19. glRotatef(Zrot, 0.0, 0.0, 1.0);
  20. glBegin(GL_POLYGON);
  21. glTexCoord2f(-PI, 0); glVertex2f(-1, -1);
  22. glTexCoord2f(PI, 0); glVertex2f( 1, -1);
  23. glTexCoord2f(PI, 1); glVertex2f( 1, 1);
  24. glTexCoord2f(-PI, 1); glVertex2f(-1, 1);
  25. glEnd();
  26. glPopMatrix();
  27. glutSwapBuffers();
  28. }
  29. static void Reshape( int width, int height )
  30. {
  31. glViewport( 0, 0, width, height );
  32. glMatrixMode( GL_PROJECTION );
  33. glLoadIdentity();
  34. glFrustum( -1.0, 1.0, -1.0, 1.0, 5.0, 25.0 );
  35. glMatrixMode( GL_MODELVIEW );
  36. glLoadIdentity();
  37. glTranslatef( 0.0, 0.0, -8.0 );
  38. }
  39. static void SpecialKey( int key, int x, int y )
  40. {
  41. float step = 3.0;
  42. (void) x;
  43. (void) y;
  44. switch (key) {
  45. case GLUT_KEY_UP:
  46. Xrot += step;
  47. break;
  48. case GLUT_KEY_DOWN:
  49. Xrot -= step;
  50. break;
  51. case GLUT_KEY_LEFT:
  52. Yrot += step;
  53. break;
  54. case GLUT_KEY_RIGHT:
  55. Yrot -= step;
  56. break;
  57. }
  58. glutPostRedisplay();
  59. }
  60. static void Key( unsigned char key, int x, int y )
  61. {
  62. (void) x;
  63. (void) y;
  64. switch (key) {
  65. case 27:
  66. exit(0);
  67. break;
  68. }
  69. glutPostRedisplay();
  70. }
  71. static void Init( void )
  72. {
  73. static const char *modulate2D =
  74. "!!ARBfp1.0\n"
  75. "TEMP R0;\n"
  76. "MOV R0, {0,0,0,1};\n"
  77. "SCS R0, fragment.texcoord[0].x; \n"
  78. "ADD R0, R0, {1.0}.x;\n"
  79. "MUL R0, R0, {0.5}.x;\n"
  80. "MOV result.color, R0; \n"
  81. "END"
  82. ;
  83. GLuint modulateProg;
  84. GLuint Texture;
  85. if (!glutExtensionSupported("GL_ARB_fragment_program")) {
  86. printf("Error: GL_ARB_fragment_program not supported!\n");
  87. exit(1);
  88. }
  89. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  90. /* Setup the fragment program */
  91. glGenProgramsARB(1, &modulateProg);
  92. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
  93. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  94. strlen(modulate2D), (const GLubyte *)modulate2D);
  95. printf("glGetError = 0x%x\n", (int) glGetError());
  96. printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
  97. (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  98. assert(glIsProgramARB(modulateProg));
  99. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  100. /* Load texture */
  101. glGenTextures(1, &Texture);
  102. glBindTexture(GL_TEXTURE_2D, Texture);
  103. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  104. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  105. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  106. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  107. printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
  108. exit(1);
  109. }
  110. /* XXX this enable shouldn't really be needed!!! */
  111. glEnable(GL_TEXTURE_2D);
  112. glClearColor(.3, .3, .3, 0);
  113. }
  114. int main( int argc, char *argv[] )
  115. {
  116. glutInit( &argc, argv );
  117. glutInitWindowPosition( 0, 0 );
  118. glutInitWindowSize( 250, 250 );
  119. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  120. glutCreateWindow(argv[0]);
  121. glutReshapeFunc( Reshape );
  122. glutKeyboardFunc( Key );
  123. glutSpecialFunc( SpecialKey );
  124. glutDisplayFunc( Display );
  125. Init();
  126. glutMainLoop();
  127. return 0;
  128. }