Clone of mesa.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Test glRead/DrawPixels for GL_DEPTH_COMPONENT, with pixelzoom.
  3. *
  4. * Brian Paul
  5. * 23 August 2003
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <math.h>
  10. #define GL_GLEXT_PROTOTYPES
  11. #include <GL/glut.h>
  12. static GLint WinWidth = 500, WinHeight = 500;
  13. static void Display(void)
  14. {
  15. GLfloat depth[100 * 100];
  16. GLfloat depth2[400 * 400];
  17. GLfloat min, max;
  18. int i;
  19. glClearColor(0.5, 0.5, 0.5, 0);
  20. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  21. /* draw a sphere */
  22. glViewport(0, 0, 100, 100);
  23. glMatrixMode(GL_PROJECTION);
  24. glLoadIdentity();
  25. glOrtho(-1, 1, -1, 1, -1, 0); /* clip away back half of sphere */
  26. glMatrixMode(GL_MODELVIEW);
  27. glLoadIdentity();
  28. glutSolidSphere(1.0, 20, 10);
  29. /* read the depth image */
  30. glReadPixels(0, 0, 100, 100, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
  31. min = max = depth[0];
  32. for (i = 1; i < 100 * 100; i++) {
  33. if (depth[i] < min)
  34. min = depth[i];
  35. if (depth[i] > max)
  36. max = depth[i];
  37. }
  38. printf("Depth value range: [%f, %f]\n", min, max);
  39. /* draw depth image with scaling (into z buffer) */
  40. glPixelZoom(4.0, 4.0);
  41. glWindowPos2i(100, 0);
  42. glDrawPixels(100, 100, GL_DEPTH_COMPONENT, GL_FLOAT, depth);
  43. /* read back scaled depth image */
  44. glReadPixels(100, 0, 400, 400, GL_DEPTH_COMPONENT, GL_FLOAT, depth2);
  45. /* draw as luminance */
  46. glPixelZoom(1.0, 1.0);
  47. glDrawPixels(400, 400, GL_LUMINANCE, GL_FLOAT, depth2);
  48. glutSwapBuffers();
  49. }
  50. static void Reshape(int width, int height)
  51. {
  52. WinWidth = width;
  53. WinHeight = height;
  54. glViewport(0, 0, width, height);
  55. }
  56. static void Key(unsigned char key, int x, int y)
  57. {
  58. (void) x;
  59. (void) y;
  60. switch (key) {
  61. case 27:
  62. exit(0);
  63. break;
  64. }
  65. glutPostRedisplay();
  66. }
  67. static void Init(void)
  68. {
  69. const GLfloat blue[4] = {.1, .1, 1.0, 0.0};
  70. const GLfloat gray[4] = {0.2, 0.2, 0.2, 1.0};
  71. const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
  72. const GLfloat pos[4] = {0, 0, 10, 0};
  73. printf("GL_VERSION = %s\n", (char *) glGetString(GL_VERSION));
  74. printf("GL_RENDERER = %s\n", (char *) glGetString(GL_RENDERER));
  75. glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, blue);
  76. glLightfv(GL_LIGHT0, GL_AMBIENT, gray);
  77. glLightfv(GL_LIGHT0, GL_DIFFUSE, white);
  78. glLightfv(GL_LIGHT0, GL_POSITION, pos);
  79. glEnable(GL_LIGHTING);
  80. glEnable(GL_LIGHT0);
  81. glEnable(GL_DEPTH_TEST);
  82. }
  83. int main(int argc, char *argv[])
  84. {
  85. glutInit(&argc, argv);
  86. glutInitWindowPosition(0, 0);
  87. glutInitWindowSize(WinWidth, WinHeight);
  88. glutInitDisplayMode(GLUT_RGB | GLUT_DEPTH | GLUT_DOUBLE);
  89. glutCreateWindow(argv[0]);
  90. glutReshapeFunc(Reshape);
  91. glutKeyboardFunc(Key);
  92. glutDisplayFunc(Display);
  93. Init();
  94. glutMainLoop();
  95. return 0;
  96. }