Clone of mesa.
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

arbfptexture.c 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. #include <GL/glew.h>
  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. static void Display( void )
  13. {
  14. glClear( GL_COLOR_BUFFER_BIT );
  15. glPushMatrix();
  16. glRotatef(Xrot, 1.0, 0.0, 0.0);
  17. glRotatef(Yrot, 0.0, 1.0, 0.0);
  18. glRotatef(Zrot, 0.0, 0.0, 1.0);
  19. glBegin(GL_POLYGON);
  20. #define Q 2
  21. glColor4f(1.0, 1.0, 1.0, 1); glTexCoord4f(0, 0, 0, Q); glVertex2f(-1, -1);
  22. glColor4f(0.2, 0.2, 1.0, 1); glTexCoord4f(1, 0, 0, Q); glVertex2f( 1, -1);
  23. glColor4f(0.2, 1.0, 0.2, 1); glTexCoord4f(1, 1, 0, Q); glVertex2f( 1, 1);
  24. glColor4f(1.0, 0.2, 0.2, 1); glTexCoord4f(0, 1, 0, Q); 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. "TEX R0, fragment.texcoord[0], texture[0], 2D; \n"
  77. "MUL result.color, R0, fragment.color; \n"
  78. "END"
  79. ;
  80. GLuint modulateProg;
  81. GLuint Texture;
  82. if (!glutExtensionSupported("GL_ARB_fragment_program")) {
  83. printf("Error: GL_ARB_fragment_program not supported!\n");
  84. exit(1);
  85. }
  86. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  87. /* Setup the fragment program */
  88. glGenProgramsARB(1, &modulateProg);
  89. glBindProgramARB(GL_FRAGMENT_PROGRAM_ARB, modulateProg);
  90. glProgramStringARB(GL_FRAGMENT_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  91. strlen(modulate2D), (const GLubyte *)modulate2D);
  92. printf("glGetError = 0x%x\n", (int) glGetError());
  93. printf("glError(GL_PROGRAM_ERROR_STRING_ARB) = %s\n",
  94. (char *) glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  95. assert(glIsProgramARB(modulateProg));
  96. glEnable(GL_FRAGMENT_PROGRAM_ARB);
  97. /* Load texture */
  98. glGenTextures(1, &Texture);
  99. glBindTexture(GL_TEXTURE_2D, Texture);
  100. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  101. glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  102. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  103. if (!LoadRGBMipmaps(TEXTURE_FILE, GL_RGB)) {
  104. printf("Error: couldn't load texture image file %s\n", TEXTURE_FILE);
  105. exit(1);
  106. }
  107. /* XXX this enable shouldn't really be needed!!! */
  108. glEnable(GL_TEXTURE_2D);
  109. glClearColor(.3, .3, .3, 0);
  110. }
  111. int main( int argc, char *argv[] )
  112. {
  113. glutInit( &argc, argv );
  114. glutInitWindowPosition( 0, 0 );
  115. glutInitWindowSize( 250, 250 );
  116. glutInitDisplayMode( GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH );
  117. glutCreateWindow(argv[0]);
  118. glewInit();
  119. glutReshapeFunc( Reshape );
  120. glutKeyboardFunc( Key );
  121. glutSpecialFunc( SpecialKey );
  122. glutDisplayFunc( Display );
  123. Init();
  124. glutMainLoop();
  125. return 0;
  126. }