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.

193 lines
3.1 KiB

  1. #undef GEORGE_DEBUG
  2. #ifdef GEORGE_DEBUG
  3. # include <stdio.h>
  4. #endif
  5. #include <windows.h>
  6. #include <math.h>
  7. #include <stdio.h>
  8. #include <GL/gl.h>
  9. #include "tk.h"
  10. #include "gl42ogl.h"
  11. int windX, windY;
  12. void
  13. getorigin (long *x, long *y) {
  14. *x = windX;
  15. *y = windY;
  16. }
  17. long
  18. getvaluator (Device dev) {
  19. /* gl4: origin in bottom right
  20. */
  21. long originX, originY;
  22. int mouseX, mouseY;
  23. long val;
  24. /* cost in performance in repeated calls,
  25. * but hey you want an easy port as possible
  26. */
  27. getorigin (&originX, &originY);
  28. switch (dev) {
  29. case MOUSEX:
  30. tkGetMouseLoc (&mouseX, &mouseY);
  31. val = mouseX + originX;
  32. break;
  33. case MOUSEY:
  34. tkGetMouseLoc (&mouseX, &mouseY);
  35. val = YOUR_SCREEN_MAXY - (mouseY + originY);
  36. break;
  37. default:
  38. fprintf (stderr, "unsupported device: %d\n", dev);
  39. break;
  40. }
  41. return (val);
  42. }
  43. #define PI 3.141593
  44. void
  45. gl_sincos (GLfloat ang, float *sine, float *cosine) {
  46. float rads = ang * PI / 1800;
  47. *sine = (float)sin (rads);
  48. *cosine = (float)cos (rads);
  49. }
  50. void
  51. glGetMatrix (GLfloat mat[]) {
  52. short i;
  53. GLint mode, ptr;
  54. static GLfloat tmp[100];
  55. glGetIntegerv (GL_MATRIX_MODE, &mode);
  56. switch (mode) {
  57. case GL_MODELVIEW:
  58. glGetIntegerv (GL_MODELVIEW_STACK_DEPTH, &ptr);
  59. glGetFloatv (GL_MODELVIEW_MATRIX, tmp);
  60. break;
  61. case GL_PROJECTION:
  62. glGetIntegerv (GL_PROJECTION_STACK_DEPTH, &ptr);
  63. glGetFloatv (GL_PROJECTION_MATRIX, tmp);
  64. break;
  65. case GL_TEXTURE:
  66. glGetIntegerv (GL_TEXTURE_STACK_DEPTH, &ptr);
  67. glGetFloatv (GL_TEXTURE_MATRIX, tmp);
  68. break;
  69. default:
  70. fprintf (stderr, "unknown matrix mode: %d\n", mode);
  71. break;
  72. }
  73. for (i = 0; i < 16; i++)
  74. mat[i] = tmp[i];
  75. }
  76. void
  77. mapcolor (Colorindex index, short r, short g, short b) {
  78. /* gl4 -> rgb = [1,255]
  79. * ogl -> rgb = [0,1]
  80. */
  81. tkSetOneColor (index, r/255.0, g/255.0, b/255.0);
  82. }
  83. void
  84. polf2i (long n, Icoord parray[][2]) {
  85. register long i;
  86. glBegin (GL_POLYGON);
  87. for (i = 0; i < n; i++)
  88. glVertex2iv (parray[i]);
  89. glEnd();
  90. }
  91. void
  92. polf2 (long n, Coord parray[][2]) {
  93. register long i;
  94. glBegin (GL_POLYGON);
  95. for (i = 0; i < n; i++)
  96. glVertex2fv (parray[i]);
  97. glEnd();
  98. }
  99. void
  100. polfi (long n, Icoord parray[][3]) {
  101. register long i;
  102. glBegin (GL_POLYGON);
  103. for (i = 0; i < n; i++)
  104. glVertex3iv (parray[i]);
  105. glEnd();
  106. }
  107. void
  108. polf (long n, Coord parray[][3]) {
  109. register long i;
  110. glBegin (GL_POLYGON);
  111. for (i = 0; i < n; i++)
  112. glVertex3fv (parray[i]);
  113. glEnd();
  114. }
  115. void
  116. poly2i (long n, Icoord parray[][2]) {
  117. register long i;
  118. glBegin (GL_LINE_LOOP);
  119. for (i = 0; i < n; i++)
  120. glVertex2iv (parray[i]);
  121. glEnd();
  122. }
  123. void
  124. poly2 (long n, Coord parray[][2]) {
  125. register long i;
  126. glBegin (GL_LINE_LOOP);
  127. for (i = 0; i < n; i++)
  128. glVertex2fv (parray[i]);
  129. glEnd();
  130. }
  131. void
  132. polyi (long n, Icoord parray[][3]) {
  133. register long i;
  134. glBegin (GL_LINE_LOOP);
  135. for (i = 0; i < n; i++)
  136. glVertex3iv (parray[i]);
  137. glEnd();
  138. }
  139. void
  140. poly (long n, Coord parray[][3]) {
  141. register long i;
  142. glBegin (GL_LINE_LOOP);
  143. for (i = 0; i < n; i++)
  144. glVertex3fv (parray[i]);
  145. glEnd();
  146. }