aboutsummaryrefslogtreecommitdiffstats
path: root/gl4java/GLContext.java.skel
blob: 50aa7c3a4e4bf5777acf4e5caf43c80ff2795873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
/**
 * @(#) GLContext.java
 */


package gl4java;

import gl4java.jau.awt.WinHandleAccess;

import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import java.lang.reflect.*;
import java.security.*;

/**
 * The base manager class for the OpenGL language mapping for Java !
 *
 * <p>
 * If you are interessting in further Documentation and/or
 * the history of GL4Java follow the following link.
 * 
 * <pre>
        <a href="../GL4Java.html">The GL4Java Documentation</a>
 * </pre>
 * <p>
 *
 * All native libraries and GLFunc* and GLUFunc* implementations
 * can/should be loaded right here !
 *
 * <pre>
 	<a href="GLContext.html#doLoadNativeLibraries(java.lang.String, java.lang.String, java.lang.String)">doLoadNativeLibraries</a>
 	<a href="GLContext.html#createGLFunc(java.lang.String)">createGLFunc</a>
 	<a href="GLContext.html#createGLUFunc(java.lang.String)">createGLUFunc</a>
        <p>
        To check the library versions, you can start the 
 	<a href="GLContext.html#main(java.lang.String[])">main</a>
        function with <code>java gl4java.GLContext</code>
 * </pre>
 *
 * <p>
 *
 * This class creates a GLContext in the constructor which fits to the native Window 
 * of the given Component !
 *
 * <pre>
   	<a href="GLContext.html#GLContext(java.awt.Component, gl4java.GLFunc, gl4java.GLUFunc>
 * </pre>
 *
 * <p>
 *
 * If you want to port any OpenGL program to GL4Java,
 * you can use 'glc2glj'. This easy kornshell-sed script converts
 * many types and Math function calls ;-). E.g.: All C double constant literals
 * will be changed to floats (0.0 -> 0.0f) and all sin, cos, .. functions
 * will get the '(float)Math.' prefix !
 *
 * <pre>
	<a href="../../../demos/glc2glj">glc2glj - A simple c to java converter for C- and GL-types</a>
 * </pre>
 * <p>
 *
 * The native libraries are plattform depended. 
 *
 * <pre>
	  The default native library's are:
	  <p>
		GL4JavaJauGljJNI    (jdk ==1.1), 
		GL4JavaJauGljJNI12  (jdk ==1.2),
		GL4JavaJauGljJNI13  (jdk ==1.3)
		GL4JavaJauGljJNI14  (jdk >=1.4)
	  <p>
	  To check wich version and vendors are currently used,
	  just call while a GLContext is created :
	  <p>
	  <a href="GLContext.html#gljShowVersions()">gljShowVersions</a>
	  <p>
	  Or just run at the command line:
	  <p>
	  	java gl4java.GLContext -info
	  <p>
 * </pre>
 *
 * Make sure that this library is installed in your library path.
 * The library path is for Unices one path of the environment 
 * variable �LD_LIBRARY_PATH� and for Windows 32 
 * �c:/winnt/system32� (WinNT) or 'c:/windows/system' (Windows 95) .
 * Or it should be installed in the 'jre/bin' or 
 * 'Netscape/communicator/Program/java/bin'  path !
 *
 * <p>
 *
 * To have a convinient usage, e.g. automatic resizing, GLContext
 * and painting/gl-rendering, some classes in the package gl4java.awt
 * may help you.
 * 
 * <pre>
          E.g.: <a href="awt/GLCanvas.html">gl4java.awt.GLCanvas</a> 
	  <p>
	  <a href="awt/GLCanvas.html#init()">init</a> to create the java-stuff and GL-inits 
	  <a href="awt/GLCanvas.html#display()">display</a> to render one frame, called by paint
	  <a href="awt/GLCanvas.html#reshape(int, int)">reshape</a> to reshape (window resize)
          <p>
          Or look for animation at 
	  <a href="awt/GLAnimCanvas.html">gl4java.awt.GLAnimCanvas</a> !
 * </pre>
 *
 * <p>
 *
 * IF you remove/release a The component which is binded to this GLContext,
 * you have to release the GLContext also - while calling:
 *
 * <pre>
 	<a href="GLContext.html#gljDestroy()">gljDestroy</a>
 * </pre>
 *
 * before releasing/dispose it�s Window !
 * 
 * <p>
 *
 * We also define our own OpenGL extension. This extension functions
 * start with the prefix glj like you can see here:
 *
 * <pre>
        THIS FUNCTIONS ARE FOR USERS PURPOSES:
	======================================

 	<a href="GLContext.html#doLoadNativeLibraries(java.lang.String, java.lang.String, java.lang.String)">doLoadNativeLibraries</a>
 	<a href="GLContext.html#createGLFunc(java.lang.String)">createGLFunc</a>
 	<a href="GLContext.html#createGLUFunc(java.lang.String)">createGLUFunc</a>
 	<a href="GLContext.html#gljIsInit()">gljIsInit</a>
 	<a href="GLContext.html#gljMakeCurrent()">gljMakeCurrent</a>
 	<a href="GLContext.html#gljSwap()">gljSwap</a>
 	<a href="GLContext.html#gljFree()">gljFree</a>
 	<a href="GLContext.html#gljDestroy()">gljDestroy</a>
 	<a href="GLContext.html#gljGetNativeLibVersion()">gljGetNativeLibVersion</a>
 	<a href="GLContext.html#gljGetClassVersion()">gljGetClassVersion</a>
	<a href="GLContext.html#gljShowVersions()">gljShowVersions</a>
 	<a href="GLContext.html#gljCheckGL()">gljCheckGL</a>
 	<a href="GLContext.html#gljCheckGLTypes()">gljCheckGLTypes</a>
 	<a href="GLContext.html#gljResize(int, int)">gljResize</a>

 * </pre>
 * <p>
 *
 * You can see our example demo sources:
 * <pre>
	<a href="../../../demos/olympicCvs.java">olympicCvs.java as java source</a>
	<a href="../../../demos/glLogoCvs.java">glLogoCvs.java as java source</a>
	<a href="../../../demos/glDemosCvs.java">glDemosCvs.java as java source</a>
 * </pre>
 * <p>
 *
 * If you are interessting in further Documentation, downloading the latest
 * version,  and/or the history of GL4Java click on the following link.
 * 
 * <pre>
	<a href="http://www.jausoft.com/gl4java.html">The GL4Java Homepage</a>
 * </pre>
 * <p>
 *
 * @version 	2.00, 21. April 1999
 * @author      Sven Goethel
 * 
 */
public class GLContext extends Object 
	implements Runnable
{
    protected boolean isInitialized = false;

   /**
    * Flag is the native library is loaded.
    * The native library is loaded at startup.
    * If we failed loading the lib., 
    * gljMakeCurrent and gljIsInit will return false.
    *
    * @see gl4java.GLContext#gljIsInit
    */
    protected static boolean libsLoaded 	        = false;

    /**
     * The default extra native library for Windows 95/NT && MS-JVM
     *
     */
    public final static String defGljMSWinLib   = "GL4JavaGljMSJDirect" ;

    /**
     * The default GLContext/GLFunc/GLUFunc native library for all 
     *
     */
    public final static String defGljLib   = "GL4JavaJauGljJNI" ;

    /**
     * The default GLFunc implementation 
     *
     */
    public static final String defGLFuncClass 	   = "GLFuncJauJNI" ;
    public static final String defGLFunc14Class	   = "GLFunc14JauJNI" ;

    /**
     * The default GLUFunc implementation 
     *
     */
    public static final String defGLUFuncClass = "GLUFuncJauJNI" ;
    public static final String defGLUFunc14Class = "GLUFunc14JauJNI" ;

    /**
     * The default native GL library ... for X11
     */
    public final static String defNativeGLLibX11 = "libGL.so";

    /**
     * The default native GL library ... for MacOS9
     */
    public final static String defNativeGLLibMacOS9 = "\\pOpenGLLibrary";

    /**
     * The default native GL library ... for MacOSX
     */
    public final static String defNativeGLLibMacOSX = "libGL.so";

    /**
     * The default native GL library ... for Win32
     */
    public final static String defNativeGLLibWin32 = "OPENGL32.DLL";


    /**
     * The default native GLU library ... for X11
     */
    public final static String defNativeGLULibX11 = "libGLU.so";

    /**
     * The default native GLU library ... for MacOS9
     */
    public final static String defNativeGLULibMacOS9 = "\\pOpenGLULibrary";

    /**
     * The default native GLU library ... for MacOSX
     */
    public final static String defNativeGLULibMacOSX = "libGLU.so";

    /**
     * The default native GLU library ... for Win32
     */
    public final static String defNativeGLULibWin32 = "GLU32.DLL";

   /**
    * the version of this java-class
    *
    * <Major>.<Minor>.<BugFix>.<Release>
    *
    * Each <Value> is dezimal !
    */
   public final static String version             = __SED_CLASS_VERSION__ ;

   /**
    * Flag's to enable/disable verbose Information.
    * Usually for debugging.
    */
    public static boolean gljClassDebug 	= false;
    public static boolean gljThreadDebug 	= false;
    public static boolean gljNativeDebug 	= false;
    
   /**
    * We will store the GL Context right here.
    *
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.GLContext#gljInit
    */
    protected long glContext=0;	
    protected static int glContextNumber=0;	

   /**
    * The context with witch display lists and textures will be shared.
    *
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.GLContext#gljInit
    */
    protected GLContext sharedGLContext;	
    protected long sharedGLContextNative= 0; // No sharing by default.	

   /**
    * Xwindow data AND Windows data for the widget
    *
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.GLContext#gljInit
    */
    protected long pixmapHandle=0;     // unique handle for the Pixmap
    protected long windowHandle=0;     // unique handle for this widget's window
    protected long displayHandle=0;    // unqiue handle to the display
    private int createwinw;
    private int createwinh;

   /**
    * MS-JDirect-Window data for the MS-JVM interface
    *
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.GLContext#gljInit
    */
    private int createwinx;
    private int createwiny;
    private boolean threadRunning = false;
    private boolean destroyWindow = false;
    protected Container containerWindow = null;

   /**
    * The custom set offscreen Size
    *
    * If this is set to != null, 
    * the offscreen pixmap is used in this size,
    * not in the components-size (-> faster if smaller)
    *
    * Must be set via createOffScreenCtx
    *
    * @see gl4java.swing.GLJPanel#paint
    * @see gl4java.GLContext#createOffScreenCtx
    */
    protected Dimension offScrnSize = null;

   /**
    * Windows data AND flag is Window-Handel is read (for X11 also) ! 
    *
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.GLContext#gljInit
    */
    long pData = 0;  // stores the pointer structure that holds windows info

    /**
     * Flag to check, if the OpenGL-Context is active !
     *
     * @see	gl4java.GLContext#isEnabled
     * @see	gl4java.GLContext#setEnabled
     */
    protected boolean glEnabled = true;

   /**
    * Do we use offscreen rendering 
    *  X11: pixmap eq window-ressources, 
    *       window eq. GLXPixmap a GLXDrawable
    *       glContext eq. GLXContext
    *
    * This is set via the constructor !
    * 
    * @see gl4java.GLContext#GLContext
    */
    protected boolean offScreenRenderer = false;    

   /**
    * We normally do not have to create an own Window !
    * This is the default visual property ... !
    * But some machines, like SGI's Irix, 
    * must use an own created overlapped window !
    * For these machines, a compiler flag is set, 
    * so that this value is alsways set to true !
    *
    * This is set via the constructor !
    * 
    * @see gl4java.GLContext#isOwnWindowCreated
    * @see gl4java.GLContext#GLContext
    */
    protected boolean createOwnWindow = false;

   /**
    * The GLCapabilities ..
    *
    * This is set via the constructor !
    * 
    * @see gl4java.GLContext#GLContext
    */
    protected GLCapabilities glCaps = null;

   /**
    * The resize flag, which indicates a resize for the next paint function !
    * This flag will bes set in 'componentResized'
    * and will be cleared after resize (glViewport) in sDisplay !!
    *
    * @see gl4java.awt.GLCanvas#sDisplay
    */
    protected boolean mustResize = false;

    protected Dimension size = null;

    /**
     * the light- or heavy component
     * where GL commands should be drawn
     */
    protected Component _comp = null;

    /**
     * the heavy component
     * where GL commands should be drawn
     *
     * if the _comp component is a swing (light)
     * component, this component contains its heavy parent !
     */
    protected Component _compHeavy = null;

   /**
    * Variable to tell is where windows or not (X11) 
    * Usally X11 ;-))
    *
    * Ok - lets give one to the Max :-) 
    */
    public final static int
       OsWindoof	= -1,
       OsUnknown	=  0,
       OsX11	   	=  1,
       OsMac9		=  2, // for Gerard Ziemski's port
       OsMacX		=  3; // for Gerard Ziemski's port
 
    private static int osType=OsUnknown;
  
    private static boolean isNetscapeJvm = false;
    private static boolean isMicrosoftJvm = false;
    private static boolean isIBMJvm = false;
    private static boolean useMSJDirect = false;
    private static String jvmVendor = null;
    private static String jvmVersion = null;
    private static int    jvmVersionMajor = 1; // min. defaults
    private static int    jvmVersionMinor = 1; // min. defaults
    private static String osName = null;

    private static String jniEXTsuff = "";

   /**
    * Get the native GL Context !
    *
    * @see gl4java.GLContext#glContext
    */
    public final long getNativeGLContext() { return glContext; }

    public final static int getNativeGLContextNumber() 
    { return glContextNumber; }

   /**
    * Get the native Window Handle !
    *
    * @see gl4java.GLContext#windowHandle
    *
    * @deprecated The native window handle is no more accessible
    *             through this method since JDK >= 1.3 !
    */
    public final long getNativeWindoHandle() { return windowHandle; }

   /**
    * Get the optional shared GL Context !
    *
    * @see gl4java.GLContext#sharedGLContext
    */
    public final GLContext getSharedGLContext() { return sharedGLContext; }

   /**
    * Get the native OS-Type !
    *
    * @see gl4java.GLContext#OsWindoof
    * @see gl4java.GLContext#OsUnknown
    * @see gl4java.GLContext#OsX11
    * @see gl4java.GLContext#OsMac9
    * @see gl4java.GLContext#OsMacX
    */
    public static int getNativeOSType() { return osType; }

    public static String getNativeOSName() { return osName; }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final GLCapabilities getGLCapabilities() { return glCaps; }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final boolean isDoubleBuffer() { return glCaps.getDoubleBuffered(); }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final int getStencilBitNumber() { return glCaps.getStencilBits(); }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final int getAccumSize() 
    { return glCaps.getAccumRedBits()+
             glCaps.getAccumGreenBits()+
             glCaps.getAccumBlueBits()+
             glCaps.getAccumAlphaBits();
    }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final boolean isStereoView() { return glCaps.getStereo(); }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#glCaps
    * @see gl4java.GLContext#GLContext
    */
    public final boolean isRGBA() { return glCaps.getTrueColor(); }

   /**
    * Query the visual property ... !
    *
    * After a GLContext is created, this property can be queried !
    *
    * @see gl4java.GLContext#createOwnWindow
    * @see gl4java.GLContext#GLContext
    */
    public final boolean isOwnWindowCreated() { return createOwnWindow; }

    /**
     * Support of loading the native library seperatly.
     *
     * Link with the default native OpenGL library.  
     * If we cannot link, an exception is thrown.  
     *
     * The name of the library is named e.g.: "GL4JavaJauGljJNI" at the 
     * Java level, or "libGL4JavaJauGljJNI.so" at the solaris level,
     * or "GL4JavaJauGljJNI.dll" at the win32 level :-).
     *
     * <p> 
     *
     * The user must call loadNativeLibrary !
     * E.g. he can add the default loader like this:
     * <pre>
	    static {
		if(GLContext.loadNativeLibraries(null, null, null)==false)
		  System.out.println("could not load def. native libs.");
	    }
     * </pre> 
     *
     * @param gljLibName The name of the GLContex/GLFunc/GLUFunc 
     *                   native library.
     *                   If gljLibName==null, the default library will be used !
     *
     * @param glLibName  deprecated
     *
     * @param gluLibName deprecated
     *
     * @return 		boolean, true if succesfull !
     *
     * @see	gl4java.GLContext#defGljLib   
     *
     * @deprecated The arguments glLibName and gluLibName are obsolete,
     *             because all glj/gl/glu stuff resides within 
     *		   the gljLib !
     *		   Now you can use doLoadNativeLibraries !
     */
    public final static boolean loadNativeLibraries ( String gljLibName,
    						String glLibName,
						String gluLibName
					      )
    {
    	return doLoadNativeLibraries(gljLibName, null, null);
    }

    /**
     * Support of loading the native library seperatly.
     *
     * Link with the given OpenGL library.  
     * If we cannot link, an exception is thrown.  
     *
     * You can also specify the OpenGL and GLU library by 
     * the environment variables:
     * <pre>
     		GLTOOL_USE_GLLIB	- OpenGL library name
     		GLTOOL_USE_GLULIB	- GLU    library name
     * </pre>
     * these environment variables does _always_ overrides
     * any given ones at this point !!
     *
     * The name of the library is named e.g.: "GL4JavaJauGljJNI" at the 
     * Java level, or "libGL4JavaJauGljJNI.so" at the solaris level,
     * or "GL4JavaJauGljJNI.dll" at the win32 level :-).
     *
     * <p> 
     *
     * The user must call doLoadNativeLibrary !
     * E.g. he can add the default loader like this:
     * <pre>
	    static {
		if(GLContext.doLoadNativeLibraries(null, null, null)==false)
		  System.out.println("could not load def. native libs.");
	    }
     * </pre> 
     *
     * @param gljLibName The name of the GLContex/GLFunc/GLUFunc 
     *                   native library.
     *                   If gljLibName==null, the default library will be used !
     *
     * @param nativeGLLibName  The name of the native GL library.
     *                   If nativeGLLibName==null, the default library will be used !
     *
     * @param nativeGLULibName The name of the native GLU library.
     *                   If nativeGLULibName==null, the default library will be used !
     *
     * @return 		boolean, true if succesfull !
     *
     * @see	gl4java.GLContext#defGljLib   
     * @see	gl4java.GLContext#defNativeGLLibX11
     * @see	gl4java.GLContext#defNativeGLLibMacOS9
     * @see	gl4java.GLContext#defNativeGLLibMacOSX
     * @see	gl4java.GLContext#defNativeGLLibWin32
     * @see	gl4java.GLContext#defNativeGLULibX11
     * @see	gl4java.GLContext#defNativeGLULibMacOS9
     * @see	gl4java.GLContext#defNativeGLULibMacOSX
     * @see	gl4java.GLContext#defNativeGLULibWin32
     */
    public final static boolean doLoadNativeLibraries ( String gljLibName,
						String nativeGLLibName,
						String nativeGLULibName
					      )
    {
        if(libsLoaded) return true;

        if(gljClassDebug)
	    System.out.println("GLContext.doLoadNativeLibraries will do it !");

        jvmVendor = java.lang.System.getProperty("java.vendor");
        jvmVersion = java.lang.System.getProperty("java.version");

        if(gljClassDebug)
	{
		System.out.println("jvm vendor: "+jvmVendor);
		System.out.println("jvm version: "+jvmVersion);
        }

	int i0 = 0;
	int i1 = jvmVersion.indexOf(".", i0);
        String strhlp = null;
	if(i1>0)
	{
	    strhlp = jvmVersion.substring(i0,i1);
	    try {
	      jvmVersionMajor = Integer.valueOf(strhlp).intValue();
	    } catch (Exception e) 
	    {System.out.println("Not a number: "+strhlp+" ("+jvmVersion+")");}
	}
	i0 = i1+1;
	i1 = jvmVersion.indexOf(".", i0);
	if( i1 < 0 )
		i1 = jvmVersion.length(); // no 2nd dot, no bug version number

	if( 0<i0 && i0<i1 )
	{
	    strhlp = jvmVersion.substring(i0,i1);
	    try {
	      jvmVersionMinor = Integer.valueOf(strhlp).intValue();
	    } catch (Exception e) 
	    {System.out.println("Not a number: "+strhlp+" ("+jvmVersion+")");}
	}

        if(gljClassDebug)
	{
		System.out.println("jvm version (parsed): "+
				   "major: "+jvmVersionMajor+
		                   ", minor: "+jvmVersionMinor);
        }

        isNetscapeJvm = jvmVendor!=null && jvmVendor.indexOf("Netscape")>=0 ;
        isMicrosoftJvm = jvmVendor!=null && jvmVendor.indexOf("Microsoft")>=0 ;
        isIBMJvm = jvmVendor!=null && jvmVendor.indexOf("IBM")>=0 ;

 	// Determine the OS
 	osName = System.getProperty( "os.name" );
 	if( osName.startsWith( "Wind" ) )
	   osType = OsWindoof;
 	else if( osName.startsWith( "Mac OS X" ) )
	   osType = OsMacX;
 	else if( osName.startsWith( "Mac OS" ) )
	   osType = OsMac9;
	else /* oops - lets guess unix/x11 :-) */
	   osType = OsX11;

	String libNames[] = null;

	if( jvmVersionMajor>=2 ||
	       ( jvmVersionMajor==1 && jvmVersionMinor>=4 )
	  )
	{
		jniEXTsuff = "14";
	}

	else 

	if( jvmVersionMajor==1 && jvmVersionMinor>=3 
	    && !isIBMJvm && !isMicrosoftJvm 
	  )
	{
		jniEXTsuff = "13";
	}

	else 

	if( jvmVersionMajor==1 && jvmVersionMinor>=2 )
	{
		jniEXTsuff = "12";
	}

	else 

	{
		jniEXTsuff = "";
	}


	if(gljLibName==null)
	    gljLibName = defGljLib+jniEXTsuff;

	if(nativeGLLibName==null)
	{
	    if ( osType==OsWindoof )
		    nativeGLLibName = defNativeGLLibWin32;
	    else if ( osType==OsMac9 )
		    nativeGLLibName = defNativeGLLibMacOS9;
	    else if ( osType==OsMacX )
		    nativeGLLibName = defNativeGLLibMacOSX;
	    else
		    nativeGLLibName = defNativeGLLibX11;
        }

	if(nativeGLULibName==null)
	{
	    if ( osType==OsWindoof )
		    nativeGLULibName = defNativeGLULibWin32;
	    else if ( osType==OsMac9 )
		    nativeGLULibName = defNativeGLULibMacOS9;
	    else if ( osType==OsMacX )
		    nativeGLULibName = defNativeGLULibMacOSX;
	    else
		    nativeGLULibName = defNativeGLULibX11;
        }

	if ( (osType==OsWindoof) && (isMicrosoftJvm) )
	{
	   // JDirect loads the GL libraries automatically,
	   // so we don't have to.
	   libNames = new String[2];
	   libNames[0]= gljLibName;
	   libNames[1]= defGljMSWinLib;
	   useMSJDirect = true;
	} else {
	   /* For MAC, Win32+SunJVM, Unices ... 
	    */
	   libNames = new String[1];
	   libNames[0]= gljLibName;
	   useMSJDirect = false;
	}

	final String f_libNames[] = libNames;

	if(isNetscapeJvm)
	{
	  System.out.println("Netscape JVM try to get Privileges");
	  try {
	        Class privmgr = 
			Class.forName("netscape.security.PrivilegeManager");
		Class[] parameterTypes = new Class[1];
		parameterTypes[0] = Class.forName("java.lang.String");
		Method m = privmgr.getMethod("enablePrivilege",parameterTypes);
		Object args[] = new Object[1];
		args[0] = (Object)(new String("UniversalLinkAccess"));
		m.invoke(privmgr,args);
		/*
		netscape.security.PrivilegeManager.enablePrivilege
			("UniversalLinkAccess");
		*/
		System.out.println("Netscape-Privilege: enabled UniversalLinkAccess priv.");
	  } catch (Exception ex) 
	  { 
		System.out.println("Not enabled Netscape-Privilege: UniversalLinkAccess priv.");
	  }
	}

	boolean ok;

	if( jvmVersionMajor>=2 ||
	    (jvmVersionMajor==1 && jvmVersionMinor>=2)
	  )
	{
	   Boolean ook = (Boolean)
	     AccessController.doPrivileged(new PrivilegedAction() {
	      public Object run() 
	      {
		/* load libs */
		int libNumber = 0;
		String _libName = null ;
		boolean libLoaded[] = new boolean[f_libNames.length];

		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
		    libLoaded[libNumber]=false;

		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
		{
			do {
			      try {
				System.loadLibrary( f_libNames[libNumber] );  
				libLoaded[libNumber]=true;
				if(gljClassDebug)
				{
				    System.out.println("loaded native library: "+
							f_libNames[libNumber]);
				}
			      } catch ( UnsatisfiedLinkError e) {
				System.out.println
				( "Sorry, can't find the library: "+
				  f_libNames[libNumber]+"\n"+e );
				
				f_libNames[libNumber]=null; // stop trying ... :-(
			      }
			} while( libLoaded[libNumber]==false && 
				 f_libNames[libNumber]!=null );
		}
		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
			if(libLoaded[libNumber]==false) 
				return new Boolean(false);
		return new Boolean(true);
	      }
	     });
	   ok = ook.booleanValue();  
	} else
	{
		/* load libs */
		int libNumber = 0;
		String _libName = null ;
		boolean libLoaded[] = new boolean[f_libNames.length];

		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
		    libLoaded[libNumber]=false;

		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
		{
			do {
			      try {
				System.loadLibrary( f_libNames[libNumber] );  
				libLoaded[libNumber]=true;
				if(gljClassDebug)
				{
				    System.out.println("loaded native library: "+
							f_libNames[libNumber]);
				}
			      } catch ( UnsatisfiedLinkError e) {
				System.out.println
				( "Sorry, can't find the library: "+
				  f_libNames[libNumber]+"\n"+e );
				
				f_libNames[libNumber]=null; // stop trying ... :-(
			      }
			} while( libLoaded[libNumber]==false && 
				 f_libNames[libNumber]!=null );
		}
		ok = true;
		for(libNumber=0; libNumber<f_libNames.length; libNumber++)
			if(libLoaded[libNumber]==false) { ok = false; break; }
	}

	if(ok)
	{
		/**
		 * load the GL/GLU libs natively first, so
		 * the OS can use the dynamic loader to
		 * solve the symbol names ..
		 */
		if(gljClassDebug)
			System.out.println("fetching GL/GLU functions ...");
		if(gljFetchGLFunctions 
			(nativeGLLibName, nativeGLULibName, true)
		  )
		{
			System.out.println("fetched GL/GLU functions succesfully !");
			libsLoaded=true;
		} else {
			System.out.println("GL4Java-ERROR: can't fetch GL/GLU functions !");
		}

	}

	if(!libsLoaded)
		System.exit(1);

	return libsLoaded;
    }
 
    /**
     * Test to load the native library, GLFunc and GLUFunc implementation !
     * If succesfull, a Frame will created and the GL-Infos (vendor, ...)
     * are shown in it !
     *
     * @param args, a list of args, 
     *
     *	  -GLLib    <OpenGL libname> 
     *	  -GLULib   <GLU libname> 
     *    -gljlib   <glj-libname> gl4java-glj-lib native library
     *    -glclass  <gl-class> gl4java-gl-class java GLFunc implementation
     *    -gluclass <glu-class> gl4java-glu-class java GLUFunc implementation
     *    -info     creates a GLContext and prints all avaiable information of GL/GLU and GL4Java
     *    -infotxt  like -info, but exits straight after -info !
     *
     *    without any arguments, a help screen is shown 
     */
    public static void main( String args[] ) 
    {
    	String nativeGLLib = null;
    	String nativeGLULib = null;
     	String gljLibName = null;
     	String glName = null;
     	String gluName = null;
	boolean info=false;
	boolean exitImmediatly=false;
	boolean noFactory=false;
	int i = 0;
	boolean ok=true;

	if(args.length==0)
	{
		System.out.println("usage: java gl4java.GLContext <options>, where options can be: ");
		System.out.println("	-GLLib <OpenGL Libname> \t choose a custom OpenGL native library (default: libGL, or OPENGL32, ..)");
		System.out.println("	-GLULib <GLU Libname> \t choose a custom GLU native library (default: libGLU, or GLU32, ..)");
		System.out.println("	-gljlib <glj-libname> \t choose a custom gl4java-glj-lib native library (default: GL4JavaJauGljJNI)");
		System.out.println("	-glclass <gl-class> \t choose a custom gl4java-gl-class java GLFunc implementation (default: GLFuncJauJNI)");
		System.out.println("	-gluclass <glu-class> \t choose a custom gl4java-glu-class java GLUFunc implementation (default: GLUFuncJauJNI)");
		System.out.println("	-info \t creates a GLContext and prints all avaiable information of GL/GLU and GL4Java");
		System.out.println("	-infotxt \t like -info, but exits straight after -info !");
		System.out.println("	-noFactory \t creates a GLContext without the new GLDrawableFactory API");
	        System.exit(0);
	}

	while(args.length>i)
	{
		if(args[i].equals("-GLLib")) {
			if(args.length>++i) nativeGLLib=args[i];
		} else if(args[i].equals("-GLULib")) {
			if(args.length>++i) nativeGLULib=args[i];
		} else if(args[i].equals("-gljlib")) {
			if(args.length>++i) gljLibName=args[i];
		} else if(args[i].equals("-glclass")) {
			if(args.length>++i) glName=args[i];
		} else if(args[i].equals("-gluclass")) {
			if(args.length>++i) gluName=args[i];
		} else if(args[i].equals("-info")) {
			info=true;
		} else if(args[i].equals("-infotxt")) {
			info=true;
			exitImmediatly=true;
		} else if(args[i].equals("-noFactory")) {
			noFactory=true;
		} else {
		  System.out.println("illegal arg "+i+": "+args[i]);
		  ok=false;
		}
		i++;
	}

	GLContext.gljNativeDebug = true;
	GLContext.gljClassDebug = true;

	GLFunc  gl = null;
	GLUFunc glu = null;

	if(GLContext.doLoadNativeLibraries(gljLibName, 
					 nativeGLLib, nativeGLULib
					)
	  )
		System.out.println("native Libraries loaded succesfull");
	else {
		System.out.println("native library NOT loaded complete");
		ok=false;
	}

	if( (gl=GLContext.createGLFunc(glName)) !=null)
		System.out.println("GLFunc implementation "+gl.getClass().getName()+" created succesfull");
	else {
		System.out.println("GLFunc implementation "+glName+" not created");
		ok=false;
	}
	if( (glu=GLContext.createGLUFunc(gluName)) !=null)
		System.out.println("GLUFunc implementation "+glu.getClass().getName()+" created succesfull");
	else {
	        System.out.println("GLUFunc implementation "+gluName+" not created");
		ok=false;
	}

	if( info && ok==true) {
		Frame f = new Frame("GL4Java Info");
		f.setSize(10, 10);

		Canvas cvs = null;
		GLCapabilities glCaps = new GLCapabilities();
		gl4java.drawable.GLDrawableFactory df = 
			gl4java.drawable.GLDrawableFactory.getFactory();

		if(noFactory || 
		   !(df instanceof gl4java.drawable.SunJDK13GLDrawableFactory)
		  )
		{
			cvs = new Canvas();
		} else {
		        gl4java.drawable.SunJDK13GLDrawableFactory sdf =
			  (gl4java.drawable.SunJDK13GLDrawableFactory)df;
			cvs = new Canvas(sdf.getGraphicsConfiguration(glCaps));
		}
		cvs.setVisible(true);
		cvs.setSize(50,50);
		f.add("Center", cvs);
		f.setSize(60,60);

		// f.pack();
		f.setVisible(true);

		GLContext glj = new GLContext( cvs, gl, glu, glCaps, null);

		Frame fInfo = glj.gljShowVersions();

                fInfo.addWindowListener
		                   ( new WindowAdapter()
                                      {
                                        public void windowClosed(WindowEvent e)
                                        {
                                           // button exit
                                           System.exit(0);
                                        }
                                      }
                                    );              

	        glj.gljDestroy();

		if(exitImmediatly)
		   System.exit(0);
	}
    }
		
    public static String getJVMVersion() { return jvmVersion; }
    public static int getJVMVersionMajor() { return jvmVersionMajor; }
    public static int getJVMVersionMinor() { return jvmVersionMinor; }

    public static String getJVMVendor() { return jvmVendor; }
    public static boolean isNetscapeJVM() { return isNetscapeJvm; }
    public static boolean isMicrosoftJVM() { return isMicrosoftJvm; }
 
    /**
     * Used to hold the user given GLFunc implementation
     */
    private GLFunc gl 	= null;

    /**
     * Used to hold the user given GLUFunc implementation
     */
    private GLUFunc glu = null;

   /**
    *
    * Constructor
    *
    * This privat constructor is for all possible
    * compinations and is called from the customized
    * constructors.
    *
    *  First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _createOwnWindow the flag for the visual property
    * @param _offScreenRenderer the flag for the visual property
    * @param _offScrnSize the fixed offscreen pixmap size
    * @param _glCaps      the GLCapabilities
    * @param _sharedGLContext the shared GLContext
    *
    */
    protected GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		         boolean _createOwnWindow, 
			 boolean _offScreenRenderer,
    			 Dimension _offScrnSize,
			 GLCapabilities _glCaps,
		         GLContext _sharedGLContext
                       )
    {
		super( );

		_comp = comp ;  // the light- or heavy component
		gl    = glf ;
		glu   = gluf ;
	        createOwnWindow = _createOwnWindow;
	        offScreenRenderer = _offScreenRenderer;
		offScrnSize= _offScrnSize;

		glCaps = _glCaps;

		this.sharedGLContext  = _sharedGLContext;
		if(sharedGLContext != null) 
			sharedGLContextNative =
				(int)sharedGLContext.getNativeGLContext();

		// fetch the heavy peer component in temporary var. comp
		while(comp!=null &&
		      (comp.getPeer() instanceof java.awt.peer.LightweightPeer)
		     )
			comp=comp.getParent();

		_compHeavy = comp ;  // the heavy component

    		Graphics  _gr = null;

		if(_compHeavy!=null)
		{
			if( ! _comp.isVisible() )
				setVisible(true); // use our own ...


			_gr = _compHeavy.getGraphics();
			if(_gr==null)
			  System.out.println("got empty Graphics");
		} else
		  System.out.println("got empty Component");

		if(_comp!=null && _gr!=null)
		{
			int i = 0;
			do {
				createGLContext(_gr); // uses _comp
				if(gljIsInit()==false)
				{
				    try
				    {
				      Thread.sleep( 100 );
				    }
				    catch( Exception e )
				    { }
				}
				i++;
			} while(gljIsInit()==false && i<5) ;
		}

	        if(gljClassDebug)
		{
			if(gljIsInit())
			  System.out.println("GLContext GLContext() succeded");
			else
			  System.out.println("GLContext GLContext() failed");
		}
    }

   /**
    *
    * Constructor
    *
    * This privat constructor is for all possible
    * compinations and is called from the customized
    * constructors.
    *
    *  First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _createOwnWindow the flag for the visual property
    * @param _offScreenRenderer the flag for the visual property
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    * @param _accumSize   the flag for the visual property
    * @param _sharedGLContext the shared GLContext
    * @param _offScrnSize the fixed offscreen pixmap size
    *
    */
    protected GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		         boolean _createOwnWindow, boolean _offScreenRenderer,
                         boolean _doubleBuffer, boolean _stereoView,
		         boolean _rgba,
		         int _stencilBits,
		         int _accumSize,
		         GLContext _sharedGLContext,
    			 Dimension _offScrnSize
                       )
    {
		this( comp, glf, gluf, _createOwnWindow, 
		      _offScreenRenderer, _offScrnSize,
		      new GLCapabilities(_doubleBuffer, _stereoView,
					 _rgba, _stencilBits, 
					 _accumSize, _accumSize, 
					 _accumSize, _accumSize),
		      _sharedGLContext);
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _glCaps      the GLCapabilities
    * @param _sharedGLContext the shared GLContext
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		      GLCapabilities _glCaps,
		      GLContext _sharedGLContext
                    )
    {
		this( comp, glf, gluf, false, 
		      false, null, _glCaps, 
		      _sharedGLContext);
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _createOwnWindow the flag for the visual property
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    * @param _accumSize   the flag for the visual property
    * @param _sharedGLContext the shared GLContext
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		      boolean _createOwnWindow,
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba,
		      int _stencilBits,
		      int _accumSize,
		      GLContext _sharedGLContext
                    )
    {
    	this(comp, glf, gluf, 
	      _createOwnWindow, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      _stencilBits,
	      _accumSize,
	      _sharedGLContext,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _createOwnWindow the flag for the visual property
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    * @param _accumSize   the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		      boolean _createOwnWindow,
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba,
		      int _stencilBits,
		      int _accumSize
                    )
    {
    	this(comp, glf, gluf, 
	      _createOwnWindow, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      _stencilBits,
	      _accumSize,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _createOwnWindow the flag for the visual property
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
		      boolean _createOwnWindow,
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba,
		      int _stencilBits
                    )
    {
    	this(comp, glf, gluf, 
	      _createOwnWindow, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      _stencilBits,
	      0 /* accumSize */,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba,
		      int _stencilBits,
		      int _accumSize
                    )
    {
    	this(comp, glf, gluf, 
	      false /* ownWindow */, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      _stencilBits,
	      _accumSize,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba,
		      int _stencilBits
                    )
    {
    	this(comp, glf, gluf, 
	      false /* ownWindow */, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      _stencilBits,
	      0 /* accumSize */,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
                      boolean _doubleBuffer, boolean _stereoView,
		      boolean _rgba
                    )
    {
    	this(comp, glf, gluf, 
	      false /* ownWindow */, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      _rgba,
	      0, /* _stencilBits */
	      0 /* accumSize */,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * ! WARNING ! This flag is just for testing purpose !!!
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _doubleBuffer the flag for the visual property
    * @param _stereoView  the flag for the visual property
    *
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf, 
                      boolean _doubleBuffer, boolean _stereoView
                    )
    {
    	this(comp, glf, gluf, 
	      false /* ownWindow */, false /* offscreen renderer */,
	      _doubleBuffer,
	      _stereoView,
	      true /* _rgba */,
	      0, /* _stencilBits */
	      0 /* accumSize */,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * We use a visual with doubleBuffer and NO stereoView !
    * Do not force a new native window !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	the users component for the gl-context
    * @param glf	the users selected GLFunc implementation
    * @param glf	the users selected GLUFunc implementation
    */
    public GLContext( Component comp, GLFunc glf, GLUFunc gluf )
    {
    	this(comp, glf, gluf, 
	      false /* ownWindow */, false /* offscreen renderer */,
	      true /* _doubleBuffer */,
	      false /* _stereoView */,
	      true /* _rgba */,
	      0, /* _stencilBits */
	      0 /* accumSize */,
	      null /* sharedGLContext */,
	      null /* offscreen size */
	    );
    }

   /**
    *
    * Constructor Function for offscreen rendering !
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    * @param _sharedGLContext the shared GLContext
    *
    * @return             the created offscreen context
    */
    public final static GLContext createOffScreenCtx
    		       ( Component comp, GLFunc glf, GLUFunc gluf, 
                         boolean _stereoView,
		         boolean _rgba,
		         int _stencilBits,
		         int _accumSize,
		         GLContext _sharedGLContext
                       )
    {
    	return new GLContext(comp, glf, gluf, 
		      false /* _createOwnWindow */, 
		      true /* offscreen renderer */,
		      false /* _doubleBuffer */,
		      _stereoView,
		      _rgba,
		      _stencilBits,
		      _accumSize,
		      _sharedGLContext,
		      null
		    );
    }

   /**
    *
    * Constructor Function for offscreen rendering !
    *
    * First the GLContext is fetched from the Component itself !
    * To do so, the Component is set visible if it is not !
    *
    * If a GLContext is fetched, it is current !
    *
    * @param comp	  the users component for the gl-context
    * @param glf	  the users selected GLFunc implementation
    * @param glf	  the users selected GLUFunc implementation
    * @param _stereoView  the flag for the visual property
    * @param _rgba	  the flag for the visual property
    * @param _stencilBits the flag for the visual property
    * @param _sharedGLContext the shared GLContext
    * @param _offScrnSize the fixed offscreen pixmap size
    *
    * @return             the created offscreen context
    */
    public final static GLContext createOffScreenCtx
    		       ( Component comp, GLFunc glf, GLUFunc gluf, 
                         boolean _stereoView,
		         boolean _rgba,
		         int _stencilBits,
		         int _accumSize,
		         GLContext _sharedGLContext,
    			 Dimension _offScrnSize
                       )
    {
    	return new GLContext(comp, glf, gluf, 
		      false /* _createOwnWindow */, 
		      true /* offscreen renderer */,
		      false /* _doubleBuffer */,
		      _stereoView,
		      _rgba,
		      _stencilBits,
		      _accumSize,
		      _sharedGLContext,
		      _offScrnSize
		    );
    }

    /**
     * @see	gl4java.GLContext#gljDestroy   
     */
    protected void finalize()
    	throws Throwable
    {
	gljDestroy();
	super.finalize();
    }

    /**
     * Used to set the user given GLFunc implementation
     */
    public final void setGLFunc(GLFunc _gl) { gl = _gl; }

    /**
     * Used to set the user given GLUFunc implementation
     */
    public final void setGLUFunc(GLUFunc _glu) { glu = _glu; }

    /**
     * Used to return the user given GLFunc implementation
     */
    public final GLFunc getGLFunc() { return gl; }

    /**
     * Used to return the user given GLUFunc implementation
     */
    public final GLUFunc getGLUFunc() { return glu; }

    /**
     * Support of loading a vendors GLFunc implementation
     *
     * Try to load the Class, if succesfull we do return the instance of it.
     * Else null is returned !
     *
     * The Class-Name is: "GL4Java." + vendorClass + ".class" !
     *
     * @param vendorClass  The name of the GLFunc implementation.
     *                     If vendorSuffix==null, the default implementation 
     *			   "GLFuncJauJNI" (-> GL4Java.GLFuncJauJNI.class ) 
     *			   will be used !
     *
     * @return 		GLFunc, the implementation's instance if exists 
     *			and valid, or null
     *
     * @see	gl4java.GLContext#defGLFuncClass   
     */
    public final static GLFunc createGLFunc(String vendorClass)
    {
        String access_name = "gl4java.";
	GLFunc gl = null;
	Object clazz = null;

	if(vendorClass==null) 
	{
          if (jvmVersionMajor>=2 ||
              (jvmVersionMajor==1 && jvmVersionMinor>=4)) {
            vendorClass = defGLFunc14Class;
          } else {
            vendorClass = defGLFuncClass;
          }
	}

	String clazzName   = access_name + vendorClass ;

	try {
		clazz = Class.forName(clazzName).newInstance();
	} catch (Exception ex) {
		// thats ok :-)
		System.out.println("could not create instance of: "+ clazzName);
	}
	if(clazz !=null && (clazz instanceof GLFunc))
		gl = (GLFunc) clazz;
	else
		System.out.println("Not a GLFunc implementation: "+ clazzName);

	return gl;
    }

    /**
     * Support of loading a vendors GLUFunc implementation
     *
     * Try to load the Class, if succesfull we do return the instance of it.
     * Else null is returned !
     *
     * The Class-Name is: "GL4Java." + vendorClass + ".class" !
     *
     * @param vendorClass  The name of the GLUFunc implementation.
     *                     If vendorSuffix==null, the default implementation 
     *			   "GLUFuncJauJNI" (-> GL4Java.GLUFuncJauJNI.class ) 
     *			   will be used !
     *
     * @return 		GLUFunc, the implementation's instance if exists 
     *			and valid, or null
     *
     * @see	gl4java.GLContext#defGLUFuncClass   
     */
    public final static GLUFunc createGLUFunc(String vendorClass)
    {
        String access_name = "gl4java.";
	GLUFunc glu = null;
	Object clazz = null;

	if(vendorClass==null) 
	{
          if (jvmVersionMajor>=2 ||
              (jvmVersionMajor==1 && jvmVersionMinor>=4)) {
	    vendorClass = defGLUFunc14Class ;
          } else {
	    vendorClass = defGLUFuncClass ;
          }
	}


	String clazzName   = access_name + vendorClass ;

	try {
		clazz = Class.forName(clazzName).newInstance();
	} catch (Exception ex) {
		// thats ok :-)
		System.out.println("could not create instance of: "+ clazzName);
	}
	if(clazz!=null && (clazz instanceof GLUFunc))
		glu = (GLUFunc) clazz;
	else
		System.out.println("Not a GLUFunc implementation: "+ clazzName);
		

	return glu;
    }

   /**
    *
    * Own setVisible
    * This one set's us visible - and wait's for that result !
    *
    * @param visible	boolean: visible==true, hide==false
    * @return 		void
    */ 
    public void setVisible( boolean visible )
    {
    	    int i= 0;

	    _comp.setVisible( visible );

	    while( _comp.isVisible() != visible  && i<5) 
	    {
		_comp.setVisible( visible );

	        try
	        {
		    Thread.sleep( 100 );
	        }
	        catch( Exception e )
	        {
		    System.out.println( "GLContext:setVisible: Error - " + e );
	        }
		i++;
	    }
	    if(i>=5)
	      System.out.println( "GLContext:setVisible: Error, could not set to "+visible); 
    }

   /**
    *
    * createGLContext gets the window handle and calls gljInit,
    * so the gl-context will be initialised here.
    *
    * this method will be invoked by the constructor
    *
    * this method is left public - this time,
    * to allow the user to to it again later - if it was not succesfull !
    *
    * @param g		the graphics reference, 
    *			where we will get the native window handle from.
    *
    * @return 		void
    *
    * @see gl4java.GLContext#GLContext
    */ 
    public final void createGLContext(Graphics g)
    {
        String access_name = "gl4java.jau.awt.";
        WinHandleAccess win_access = null;

	try {
	    if(gljClassDebug)
	      System.out.println("GLContext createGLContext");
 
          if(pData == 0)
	  {
	    if ( useMSJDirect )
	    {
	          if(gljClassDebug)
			  System.out.println("using MSJDirect ...");

		  win_access = (WinHandleAccess)
		    Class.forName(
	               access_name+"windows.MSWin32HandleAccess"
		    ).newInstance();
                  /* _comp should be a subclass of Canvas, and its parent
                     class should be of type Panel, Frame or Window.  If not,
                     this all falls apart. */

		  /* This part is now rewritten, 
	             to respect direkt Windows (Frames and Dialogs)
		     and Applets .. */

                  Component ob = _comp;

		  while ( (ob instanceof Window)==false &&
		  	  (ob instanceof Applet)==false
			)
		  {
                      ob = ob.getParent();
                  }

		  containerWindow = (Container)ob;

		  /* refetch the Graphics component */
		  g = ob.getGraphics();
		  if(g==null)
		    System.out.println("GL4Java-MSJVM: got empty Graphics");

		  pData = win_access.getWinHandle(ob,g);

		  if (pData != 0)
		  {
			Point p1;
			try
			{
				p1 = _comp.getLocationOnScreen();
			}
			catch (Exception e)
			{
				p1 = _comp.getLocation();
				Point p2 = containerWindow.getLocation();
				p1.x += p2.x;
				p1.y += p2.y;
				Insets is = containerWindow.getInsets();
				p1.x += is.left;
				p1.y += is.top;
			}
			Rectangle r = _comp.getBounds();
			createwinx = p1.x;
			createwiny = p1.y;
			createwinw = r.width;
			createwinh = r.height;
			windowHandle = 0;
			threadRunning = true;
			destroyWindow = false;
			Thread th = new Thread(this);
			th.start();
			while ( (windowHandle == 0) && (threadRunning) )
			{
				try
				{
					Thread.currentThread().sleep(100);
				}
				catch( Exception e )
				{ }
			}
		  }
 	    } else if(osType==OsWindoof && !useJAWT())
	    {
		  win_access = (WinHandleAccess) 
		    Class.forName(
		        access_name+"windows.Win32HandleAccess"
		    ).newInstance();
		  pData = win_access.getWinHandle(_compHeavy, g);
		  windowHandle = pData;
	    }
            else if((osType==OsMac9 || osType==OsMacX) && !useJAWT())
            {
		  win_access = (WinHandleAccess)
		    Class.forName(
			access_name+"macintosh.MacHandleAccess"
		    ).newInstance();
		  pData = win_access.getWinHandle(_compHeavy, g);
		  windowHandle = pData;
            }     
	    else if(!useJAWT())
	    {
		  win_access = (WinHandleAccess) 
		    Class.forName(
		         access_name+"motif.X11HandleAccess"
		    ).newInstance();
		  pData = win_access.getWinHandle(_compHeavy, g);
		  windowHandle = pData;
	    }
	  }

	  if(offScrnSize!=null)
	  {
		  createwinw = offScrnSize.width;
		  createwinh = offScrnSize.height;
	  } else {
		  Rectangle r = _comp.getBounds();
		  createwinw = r.width;
		  createwinh = r.height;
	  }

	  /* try to establish a context to OpenGL */
	  try 
	  {
		    gljInit();
	  }
	  catch( GL4JavaInitException e ) 
	  {
		    System.out.println( "can't create a GL context\n");
	  }
    
	} catch (Exception e) {
	      System.out.println( "An exception is thrown, while creating a GL context\n");
	      System.out.println(e);
	      e.printStackTrace();
	}
    }

    /* glj* stuff */
    			
   /**
    *
    * Initializes the gl-context. 
    * gljInit is called by createGLContext (which is calles by the first paint)!
    *
    * Also gljInit will call the init method after GL initialisation,
    * so the user can override �init� to initialize his own stuff !
    *
    * @return 		void
    * @exception 	GL4Java.GL4JavaInitException 
    *			this class throws an exception 
    *			if the native call to create a OpenGL context failed.
    * @see gl4java.GLContext#createGLContext
    * @see gl4java.awt.GLCanvas#paint
    * @see gl4java.awt.GLCanvas#init
    */ 
    protected final synchronized void gljInit() 
      throws GL4JavaInitException 
    {
	if( libsLoaded==false ) return ;

	if(glCaps==null)
	{
	    System.out.println("Internal error: glCaps not initialized !!");
            throw new GL4JavaInitException ();
	}

	if(pData==0 && !offScreenRenderer && !useJAWT())
	{
	    System.out.println("could not open a GL widget -- Win CONTEXT");
            throw new GL4JavaInitException ();
	}

	if(gljClassDebug)
	  System.out.println("GLContext gljInit");

        boolean ok;

	ok = openOpenGLNative(_comp);

        if( ! ok )
        {
	    if ( useMSJDirect )
	    {
		destroyWindow = true;
		while (threadRunning)
		{
			try
			{
				Thread.currentThread().sleep(100);
			}
			catch( Exception e )
			{ }
		}
		pData = 0;
		windowHandle = 0;
	    }
	    System.out.println("could not open a GL widget -- GL CONTEXT");
            throw new GL4JavaInitException ();
          } else {
	    isInitialized = true;
	    glEnabled=true;
	    glContextNumber++;
	}
    }

    /**
     * For MSJVM Only !
     *
     * This functions fetches the window-handle within a special thread !
     */
    public void run()
    {
	if ( !useMSJDirect )
	{
		System.err.println("GL4Java-MSJVM-Run: INTERNAL ERROR"); 
		System.exit(0);
	}

	/*
	System.out.println("OGL create win: x="+createwinx+", y="+createwiny+
				", w="+createwinw+", h="+createwinh);
	System.out.println("OGL create parent: "+pData);
	*/

	pData = gl4java.system.GljMSJDirect.createOGLWindowNative( 
					      pData,
	                                      createwinx,createwiny,
					      createwinw,createwinh);
	if (pData != 0)
	{
		windowHandle = pData;
		while (!destroyWindow)
		{
			gl4java.system.GljMSJDirect.OGLWindowMsgPump();
			try
			{
				Thread.currentThread().sleep(10);
			}
			catch( Exception e )
			{ }
		}
		destroyWindow = false;
		gl4java.system.GljMSJDirect.destroyOGLWindowNative(
								windowHandle);
		windowHandle = 0;
		pData = 0;
		gl4java.system.GljMSJDirect.OGLWindowMsgPump();
	}
	threadRunning = false;
    }

   /**
    *
    * Checks if the gl-context is Initializes
    * If returns true,
    * gljInit is allready called and a valid gl-context is achieved.
    *
    * No glMakeCurrent is done - 
    * like gljMakeCurrent (important for more gl-context) !
    * 
    * <p>
    *
    * The user can use this method to check if he can start rendering
    * and to be sure his initialisation (init) is done !
    *
    * <p>
    *
    * If you use gl4java.awt.GLCanvas, you should use the cvsIsInit
    * method !
    * <p>
    *
    * @return 		boolean
    * @see gl4java.GLContext#gljInit
    * @see gl4java.awt.GLCanvas#cvsIsInit
    */ 
    public final boolean gljIsInit() 
    {
	return isInitialized;
    }

    /**
     * Resizes the gl-viewport
     *
     * Should be called, if the component is resized.
     * The user should take advantage of this functionality.
     *
     * Be sure to resize not within the event-method of the
     * ComponentHandler, you better resize while normal painting.
     * This can be done while using a boolean flag ;-)
     * 
     * Look at GLComponent !
     */
    public final void gljResize(int width, int height)
    {
    	if ( ! isInitialized || !glEnabled ) return;

	if(offScreenRenderer)
	{
		//JAU: TODO
		return;
	}

	if ( useMSJDirect )
        {
		try
		{
			Point p = _comp.getLocationOnScreen();
			gl4java.system.GljMSJDirect.moveOGLWindowNative(
					     windowHandle,p.x,p.y,width,height);
		}
		catch (Exception e)
		{ }
	}
        else
                gljResizeNative( createOwnWindow,
		                 displayHandle, windowHandle,
		                 width,height);
    }

    private final native void gljResizeNative( boolean isOwnWindow,
				               long disp, long thisWin,
				               int width, int height );

    /**
     * native C function of GLJ Library,
     * which query if it uses the JDK 1.3 JAWT interface
     * to fetch the native window handle
     */
    protected final native boolean useJAWT();

    /**
     * native C function of GLJ Library,
     * which query if the JAWT Surface has changed !
     *
     * Use this after gljMakeCurrent -> jawt_lock !
     *  
     * If true, we need a new GLContext !
     */
    protected final native boolean hasJAWTSurfaceChanged(long thisWin);

    /**
     * native C function to open the OpenGLwidget
     */
    protected final native boolean openOpenGLNative(Component canvas);

    /**
     * native C function to check the gl types.
     * At this time, all GL* types will be checked if they fit's
     * in the used java JNI types.
     *
     * this checks is allready performed, while the GL context is
     * fetched with gljInit !
     *
     * BUT we used this function, to perform a check without an
     * X11-connection to our AIX host ;-))
     * So a call to this function is not needed !
     */
    public final static boolean gljCheckGLTypes()
    {
        return gljCheckGLTypesNative();
    }

    private final static native boolean gljCheckGLTypesNative();

    public final boolean gljCheckGL()
    {
    	if ( ! isInitialized || !glEnabled ) return false;

	int ec = gl.glGetError();

	if(ec!=GLFunc.GL_NO_ERROR)
	{
		String errStr = glu.gluErrorString(ec);

		try
		{
		   throw new Exception();
		}
		catch (Exception e)
		{
		   System.out.println("GL ERROR : "+errStr);
		   System.out.println("GL ERROR : "+ec+" == 0x"+Integer.toHexString(ec));
		   e.printStackTrace();
		   System.out.println();
		   System.out.flush();
		}

		return false;
	}
	return true;
    }

   private Thread ctxThread = null;
   private Thread nextThread = null;

   /**
    *
    * gljIsCurrent checks 
    * if the current Thread holds the GL context of this 
    * GLContext instance !
    *
    * @return 		boolean
    *
    * @see gl4java.GLContext#gljIsRequested
    * @see gl4java.GLContext#gljMakeCurrent
    * @see gl4java.GLContext#getNativeGLContext
    * @see gl4java.GLContext#gljGetCurrentContext
    */ 
   public synchronized final boolean gljIsCurrent()
   {
    	if ( ! isInitialized || !glEnabled )
	    return false;

	Thread thisThread = Thread.currentThread();

        if (ctxThread==thisThread && glContext==gljGetCurrentContext())
	     return true;

        return false;
   }

   /**
    *
    * gljIsRequested checks 
    * if the this GLContext instance's native context
    * is requested by another thread !
    *
    * @return 		boolean
    *
    * @see gl4java.GLContext#gljIsCurrent
    * @see gl4java.GLContext#gljMakeCurrent
    * @see gl4java.GLContext#getNativeGLContext
    * @see gl4java.GLContext#gljGetCurrentContext
    */ 
   public synchronized final boolean gljIsRequested()
   {
    	if ( ! isInitialized || !glEnabled )
	    return false;

	Thread thisThread = Thread.currentThread();

        if (nextThread!=null && nextThread!=thisThread)
	     return true;

        return false;
   }

   /**
    *
    * gljMakeCurrent checks whether GL4Java is initializes 
    * AND makes the GL-Context current for this thread.
    *
    * <p>
    *
    * This functions now optimizes the context-switch !
    *
    * The context is changed, only if :
    * <pre>
    	- another thread has requested this context -> release it
	  this gives the other thread a chance to get it ..

	- this thread does not own the current context
    * </pre>
    *
    * <p>
    *
    * You MUST encapsulate your OpenGL call's within:
    * <pre>
    	- gljMakeCurrent()
		YOUR OpenGL commands here !
    	- gljFree()
    * </pre>
    *
    * @return 		boolean
    *
    * @see gl4java.GLContext#gljSwap
    * @see gl4java.awt.GLCanvas#display
    * @see gl4java.awt.GLCanvas#sDisplay
    */ 
    public synchronized final boolean gljMakeCurrent()
    {
    	if ( ! isInitialized || !glEnabled )
	    return false;

	Thread thisThread = Thread.currentThread();
	boolean dbgPrinted = false;

	/**
	 * force a thread switch to improve responsiveness !
	 *
	 * if an earmarked thread exist (nextThread)
	 * we have to wait ..
	 */
	while (nextThread!=null && nextThread!=thisThread)
	{
	     if(gljThreadDebug && !dbgPrinted)
	     {
		     System.out.println("wait-switch: "+thisThread);
	     	     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	     }

	     if(ctxThread==thisThread)
	     {
	         /** 
	          * Force freeing this threads context .. to avoid a deadlock ..
	          * This makes sense, because it is possible,
	          * that the same thread enters this point twice,
	          * before calling gljFree !
	          */
	         if(gljThreadDebug && !dbgPrinted)
	         {
	             System.out.println("wait-current: "+thisThread+" for earmarked: "+nextThread);
	             System.out.println("\tfreeing context force .. ctxThread="+ctxThread);
	         }

	         gljFree(true); // force freeing the context
	     }

	     dbgPrinted=true;

	     try {
		  // wait till earmarked nextThread has its chance ..
	          wait();
	     } catch (InterruptedException e) { }
	}
        dbgPrinted=false;

	/**
	 *  put all req. threads to the wait-state,
	 *  if another thread owns the GLXContext !
	 */
	while (ctxThread!=null && ctxThread!=thisThread)
	{
	     /**
	      * remember this thread as earmarked,
	      * to be sure being the next one ...
	      */
	     nextThread = thisThread;

	     if(gljThreadDebug && !dbgPrinted)
	     {
		     System.out.println("wait-earmarked: "+thisThread);
	     	     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
		     dbgPrinted=true;
	     }
             if( _comp instanceof GLRunnable )
	     {
	     	if ( ((GLRunnable)_comp).ownsThread(ctxThread) )
		{
			synchronized (_comp) {
				((GLRunnable)_comp).freeGLContext();
				((GLRunnable)_comp).notifyAll();
			}
			notifyAll();
		        if(gljThreadDebug)
				System.out.println("\tfreeGLContext -> "+ctxThread);
		}
	     }

	     try {
		  // wait for gljFree to release the GLXContext
	          wait();
	     } catch (InterruptedException e) { }
	}

	boolean result = false;

	/* is this thread allready owning the context ? */
        if ( gljIsCurrent() )
	{
		result = lockJAWT(_comp, windowHandle, gljThreadDebug);
		if(gljThreadDebug)
		     System.out.println("MakeCurrent: "+thisThread+" no CTX change, allready own, lockJAWT: "+result);
		return result;
	} else if( ctxThread!=null && ctxThread!=thisThread ) {
	     System.out.println("MakeCurrent: ctxThread ain't zero, funny failure");
	     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	     return result;
	}

	ctxThread = thisThread ; // blocking asap ..

        if(gljThreadDebug)
	{
		if(nextThread==thisThread)
		{
		     System.out.println("MakeCurrent: "+thisThread+" <EarMarked Run>");
	        } else {
		     System.out.println("MakeCurrent: "+thisThread+" <New>");
		}
	        System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	}

	/**
	 * if next thread gotten the context, it is no more earmarked ..
	 */
        if(nextThread==thisThread)
	     nextThread = null;

        result =  gljMakeCurrentNative( _comp, displayHandle, 
	                                windowHandle, glContext);

	/**
	 * If glXMakeCurrent failed, nobody holds this GLXContext ..
	 */
	if(!result)
	{
	        if(gljThreadDebug)
		{
			     System.out.println("Native MakeCurrent failed");
			     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
			     Exception e = new Exception();
			     e.printStackTrace();
		}

		if(hasJAWTSurfaceChanged(windowHandle))
		{
			/**
			 * This can only happen while using JAWT ..
			 */
			System.out.println("GL4Java: JAWT Surface-Change !!!");
			System.out.println("\t destroying GLContext ...!!!");
			gljDestroy();

			System.out.println("GL4Java: JAWT Surface-Change !!!");
			System.out.println("\t creating GLContext ...!!!");

			/* try to establish a context to OpenGL */
			try 
			{
			    System.out.println("GL4Java: JAWT Surface-Change !!!");
			    gljInit();
			    System.out.println("GL4Java: JAWT Surface-Change finished !!!");
			}
			catch( GL4JavaInitException e ) 
			{
			    System.out.println( "\tcan't create a GL context\n");
			    System.out.println("GL4Java: JAWT Surface Change FAILED!!!");
			}
			System.out.println("\t GLContext Recreated ...!!!");
		}
	}

	notifyAll(); // notify gljFree after action is done ..

        // Workaround for problem on Windows where extensions do not
        // become visible until the first time an OpenGL context is
        // made current (at least with NVidia's drivers).
        if (firstContextMakeCurrent) {
          firstContextMakeCurrent = false;
          gljFetchGLFunctions0(null, null, false, true);
        }

	return result;
    }


   /**
    *
    * gljMakeCurrent checks whether GL4Java is initializes 
    * AND makes the GL-Context current for this thread.
    *
    * It's more save to use �gljMakeCurrent�, instead of
    * �gljMakeCurrentNative�, because we do check if GL is initalised !
    *
    * @param	freeContextFirst is obsolete !
    *
    * @return 		boolean
    *
    * @deprecated The argument freeContextFirst is obsolete !
    */ 
    public final boolean gljMakeCurrent(boolean freeContextFirst)
    {
        return gljMakeCurrent();
    }

    /**
     * if using JAWT, this function handles the JAWT lock also
     */
    private final static native boolean gljMakeCurrentNative(
    						Component canvas,
    						long disp, 
    					        long thisWin,
					        long glContext);

    private final static native boolean lockJAWT(
    						Component canvas,
    					        long thisWin, boolean verbose);

   /**
    *
    * gljGetCurrentContext fetches the current native
    * GL-Context, which is attached to this _native_ thread !
    *
    * @return 		int
    */ 
    public final static native long gljGetCurrentContext();

    /**
     *
     * gljDestroy destroy�s the GL Context
     *
     * This function should be called when removing 
     * a GLContext !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
     *
     * Call gljFree befor this method, to be sure ..
     *
     * @return 		void
     *
     * @see gl4java.GLContext#gljMakeCurrent
     * @see gl4java.GLContext#gljFree
     * @see gl4java.GLContext#gljSwap
     */ 
     public synchronized final boolean gljDestroy()
     {
    	if ( ! isInitialized ) return false;

        boolean result = true;

        if (!gljDestroyNative(_comp)) 
		result = false;

        windowHandle = 0;
        glContext = 0;
	pixmapHandle = 0;


	if ( useMSJDirect )
	{
		destroyWindow = false;
		gl4java.system.GljMSJDirect.destroyOGLWindowNative( pData );
		windowHandle = 0;
		gl4java.system.GljMSJDirect.OGLWindowMsgPump();
	}

        pData = 0;
        isInitialized = false;
	glContextNumber--;

	if(gljClassDebug)
	  System.out.println("GLContext destroyed (remaining ctx="+
	  	glContextNumber+")");
        return result;
    }

     private final native boolean gljDestroyNative(Component canvas);

    /**
     *
     * gljFree free�s the GL Context
     *
     * This MUST be called at last in your display function !
     *
     * <p>
     *
     * This functions now optimizes the context-switch !
     *
     * The context is changed, only if :
     * <pre>
    	- another thread has requested this context -> release it
     * </pre>
     *
     * <p>
     *
     * @return 		boolean
     *
     * @see gl4java.GLContext#gljFree
     * @see gl4java.GLContext#gljIsCurrent
     * @see gl4java.GLContext#gljIsRequested
     * @see gl4java.GLContext#gljMakeCurrent
     * @see gl4java.GLContext#gljSwap
     * @see gl4java.awt.GLCanvas#display
     * @see gl4java.awt.GLCanvas#sDisplay
     */ 
    public final boolean gljFree()
    {
	return gljFree(false);
    }

    /**
     *
     * gljFree free�s the GL Context
     *
     * This MUST be called at last in your display function !
     *
     * <p>
     *
     * This functions now optimizes the context-switch !
     *
     * The context is changed, only if one of the following is true:
     * <pre>
    	- another thread has requested this context
	- the force flag is true
	- this thread is the AWT thread
	- the component of this context does _not_ implement GLRunnable
	- the calling thread is not the thread, this GLRunnable component holds !
     * </pre>
     * 
     * <p>
     *
     * @return 		boolean
     *
     * @see gl4java.GLContext#gljIsCurrent
     * @see gl4java.GLContext#gljIsRequested
     * @see gl4java.GLContext#gljMakeCurrent
     * @see gl4java.GLContext#gljSwap
     * @see gl4java.GLRunnable#run
     */ 
    public synchronized final boolean gljFree(boolean force)
    {
    	if ( ! isInitialized ) return false;

	boolean result = true;
	Thread thisThread = Thread.currentThread();

	if ( ctxThread!=thisThread )
	{
	     if(gljThreadDebug)
	     {
	         System.out.println("gljFree: denied, not holding context ! ");
	         System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	         Exception e = new Exception();
	         e.printStackTrace();
	     }
	     return true;
	}

        if( (_comp instanceof GLRunnable) == false ||
	    ((GLRunnable)_comp).ownsThread(thisThread) == false
	  )
		force=true;

	/**
	 * only free the context, if another thread does 
	 * request this context ...
	 * or the force-flag is true
	 */
        if ( force==true || ( nextThread!=null && nextThread!=thisThread ) )
	{
        	result = gljFreeNative ( _comp, displayHandle,
		                         windowHandle,
		                         glContext);

		ctxThread = null ;

	        if(gljThreadDebug)
		{
		     System.out.println("gljFree: gljFreeNative result: "+result);
	     	     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	        }
	} else {
    		result = unlockJAWT(windowHandle, false);
		if(gljThreadDebug)
		{
	     	     System.out.println("gljFree: no CTX change, no requests, unlockJAWT: "+result);
	     	     System.out.println("\tctxstate thisThread="+thisThread+", ctxThread="+ctxThread+", nextThread="+nextThread+", thisContext="+glContext+", currentContext="+gljGetCurrentContext());
	        }
	}
	notifyAll();

	return result;
    }

    /**
     * if using JAWT, this function handles the JAWT unlock also
     */
    private final static native boolean gljFreeNative( Component canvas,
     							long disp, 
    					                long thisWin,
					                long glContext );

    private final static native boolean unlockJAWT(long thisWin, boolean verbose);

    /**
     * swap method are for double buffering
     */
    public final boolean gljSwap()
    {
    	if ( ! isInitialized || !glEnabled ) return false;

        return gljSwapNative( displayHandle,
			      windowHandle,
			      glContext,
			      glCaps.getDoubleBuffered());
    }

    private final static native boolean gljSwapNative( long disp, 
    					              long thisWin,
					              long glContext,
						      boolean doubleBuffer );

    /**
     * This function enables, disables the GL-Context !
     * If false is given, the openGL renderer/context is 
     * disabled and disconected (gljFree is called, if initialized) !
     *
     * If disabled, all GL Functions are disabled but the 
     * Destroy & Free are not !
     *
     * @return 	boolean
     *
     * @see     gl4java.GLContext#gljMakeCurrent
     * @see     gl4java.GLContext#gljDestroy
     * @see     gl4java.GLContext#gljFree
     */ 
    public void setEnabled(boolean b)
    {
        glEnabled = b;
    	if ( b==false && isInitialized ) 
		gljFree();
    }

    /**
     * This function queries, if the GL-Context is enabled !
     *
     * @return 	boolean
     *
     * @see	gl4java.GLContext#setEnabled
     * @see     gl4java.GLContext#gljMakeCurrent
     */ 
    public boolean isEnabled()
    {
        return glEnabled;
    }

    /**
     * This functions fetches/dispatches the GL/GLU functions,
     * which must be allready loaded via the doLoadNativeLibraries
     * function !
     *
     * @see	gl4java.GLContext#doLoadNativeLibraries
     */
    public final static native boolean gljFetchOSGLFunctions 
			( String gllibname, String glulibname, boolean force );
    public final static boolean gljFetchGLFunctions(String gllibname,
                                                    String glulibname,
                                                    boolean force) {
      return gljFetchGLFunctions0(gllibname, glulibname, force, false);
    }

    // This routine is used internally only. On Windows it appears
    // that extensions only become visible once an OpenGL context is
    // made current for the first time (at least with NVidia's
    // drivers). To avoid making drastic changes to the code
    // structure, we reload all of the OpenGL functions the first time
    // a context is made current. (This could be made more efficient
    // by only loading extensions' routines at this time.)
    private volatile static boolean firstContextMakeCurrent = true;
    private final static native boolean gljFetchGLFunctions0(String gllibname,
                                                             String glulibname,
                                                             boolean force,
                                                             boolean reload);

    /**
     * This functions checks the existence of 
     * the GL functions !
     */
    public final static boolean gljTestGLProc ( String name, boolean verbose ) {
      // Special case any routines which are exposed in a different fashion
      if (name.equals("glAllocateMemoryNV")) {
        int os = getNativeOSType();
        if (os == OsWindoof) {
          name = "wglAllocateMemoryNV";
        } else if (os == OsX11) {
          name = "glXAllocateMemoryNV";
        } // else will fail anyway; fall through
      }
      return gljTestGLProc0(name, verbose);
    }

    private static final native boolean gljTestGLProc0(String name, boolean verbose);

    /**
     * This functions reads the pixel from the GL frame
     * and puts it into the pixelDest array,
     * while converting them correctly to the AWT pixel format,
     * using GL_BGRA and BufferedImage.TYPE_INT_ARGB !
     */
    public final static native void gljReadPixelGL2AWT (
    			int pack_rowlen,
    			int pack_x, int pack_y,
			int x, int y, int width, int height,
			int format, int type, int bufferName,
			int[] pixelDest);

    /**
     * This functions reads the pixel from the GL frame
     * and puts it into the pixelDest array,
     * while converting them correctly to the AWT pixel format,
     * using GL_RGB and BufferedImage.TYPE_USHORT_565_RGB !
     */
    public final static native void gljReadPixelGL2AWT (
    			int pack_rowlen,
    			int pack_x, int pack_y,
			int x, int y, int width, int height,
			int format, int type, int bufferName,
			short[] pixelDest);

    /**
     * This functions reads the pixel from the GL frame
     * and puts it into the pixelDest array,
     * while using hardware correct AWT and GL pixel format,
     * using GL_BGR and BufferedImage.TYPE_3BYTE_BGR !
     */
    public final static native void gljReadPixelGL2AWT (
    			int pack_rowlen,
    			int pack_x, int pack_y,
			int x, int y, int width, int height,
			int format, int type, int bufferName,
			byte[] pixelGLDest);

    /**
     * native C function to achieve the native lib vendor !
     *
     * now it is possible to check the native-lib at runtime !
     */
    public final static String gljGetNativeLibVendor()
    {
        return gljGetNativeLibVendorNative();
    }

    private final static native String gljGetNativeLibVendorNative();

    /**
     * native C function to achieve the native lib version !
     *
     * now it is possible to check the native-lib at runtime !
     */
    public final static String gljGetNativeLibVersion()
    {
        return gljGetNativeLibVersionNative();
    }

    private final static native String gljGetNativeLibVersionNative();

    /**
     * function to achieve the java-class version !
     *
     * now it is possible to check the java-class at runtime !
     */
    public final static String gljGetClassVersion()
    { return version; }

    /**
     * function to achieve the java-class vendor !
     *
     * now it is possible to check the java-class at runtime !
     */
    public final static String gljGetClassVendor()
    { return "Jausoft - Sven Goethel Software Development"; }

    /**
     * function to achieve complete version info
     *
     * Be sure that the native library must be loaded !
     */
    public final String gljGetVersions()
    {
	return gljGetVersions(false);
    }

    public final String gljGetVersions(boolean verbose)
    {
      if(libsLoaded==false || gl==null || glu==null || !gljIsInit())
      	return null;

      String jvmstr = "Java Virtual Machine: Version "+ getJVMVersion() +
                     " ("+getJVMVersionMajor()+"."+getJVMVersionMinor()+")"+
		     ", Vendor: "+ getJVMVendor() + "\n" ;

      gl4java.utils.glf.GLF glf = new gl4java.utils.glf.GLF();

      String info1= "GL4Java - LGPL-Version"                       + "\n" +
      	            "-------------------------------------------------\n" +
      	            "-------------------------------------------------\n" +
		    "Java-Class         : GL4Java.GLContext           \n" +
		    "          : Version: "+gljGetClassVersion()   + "\n" +
		    "            Vendor : "+gljGetClassVendor()    + "\n" +
		    "Native-Library     : GL4Java.GLContext           \n" +
		    "            Version: "+gljGetNativeLibVersion()+"\n" +
		    "            Vendor : "+gljGetNativeLibVendor() +"\n" +
      	            "-------------------------------------------------\n" +
		    "Java-Class         : GL4Java.GLFunc impl.        \n" +
		    "          : Version: "+gl.getClassVersion()   + "\n" +
		    "            Vendor : "+gl.getClassVendor()    + "\n" +
		    "Native-Library     : GL4Java.GLFunc impl.        \n" +
		    "            Version: "+gl.getNativeVersion()  + "\n" +
		    "            Vendor : "+gl.getNativeVendor()   + "\n" +
      	            "-------------------------------------------------\n" +
		    "Java-Class         : GL4Java.GLUFunc impl.       \n" +
		    "          : Version: "+glu.getClassVersion()  + "\n" +
		    "            Vendor : "+glu.getClassVendor()   + "\n" +
		    "Native-Library     : GL4Java.GLUFunc impl.       \n" +
		    "            Version: "+glu.getNativeVersion() + "\n" +
		    "            Vendor : "+glu.getNativeVendor()  + "\n" +
      	            "-------------------------------------------------\n" +
		    "Java-Class         : GL4Java.utils.glf.GLFFuncJNI  \n" +
		    "          : Version: "+glf.getClassVersion()  + "\n" +
		    "            Vendor : "+glf.getClassVendor()   + "\n" +
		    "Native-Library     : GL4Javautils.glf..GLFFuncJNI  \n" +
		    "            Version: "+glf.getNativeVersion() + "\n" +
		    "            Vendor : "+glf.getNativeVendor()  + "\n" +
      	            "-------------------------------------------------\n" +
		    "\n"+
		    jvmstr +
		    "\n" ;

        String glVen = gl.glGetString(GLFunc.GL_VENDOR);
	String glRen = gl.glGetString(GLFunc.GL_RENDERER);
	String glVer = gl.glGetString(GLFunc.GL_VERSION);
	String glExt = gl.glGetString(GLFunc.GL_EXTENSIONS);
	String gluVer = glu.gluGetString(GLUFunc.GLU_VERSION);
	String gluExt = glu.gluGetString(GLUFunc.GLU_EXTENSIONS);

     String info2=      "OpenGL - Versions                              \n" +
      	                "-----------------------------------------------\n" +
	                "GL  VENDOR: "+glVen+"\n"+
			"GL  RENDERER: "+glRen+"\n"+
			"GL  VERSION: "+glVer+"\n"+
			"GL  EXTENSIONS: "+glExt+"\n"+
			"GLU VERSION: "+gluVer+"\n"+
			"GLU EXTENSIONS: "+gluExt+"\n"+"\n" ;
	
     String info3=      "OpenGL - Function Test ("+ 
     			GLFunc.GL_PROC_NAMES.length +" Functions)       \n" +
      	                "-----------------------------------------------\n";

     if(verbose)
     {
	 System.out.println(info1);
	 System.out.println(info2);
	 System.out.println(info3);
     }
	 
     String h;	
     String tmp;
     int okNum=0;

     for(int i=0; i<GLFunc.GL_PROC_NAMES.length; i++)
     {
        h=GLFunc.GL_PROC_NAMES[i];
	if(h==null) break;

     	if(gljTestGLProc (h, verbose))
	{
		tmp= "#"+i+" OK   : "+h+"\n";
		okNum++;
	} else 
		tmp= "#"+i+" NOPE : "+h+"\n";
	    
	info3 += tmp;
     }
     info3 += "-----------------------------------------------\n";
     info3 += "Got "+okNum+" / "+GLFunc.GL_PROC_NAMES.length+" Functions \n";
     info3 += "===============================================\n";

     return info1+"\n"+info2+"\n"+info3;
    }

    /**
     * function to show complete version info into an extra Frame
     *
     * Be sure that the native library must be loaded !
     */
    public final Frame gljShowVersions()
    {
	Frame f = new Frame("GL4Java Version");
	TextArea info= new TextArea(25, 80);
	info.setEditable(false);
	f.add(info);
	f.setSize(600, 400);

	f.pack();
	f.setVisible(true);

	String str = "null string";
	if( gljMakeCurrent(true) == false ) 
	{
		str="problem in use() method\n";
	} else {
		str=gljGetVersions(gljNativeDebug);
		if(str==null)
			str="could not get versions";
		System.out.println(str);
		gljFree();
	}
	info.append(str);

	f.addWindowListener
			   ( new WindowAdapter()
			      {
				public void windowClosing(WindowEvent e)
				{
				   // button window menu ... :-)
				   e.getWindow().dispose();
				}
			      }
			    );              

	return f;
    }

}