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.

152 lines
3.2 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. HGLRC ctx2;
  8. void Initialize(void)
  9. {
  10. ctx2 = wglCreateContext(auxGetHDC());
  11. if (ctx2 == NULL)
  12. {
  13. printf("Unable to create ctx2\n");
  14. exit(1);
  15. }
  16. }
  17. void TriangleAt(GLfloat x, GLfloat y, GLfloat z, BOOL colors)
  18. {
  19. glPushMatrix();
  20. glTranslatef(x, y, z);
  21. glBegin (GL_TRIANGLES);
  22. if (colors)
  23. {
  24. glColor3f(1.0f, 0.0f, 0.0f);
  25. }
  26. glVertex2f (0.0f, 0.0f);
  27. if (colors)
  28. {
  29. glColor3f(0.0f, 1.0f, 0.0f);
  30. }
  31. glVertex2f (5.0f, 5.0f);
  32. if (colors)
  33. {
  34. glColor3f(0.0f, 0.0f, 1.0f);
  35. }
  36. glVertex2f (0.0f, 5.0f);
  37. glEnd ();
  38. glPopMatrix();
  39. }
  40. void Test(void)
  41. {
  42. HGLRC old_ctx;
  43. old_ctx = wglGetCurrentContext();
  44. glColor3f(1.0f, 0.0f, 0.0f);
  45. TriangleAt(1.0f, 1.0f, 0.0f, FALSE);
  46. if (!wglCopyContext(old_ctx, ctx2, GL_CURRENT_BIT))
  47. {
  48. printf("Unable to copy context\n");
  49. exit(1);
  50. }
  51. wglMakeCurrent(auxGetHDC(), ctx2);
  52. // Should be red instead of white because current color is copied
  53. TriangleAt(7.0f, 1.0f, 0.0f, FALSE);
  54. wglMakeCurrent(auxGetHDC(), old_ctx);
  55. glEnable(GL_CULL_FACE);
  56. glCullFace(GL_FRONT);
  57. glDisable(GL_DITHER);
  58. // Should be culled
  59. TriangleAt(13.0f, 1.0f, 0.0f, TRUE);
  60. if (!wglCopyContext(old_ctx, ctx2, GL_COLOR_BUFFER_BIT))
  61. {
  62. printf("Unable to copy context\n");
  63. exit(1);
  64. }
  65. wglMakeCurrent(auxGetHDC(), ctx2);
  66. // Should be drawn but not dithered since we only copied the
  67. // color buffer state
  68. TriangleAt(19.0f, 1.0f, 0.0f, TRUE);
  69. wglMakeCurrent(auxGetHDC(), old_ctx);
  70. if (!wglCopyContext(old_ctx, ctx2, GL_POLYGON_BIT))
  71. {
  72. printf("Unable to copy context\n");
  73. exit(1);
  74. }
  75. wglMakeCurrent(auxGetHDC(), ctx2);
  76. // Should be culled now that the culling been copied
  77. TriangleAt(25.0f, 1.0f, 0.0f, TRUE);
  78. wglMakeCurrent(auxGetHDC(), old_ctx);
  79. }
  80. void display(void)
  81. {
  82. glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  83. Test ();
  84. glFlush ();
  85. }
  86. void myReshape(GLsizei w, GLsizei h)
  87. {
  88. HGLRC old_ctx;
  89. old_ctx = wglGetCurrentContext();
  90. glViewport(0, 0, w, h);
  91. glMatrixMode(GL_PROJECTION);
  92. glLoadIdentity();
  93. if (w <= h)
  94. gluOrtho2D (0.0, 100.0, 0.0, 100.0 * (GLfloat) h/(GLfloat) w);
  95. else
  96. gluOrtho2D (0.0, 100.0 * (GLfloat) w/(GLfloat) h, 0.0, 100.0);
  97. glMatrixMode(GL_MODELVIEW);
  98. wglMakeCurrent(auxGetHDC(), ctx2);
  99. glViewport(0, 0, w, h);
  100. glMatrixMode(GL_PROJECTION);
  101. glLoadIdentity();
  102. if (w <= h)
  103. gluOrtho2D (0.0, 100.0, 0.0, 100.0 * (GLfloat) h/(GLfloat) w);
  104. else
  105. gluOrtho2D (0.0, 100.0 * (GLfloat) w/(GLfloat) h, 0.0, 100.0);
  106. glMatrixMode(GL_MODELVIEW);
  107. wglMakeCurrent(auxGetHDC(), old_ctx);
  108. }
  109. /* Main Loop
  110. * Open window with initial window size, title bar,
  111. * RGBA display mode, and handle input events.
  112. */
  113. int __cdecl main(int argc, char** argv)
  114. {
  115. auxInitDisplayMode (AUX_SINGLE | AUX_RGB | AUX_DEPTH16);
  116. auxInitPosition (0, 0, 500, 500);
  117. auxInitWindow ("CopyContext Test");
  118. Initialize();
  119. auxReshapeFunc (myReshape);
  120. auxMainLoop(display);
  121. return 0;
  122. }