added glutGetProcAddress() and GLUT_FPS env var option
[mesa.git] / src / glut / glx / win32_util.c
1
2 /* Copyright (c) Nate Robins, 1997. */
3
4 /* portions Copyright (c) Mark Kilgard, 1997, 1998. */
5
6 /* This program is freely distributable without licensing fees
7 and is provided without guarantee or warrantee expressed or
8 implied. This program is -not- in the public domain. */
9
10
11 #include "glutint.h"
12 #include "glutstroke.h"
13 #include "glutbitmap.h"
14 #include <sys/timeb.h>
15
16 /* The following added by Paul Garceau <pgarceau@teleport.com> */
17 #if defined(__MINGW32__)
18 #include <time.h>
19 #include <windows.h>
20 struct timeval;
21 #endif
22
23 extern StrokeFontRec glutStrokeRoman, glutStrokeMonoRoman;
24 extern BitmapFontRec glutBitmap8By13, glutBitmap9By15, glutBitmapTimesRoman10, glutBitmapTimesRoman24, glutBitmapHelvetica10, glutBitmapHelvetica12, glutBitmapHelvetica18;
25
26 #ifndef __CYGWIN32__
27 int
28 gettimeofday(struct timeval* tp, void* tzp)
29 {
30 struct timeb tb;
31
32 ftime(&tb);
33 tp->tv_sec = tb.time;
34 tp->tv_usec = tb.millitm * 1000;
35
36 /* 0 indicates that the call succeeded. */
37 return 0;
38 }
39 #endif
40
41 /* To get around the fact that Microsoft DLLs only allow functions
42 to be exported and now data addresses (as Unix DSOs support), the
43 GLUT API constants such as GLUT_STROKE_ROMAN have to get passed
44 through a case statement to get mapped to the actual data structure
45 address. */
46 void*
47 __glutFont(void *font)
48 {
49 switch((int)font) {
50 case (int)GLUT_STROKE_ROMAN:
51 return &glutStrokeRoman;
52 case (int)GLUT_STROKE_MONO_ROMAN:
53 return &glutStrokeMonoRoman;
54 case (int)GLUT_BITMAP_9_BY_15:
55 return &glutBitmap9By15;
56 case (int)GLUT_BITMAP_8_BY_13:
57 return &glutBitmap8By13;
58 case (int)GLUT_BITMAP_TIMES_ROMAN_10:
59 return &glutBitmapTimesRoman10;
60 case (int)GLUT_BITMAP_TIMES_ROMAN_24:
61 return &glutBitmapTimesRoman24;
62 case (int)GLUT_BITMAP_HELVETICA_10:
63 return &glutBitmapHelvetica10;
64 case (int)GLUT_BITMAP_HELVETICA_12:
65 return &glutBitmapHelvetica12;
66 case (int)GLUT_BITMAP_HELVETICA_18:
67 return &glutBitmapHelvetica18;
68 }
69 __glutFatalError("out of memory.");
70 /* NOTREACHED */
71 return NULL; /* MSVC compiler complains if there is no return at all */
72 }
73
74 int
75 __glutGetTransparentPixel(Display * dpy, XVisualInfo * vinfo)
76 {
77 /* the transparent pixel on Win32 is always index number 0. So if
78 we put this routine in this file, we can avoid compiling the
79 whole of layerutil.c which is where this routine normally comes
80 from. */
81 return 0;
82 }
83
84 void
85 __glutAdjustCoords(Window parent, int* x, int* y, int* width, int* height)
86 {
87 RECT rect;
88
89 /* adjust the window rectangle because Win32 thinks that the x, y,
90 width & height are the WHOLE window (including decorations),
91 whereas GLUT treats the x, y, width & height as only the CLIENT
92 area of the window. */
93 rect.left = *x; rect.top = *y;
94 rect.right = *x + *width; rect.bottom = *y + *height;
95
96 /* must adjust the coordinates according to the correct style
97 because depending on the style, there may or may not be
98 borders. */
99 AdjustWindowRect(&rect, WS_CLIPSIBLINGS | WS_CLIPCHILDREN |
100 (parent ? WS_CHILD : WS_OVERLAPPEDWINDOW),
101 FALSE);
102 /* FALSE in the third parameter = window has no menu bar */
103
104 /* readjust if the x and y are offscreen */
105 if(rect.left < 0) {
106 *x = 0;
107 } else {
108 *x = rect.left;
109 }
110
111 if(rect.top < 0) {
112 *y = 0;
113 } else {
114 *y = rect.top;
115 }
116
117 *width = rect.right - rect.left; /* adjusted width */
118 *height = rect.bottom - rect.top; /* adjusted height */
119 }
120