Source code of Windows XP (NT5)
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.

120 lines
2.3 KiB

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <windows.h>
  4. #include <GL/gl.h>
  5. #include <GL/glu.h>
  6. #include "glaux.h"
  7. #define WIDTH 500
  8. #define HEIGHT 500
  9. void TriangleAt(GLfloat x, GLfloat y, GLfloat z, GLfloat size, BOOL colors)
  10. {
  11. glPushMatrix();
  12. glTranslatef(x, y, z);
  13. glBegin (GL_TRIANGLES);
  14. if (colors)
  15. {
  16. glColor3f(1.0f, 0.0f, 0.0f);
  17. }
  18. glVertex2f (0.0f, 0.0f);
  19. if (colors)
  20. {
  21. glColor3f(0.0f, 1.0f, 0.0f);
  22. }
  23. glVertex2f (size, size);
  24. if (colors)
  25. {
  26. glColor3f(0.0f, 0.0f, 1.0f);
  27. }
  28. glVertex2f (0.0f, size);
  29. glEnd ();
  30. glPopMatrix();
  31. }
  32. void gl_copy(void)
  33. {
  34. GLint ix, iy;
  35. GLsizei w, h;
  36. GLdouble rx1,ry1,rx2,ry2;
  37. GLint mm, dm;
  38. ix = 0;
  39. iy = 0;
  40. w = WIDTH;
  41. h = HEIGHT;
  42. rx1 = 0.;
  43. ry1 = 0;
  44. rx2 = WIDTH;
  45. ry2 = HEIGHT;
  46. glViewport(ix, iy, w, h);
  47. glGetIntegerv(GL_MATRIX_MODE, &mm);
  48. glMatrixMode(GL_PROJECTION);
  49. glLoadIdentity();
  50. gluOrtho2D(rx1, rx2, ry1, ry2);
  51. glMatrixMode(mm);
  52. glScissor (ix, iy, w, h);
  53. glRasterPos2i (ix,iy);
  54. #if 0
  55. glGetIntegerv(GL_DITHER, &dm);
  56. if (dm)
  57. {
  58. glDisable(GL_DITHER);
  59. }
  60. #endif
  61. glCopyPixels (ix, iy, w, h, GL_COLOR);
  62. #if 0
  63. if (dm)
  64. {
  65. glEnable(GL_DITHER);
  66. }
  67. #endif
  68. glFlush();
  69. }
  70. void Test(void)
  71. {
  72. glDrawBuffer(GL_FRONT);
  73. TriangleAt(1.0f, 1.0f, 0.0f, 98.0f, TRUE);
  74. glDrawBuffer(GL_BACK);
  75. glReadBuffer(GL_FRONT);
  76. gl_copy();
  77. TriangleAt(10.0f, 10.0f, 0.0f, 80.0f, TRUE);
  78. auxSwapBuffers();
  79. }
  80. void display(void)
  81. {
  82. glClear (GL_COLOR_BUFFER_BIT);
  83. Test ();
  84. glFlush ();
  85. }
  86. void myReshape(GLsizei w, GLsizei h)
  87. {
  88. glViewport(0, 0, w, h);
  89. glMatrixMode(GL_PROJECTION);
  90. glLoadIdentity();
  91. if (w <= h)
  92. gluOrtho2D (0.0, 100.0, 0.0, 100.0 * (GLfloat) h/(GLfloat) w);
  93. else
  94. gluOrtho2D (0.0, 100.0 * (GLfloat) w/(GLfloat) h, 0.0, 100.0);
  95. glMatrixMode(GL_MODELVIEW);
  96. }
  97. /* Main Loop
  98. * Open window with initial window size, title bar,
  99. * RGBA display mode, and handle input events.
  100. */
  101. int __cdecl main(int argc, char** argv)
  102. {
  103. auxInitDisplayMode (AUX_DOUBLE | AUX_RGB);
  104. auxInitPosition (15, 15, WIDTH, HEIGHT);
  105. auxInitWindow ("Copying Front Buffer to Back Buffer Test");
  106. auxReshapeFunc (myReshape);
  107. auxMainLoop(display);
  108. return 0;
  109. }