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.

vp-tri-tex.c 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Test glGenProgramsNV(), glIsProgramNV(), glLoadProgramNV() */
  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. static void Init( void )
  10. {
  11. GLint errno;
  12. GLuint prognum;
  13. static const char *prog1 =
  14. "!!ARBvp1.0\n"
  15. "MOV result.texcoord[0], vertex.texcoord[0];\n"
  16. "MOV result.position, vertex.position;\n"
  17. "END\n";
  18. glGenProgramsARB(1, &prognum);
  19. glBindProgramARB(GL_VERTEX_PROGRAM_ARB, prognum);
  20. glProgramStringARB(GL_VERTEX_PROGRAM_ARB, GL_PROGRAM_FORMAT_ASCII_ARB,
  21. strlen(prog1), (const GLubyte *) prog1);
  22. assert(glIsProgramARB(prognum));
  23. errno = glGetError();
  24. printf("glGetError = %d\n", errno);
  25. if (errno != GL_NO_ERROR)
  26. {
  27. GLint errorpos;
  28. glGetIntegerv(GL_PROGRAM_ERROR_POSITION_ARB, &errorpos);
  29. printf("errorpos: %d\n", errorpos);
  30. printf("%s\n", (char *)glGetString(GL_PROGRAM_ERROR_STRING_ARB));
  31. }
  32. #define SIZE 32
  33. {
  34. GLubyte tex2d[SIZE][SIZE][3];
  35. GLint s, t;
  36. for (s = 0; s < SIZE; s++) {
  37. for (t = 0; t < SIZE; t++) {
  38. #if 0
  39. tex2d[t][s][0] = (s < SIZE/2) ? 0 : 255;
  40. tex2d[t][s][1] = (t < SIZE/2) ? 0 : 255;
  41. tex2d[t][s][2] = 0;
  42. #else
  43. tex2d[t][s][0] = s*255/(SIZE-1);
  44. tex2d[t][s][1] = t*255/(SIZE-1);
  45. tex2d[t][s][2] = 0;
  46. #endif
  47. }
  48. }
  49. glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
  50. glTexImage2D(GL_TEXTURE_2D, 0, 3, SIZE, SIZE, 0,
  51. GL_RGB, GL_UNSIGNED_BYTE, tex2d);
  52. glEnable(GL_TEXTURE_2D);
  53. glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
  54. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_REPEAT);
  55. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
  56. glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  57. glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
  58. }
  59. }
  60. static void Display( void )
  61. {
  62. glClearColor(0.3, 0.3, 0.3, 1);
  63. glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
  64. glEnable(GL_VERTEX_PROGRAM_NV);
  65. glBegin(GL_TRIANGLES);
  66. glTexCoord2f(1,-1);
  67. glVertex3f( 0.9, -0.9, -0.0);
  68. glTexCoord2f(1,1);
  69. glVertex3f( 0.9, 0.9, -0.0);
  70. glTexCoord2f(-1,0);
  71. glVertex3f(-0.9, 0.0, -0.0);
  72. glEnd();
  73. glFlush();
  74. }
  75. static void Reshape( int width, int height )
  76. {
  77. glViewport( 0, 0, width, height );
  78. glMatrixMode( GL_PROJECTION );
  79. glLoadIdentity();
  80. glOrtho(-1.0, 1.0, -1.0, 1.0, -0.5, 1000.0);
  81. glMatrixMode( GL_MODELVIEW );
  82. glLoadIdentity();
  83. /*glTranslatef( 0.0, 0.0, -15.0 );*/
  84. }
  85. static void Key( unsigned char key, int x, int y )
  86. {
  87. (void) x;
  88. (void) y;
  89. switch (key) {
  90. case 27:
  91. exit(0);
  92. break;
  93. }
  94. glutPostRedisplay();
  95. }
  96. int main( int argc, char *argv[] )
  97. {
  98. glutInit( &argc, argv );
  99. glutInitWindowPosition( 0, 0 );
  100. glutInitWindowSize( 250, 250 );
  101. glutInitDisplayMode( GLUT_DEPTH | GLUT_RGB | GLUT_SINGLE );
  102. glutCreateWindow(argv[0]);
  103. glewInit();
  104. glutReshapeFunc( Reshape );
  105. glutKeyboardFunc( Key );
  106. glutDisplayFunc( Display );
  107. Init();
  108. glutMainLoop();
  109. return 0;
  110. }