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
|
/* Last saved: Tue 02 Apr 2013 02:45:10 PM */
/* Copyright (c) 1998 Kenneth Albanowski. All rights reserved.
* Copyright (c) 2007 Bob Free. All rights reserved.
* Copyright (c) 2009 Chris Marshall. All rights reserved.
* Copyright (c) 2015 Bob Free. All rights reserved.
* This program is free software; you can redistribute it and/or
* modify it under the same terms as Perl itself.
*/
#include <stdio.h>
#include "pgopogl.h"
/* glut_util.h is where you include the appropriate GLUT header
* file based on what is available. It also defines some constants
* that may not be defined everywhere. Replace this by user
* specified include information for the include and compile-time
* perl constants rather than some special cases
*/
#include "glut_util.h"
/* TODO: calculate this from the actual GLUT include file */
#ifndef GLUT_API_VERSION
#define GLUT_API_VERSION 4
#endif
static int _done_glutInit = 0;
static int _done_glutCloseFunc_warn = 0;
/* Macros for GLUT callback and handler declarations */
# define DO_perl_call_sv(handler, flag) perl_call_sv(handler, flag)
# define ENSURE_callback_thread
# define GLUT_PUSH_NEW_SV(sv) XPUSHs(sv_2mortal(newSVsv(sv)))
# define GLUT_PUSH_NEW_IV(i) XPUSHs(sv_2mortal(newSViv(i)))
# define GLUT_PUSH_NEW_U8(c) XPUSHs(sv_2mortal(newSViv((int)c)))
# define GLUT_EXTEND_STACK(sp,n)
# define GLUT_PUSHMARK(sp) PUSHMARK(sp)
/* Set up for all the GLUT callback handlers */
static AV * glut_handlers = 0;
/* Attach a handler to a window */
static void set_glut_win_handler(int win, int type, SV * data)
{
SV ** h;
AV * a;
if (!glut_handlers)
glut_handlers = newAV();
h = av_fetch(glut_handlers, win, FALSE);
if (!h) {
a = newAV();
av_store(glut_handlers, win, newRV_inc((SV*)a));
SvREFCNT_dec(a);
} else if (!SvOK(*h) || !SvROK(*h))
croak("Unable to establish glut handler");
else
a = (AV*)SvRV(*h);
av_store(a, type, newRV_inc(data));
SvREFCNT_dec(data);
}
/* Get a window's handler */
static SV * get_glut_win_handler(int win, int type)
{
SV ** h;
if (!glut_handlers)
croak("Unable to locate glut handler");
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Unable to locate glut handler");
h = av_fetch((AV*)SvRV(*h), type, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Unable to locate glut handler");
return SvRV(*h);
}
/* Release a window's handlers */
static void destroy_glut_win_handlers(int win)
{
SV ** h;
if (!glut_handlers)
return;
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
return;
av_store(glut_handlers, win, newSVsv(&PL_sv_undef));
}
/* Release a handler */
static void destroy_glut_win_handler(int win, int type)
{
SV ** h;
AV * a;
if (!glut_handlers)
glut_handlers = newAV();
h = av_fetch(glut_handlers, win, FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
return;
a = (AV*)SvRV(*h);
av_store(a, type, newSVsv(&PL_sv_undef));
}
/* Begin window callback definition */
#define begin_decl_gwh(type, params, nparam) \
\
static void generic_glut_ ## type ## _handler params \
{ \
int win = glutGetWindow(); \
AV * handler_data = (AV*)get_glut_win_handler(win, HANDLE_GLUT_ ## type);\
SV * handler; \
int i; \
dSP; \
\
handler = *av_fetch(handler_data, 0, 0); \
\
GLUT_PUSHMARK(sp); \
GLUT_EXTEND_STACK(sp,av_len(handler_data)+nparam); \
for (i=1;i<=av_len(handler_data);i++) \
GLUT_PUSH_NEW_SV(*av_fetch(handler_data, i, 0));
/* End window callback definition */
#define end_decl_gwh() \
PUTBACK; \
DO_perl_call_sv(handler, G_DISCARD); \
}
/* Activate a window callback handler */
#define decl_gwh_xs(type) \
{ \
int win = glutGetWindow(); \
\
if (!handler || !SvOK(handler)) { \
destroy_glut_win_handler(win, HANDLE_GLUT_ ## type);\
glut ## type ## Func(NULL); \
} else { \
AV * handler_data = newAV(); \
\
PackCallbackST(handler_data, 0); \
\
set_glut_win_handler(win, HANDLE_GLUT_ ## type, (SV*)handler_data);\
\
glut ## type ## Func(generic_glut_ ## type ## _handler);\
} \
ENSURE_callback_thread;}
/* Activate a window callback handler; die on failure */
#define decl_gwh_xs_nullfail(type, fail) \
{ \
int win = glutGetWindow(); \
\
if (!handler || !SvOK(handler)) { \
croak fail; \
} else { \
AV * handler_data = newAV(); \
\
PackCallbackST(handler_data, 0); \
\
set_glut_win_handler(win, HANDLE_GLUT_ ## type, (SV*)handler_data);\
\
glut ## type ## Func(generic_glut_ ## type ## _handler);\
} \
ENSURE_callback_thread;}
/* Activate a global state callback handler */
#define decl_ggh_xs(type) \
{ \
if (glut_ ## type ## _handler_data) \
SvREFCNT_dec(glut_ ## type ## _handler_data); \
\
if (!handler || !SvOK(handler)) { \
glut_ ## type ## _handler_data = 0; \
glut ## type ## Func(NULL); \
} else { \
AV * handler_data = newAV(); \
\
PackCallbackST(handler_data, 0); \
\
glut_ ## type ## _handler_data = handler_data; \
\
glut ## type ## Func(generic_glut_ ## type ## _handler);\
} \
ENSURE_callback_thread;}
/* Begin a global state callback definition */
#define begin_decl_ggh(type, params, nparam) \
\
static AV * glut_ ## type ## _handler_data = 0; \
\
static void generic_glut_ ## type ## _handler params \
{ \
AV * handler_data = glut_ ## type ## _handler_data; \
SV * handler; \
int i; \
dSP; \
\
handler = *av_fetch(handler_data, 0, 0); \
\
GLUT_PUSHMARK(sp); \
GLUT_EXTEND_STACK(sp,av_len(handler_data)+nparam); \
for (i=1;i<=av_len(handler_data);i++) \
GLUT_PUSH_NEW_SV(*av_fetch(handler_data, i, 0));
/* End a global state callback definition */
#define end_decl_ggh() \
PUTBACK; \
DO_perl_call_sv(handler, G_DISCARD); \
}
/* Define callbacks */
enum {
HANDLE_GLUT_Display,
HANDLE_GLUT_OverlayDisplay,
HANDLE_GLUT_Reshape,
HANDLE_GLUT_Keyboard,
HANDLE_GLUT_KeyboardUp,
HANDLE_GLUT_Mouse,
HANDLE_GLUT_MouseWheel, /* Open/FreeGLUT -chm */
HANDLE_GLUT_Motion,
HANDLE_GLUT_PassiveMotion,
HANDLE_GLUT_Entry,
HANDLE_GLUT_Visibility,
HANDLE_GLUT_WindowStatus,
HANDLE_GLUT_Special,
HANDLE_GLUT_SpecialUp,
HANDLE_GLUT_Joystick, /* Open/FreeGLUT -chm */
HANDLE_GLUT_SpaceballMotion,
HANDLE_GLUT_SpaceballRotate,
HANDLE_GLUT_SpaceballButton,
HANDLE_GLUT_ButtonBox,
HANDLE_GLUT_Dials,
HANDLE_GLUT_TabletMotion,
HANDLE_GLUT_TabletButton,
HANDLE_GLUT_MenuDestroy, /* Open/FreeGLUT -chm */
HANDLE_GLUT_Close, /* Open/FreeGLUT -chm */
HANDLE_GLUT_WMClose, /* AGL GLUT -chm */
};
/* Callback for glutDisplayFunc */
begin_decl_gwh(Display, (void), 0)
end_decl_gwh()
/* Callback for glutOverlayDisplayFunc */
begin_decl_gwh(OverlayDisplay, (void), 0)
end_decl_gwh()
/* Callback for glutReshapeFunc */
begin_decl_gwh(Reshape, (int width, int height), 2)
GLUT_PUSH_NEW_IV(width);
GLUT_PUSH_NEW_IV(height);
end_decl_gwh()
/* Callback for glutKeyboardFunc */
begin_decl_gwh(Keyboard, (unsigned char key, int width, int height), 3)
GLUT_PUSH_NEW_U8(key);
GLUT_PUSH_NEW_IV(width);
GLUT_PUSH_NEW_IV(height);
end_decl_gwh()
/* Callback for glutKeyboardUpFunc */
begin_decl_gwh(KeyboardUp, (unsigned char key, int width, int height), 3)
GLUT_PUSH_NEW_U8(key);
GLUT_PUSH_NEW_IV(width);
GLUT_PUSH_NEW_IV(height);
end_decl_gwh()
/* Callback for glutMouseFunc */
begin_decl_gwh(Mouse, (int button, int state, int x, int y), 4)
GLUT_PUSH_NEW_IV(button);
GLUT_PUSH_NEW_IV(state);
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutMouseWheelFunc */ /* Open/FreeGLUT -chm */
begin_decl_gwh(MouseWheel, (int wheel, int direction, int x, int y), 4)
GLUT_PUSH_NEW_IV(wheel);
GLUT_PUSH_NEW_IV(direction);
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutPassiveMotionFunc */
begin_decl_gwh(PassiveMotion, (int x, int y), 2)
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutMotionFunc */
begin_decl_gwh(Motion, (int x, int y), 2)
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutVisibilityFunc */
begin_decl_gwh(Visibility, (int state), 1)
GLUT_PUSH_NEW_IV(state);
end_decl_gwh()
/* Callback for glutWindowStatusFunc */
begin_decl_gwh(WindowStatus, (int state), 1)
GLUT_PUSH_NEW_IV(state);
end_decl_gwh()
/* Callback for glutEntryFunc */
begin_decl_gwh(Entry, (int state), 1)
GLUT_PUSH_NEW_IV(state);
end_decl_gwh()
/* Callback for glutSpecialFunc */
begin_decl_gwh(Special, (int key, int width, int height), 3)
GLUT_PUSH_NEW_IV(key);
GLUT_PUSH_NEW_IV(width);
GLUT_PUSH_NEW_IV(height);
end_decl_gwh()
/* Callback for glutSpecialUpFunc */
begin_decl_gwh(SpecialUp, (int key, int width, int height), 3)
GLUT_PUSH_NEW_IV(key);
GLUT_PUSH_NEW_IV(width);
GLUT_PUSH_NEW_IV(height);
end_decl_gwh()
/* Callback for glutJoystickFunc */ /* Open/FreeGLUT -chm */
begin_decl_gwh(Joystick, (unsigned int buttons, int xaxis, int yaxis, int zaxis), 4)
GLUT_PUSH_NEW_IV(buttons);
GLUT_PUSH_NEW_IV(xaxis);
GLUT_PUSH_NEW_IV(yaxis);
GLUT_PUSH_NEW_IV(zaxis);
end_decl_gwh()
/* Callback for glutSpaceballMotionFunc */
begin_decl_gwh(SpaceballMotion, (int x, int y, int z), 3)
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
GLUT_PUSH_NEW_IV(z);
end_decl_gwh()
/* Callback for glutSpaceballRotateFunc */
begin_decl_gwh(SpaceballRotate, (int x, int y, int z), 3)
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
GLUT_PUSH_NEW_IV(z);
end_decl_gwh()
/* Callback for glutSpaceballButtonFunc */
begin_decl_gwh(SpaceballButton, (int button, int state), 2)
GLUT_PUSH_NEW_IV(button);
GLUT_PUSH_NEW_IV(state);
end_decl_gwh()
/* Callback for glutButtonBoxFunc */
begin_decl_gwh(ButtonBox, (int button, int state), 2)
GLUT_PUSH_NEW_IV(button);
GLUT_PUSH_NEW_IV(state);
end_decl_gwh()
/* Callback for glutDialsFunc */
begin_decl_gwh(Dials, (int dial, int value), 2)
GLUT_PUSH_NEW_IV(dial);
GLUT_PUSH_NEW_IV(value);
end_decl_gwh()
/* Callback for glutTabletMotionFunc */
begin_decl_gwh(TabletMotion, (int x, int y), 2)
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutTabletButtonFunc */
begin_decl_gwh(TabletButton, (int button, int state, int x, int y), 4)
GLUT_PUSH_NEW_IV(button);
GLUT_PUSH_NEW_IV(state);
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_gwh()
/* Callback for glutIdleFunc */
begin_decl_ggh(Idle, (void), 0)
end_decl_ggh()
/* Callback for glutMenuStatusFunc */
begin_decl_ggh(MenuStatus, (int status, int x, int y), 3)
GLUT_PUSH_NEW_IV(status);
GLUT_PUSH_NEW_IV(x);
GLUT_PUSH_NEW_IV(y);
end_decl_ggh()
/* Callback for glutMenuStateFunc */
begin_decl_ggh(MenuState, (int status), 1)
GLUT_PUSH_NEW_IV(status);
end_decl_ggh()
/* Callback for glutMenuDestroyFunc */ /* Open/FreeGLUT -chm */
begin_decl_gwh(MenuDestroy, (void), 0)
end_decl_gwh()
/* Callback for glutCloseFunc */
#ifdef HAVE_AGL_GLUT
static void generic_glut_WMClose_handler(void)
#else
static void generic_glut_Close_handler(void)
#endif
{
int win = glutGetWindow();
AV * handler_data = (AV*)get_glut_win_handler(win, HANDLE_GLUT_Close);
SV * handler = *av_fetch(handler_data, 0, 0);
dSP;
GLUT_PUSHMARK(sp);
GLUT_EXTEND_STACK(sp,1);
GLUT_PUSH_NEW_IV(win);
PUTBACK;
DO_perl_call_sv(handler, G_DISCARD);
}
/* glut_timer_handlers is an allocation buffer.
All unused elements are SVivs forming a linked-list,
starting at glut_timer_handlers_next_free.
The end of the list is marked by a -1.
If no element is free when one is needed, the buffer will grow.
*/
static AV * glut_timer_handlers = 0;
static int glut_timer_handlers_next_free = -1;
/* Callback for glutTimerFunc */
static void generic_glut_timer_handler(int value)
{
if (!glut_timer_handlers)
croak("Timer handler called, but no timers have ever been set up");
SV** h = av_fetch(glut_timer_handlers,value,FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Timer handler called for unregistered timer");
AV * handler_data = (AV*)SvRV(*h);
sv_setiv(*h,glut_timer_handlers_next_free);
glut_timer_handlers_next_free = value;
SV * handler;
int i;
dSP;
handler = *av_fetch(handler_data, 0, 0);
GLUT_PUSHMARK(sp);
GLUT_EXTEND_STACK(sp,av_len(handler_data));
for (i=1;i<=av_len(handler_data);i++)
GLUT_PUSH_NEW_SV(*av_fetch(handler_data, i, 0));
PUTBACK;
DO_perl_call_sv(handler, G_DISCARD);
SvREFCNT_dec(handler_data);
}
static AV * glut_menu_handlers = 0;
/* Callback for glutMenuFunc */
static void generic_glut_menu_handler(int value)
{
AV * handler_data;
SV * handler;
SV ** h;
int i;
dSP;
h = av_fetch(glut_menu_handlers, glutGetMenu(), FALSE);
if (!h || !SvOK(*h) || !SvROK(*h))
croak("Unable to locate menu handler");
handler_data = (AV*)SvRV(*h);
handler = *av_fetch(handler_data, 0, 0);
GLUT_PUSHMARK(sp);
GLUT_EXTEND_STACK(sp,av_len(handler_data) + 1);
for (i=1;i<=av_len(handler_data);i++)
GLUT_PUSH_NEW_SV(*av_fetch(handler_data, i, 0));
GLUT_PUSH_NEW_IV(value);
PUTBACK;
DO_perl_call_sv(handler, G_DISCARD);
}
/* End of set up for GLUT callback stuff */
MODULE = OpenGL::GLUT PACKAGE = OpenGL
#// Test for done with glutInit
int
done_glutInit()
CODE:
RETVAL = _done_glutInit;
OUTPUT:
RETVAL
# GLUT
#//# glutInit();
void
glutInit()
CODE:
{
int argc;
char ** argv;
AV * ARGV;
SV * ARGV0;
SV * sv;
int i;
if (_done_glutInit)
croak("illegal glutInit() reinitialization attempt");
argv = 0;
ARGV = perl_get_av("ARGV", FALSE);
ARGV0 = perl_get_sv("0", FALSE);
argc = av_len(ARGV)+2;
if (argc) {
argv = malloc(sizeof(char*)*argc);
argv[0] = SvPV(ARGV0, PL_na);
for(i=0;i<=av_len(ARGV);i++)
argv[i+1] = SvPV(*av_fetch(ARGV, i, 0), PL_na);
}
i = argc;
glutInit(&argc, argv);
_done_glutInit = 1;
while(argc<i--)
sv = av_shift(ARGV);
if (argv)
free(argv);
}
#//# glutInitWindowSize($width, $height);
void
glutInitWindowSize(width, height)
int width
int height
#//# glutInitWindowPosition($x, $y);
void
glutInitWindowPosition(x, y)
int x
int y
#//# glutInitDisplayMode($mode);
void
glutInitDisplayMode(mode)
int mode
#//# glutInitDisplayString($string);
void
glutInitDisplayString(string)
char * string
#//# glutMainLoop();
void
glutMainLoop()
#//# glutCreateWindow($name);
int
glutCreateWindow(name)
char * name
CODE:
RETVAL = glutCreateWindow(name);
destroy_glut_win_handlers(RETVAL);
OUTPUT:
RETVAL
#//# glutCreateSubWindow($win, $x, $y, $width, $height);
int
glutCreateSubWindow(win, x, y, width, height)
int win
int x
int y
int width
int height
CODE:
RETVAL = glutCreateSubWindow(win, x, y, width, height);
destroy_glut_win_handlers(RETVAL);
OUTPUT:
RETVAL
#//# glutSetWindow($win);
void
glutSetWindow(win)
int win
#//# glutGetWindow();
int
glutGetWindow()
#//# glutDestroyWindow($win);
void
glutDestroyWindow(win)
int win
CODE:
glutDestroyWindow(win);
destroy_glut_win_handlers(win);
#//# glutPostRedisplay();
void
glutPostRedisplay()
#//# glutSwapBuffers();
void
glutSwapBuffers()
#//# glutPositionWindow($x, $y);
void
glutPositionWindow(x, y)
int x
int y
#//# glutReshapeWindow($width, $height);
void
glutReshapeWindow(width, height)
int width
int height
#if GLUT_API_VERSION >= 3
#//# glutFullScreen();
void
glutFullScreen()
#endif
#//# glutPopWindow();
void
glutPopWindow()
#//# glutPushWindow();
void
glutPushWindow()
#//# glutShowWindow();
void
glutShowWindow()
#//# glutHideWindow();
void
glutHideWindow()
#//# glutIconifyWindow();
void
glutIconifyWindow()
#//# glutSetWindowTitle($title);
void
glutSetWindowTitle(title)
char * title
#//# glutSetIconTitle($title);
void
glutSetIconTitle(title)
char * title
#if GLUT_API_VERSION >= 3
#//# glutSetCursor(cursor);
void
glutSetCursor(cursor)
int cursor
#endif
# Overlays
#if GLUT_API_VERSION >= 3
#//# glutEstablishOverlay();
void
glutEstablishOverlay()
#//# glutUseLayer(layer);
void
glutUseLayer(layer)
GLenum layer
#//# glutRemoveOverlay();
void
glutRemoveOverlay()
#//# glutPostOverlayRedisplay();
void
glutPostOverlayRedisplay()
#//# glutShowOverlay();
void
glutShowOverlay()
#//# glutHideOverlay();
void
glutHideOverlay()
#endif
# Menus
#//# $ID = glutCreateMenu(\&callback);
int
glutCreateMenu(handler=0, ...)
SV * handler
CODE:
{
if (!handler || !SvOK(handler)) {
croak("A handler must be specified");
} else {
AV * handler_data = newAV();
PackCallbackST(handler_data, 0);
RETVAL = glutCreateMenu(generic_glut_menu_handler);
if (!glut_menu_handlers)
glut_menu_handlers = newAV();
av_store(glut_menu_handlers, RETVAL, newRV_inc((SV*)handler_data));
SvREFCNT_dec(handler_data);
}
}
OUTPUT:
RETVAL
#//# glutSetMenu($menu);
void
glutSetMenu(menu)
int menu
#//# glutGetMenu();
int
glutGetMenu()
#//# glutDestroyMenu($menu);
void
glutDestroyMenu(menu)
int menu
CODE:
{
glutDestroyMenu(menu);
av_store(glut_menu_handlers, menu, newSVsv(&PL_sv_undef));
}
#//# glutAddMenuEntry($name, $value);
void
glutAddMenuEntry(name, value)
char * name
int value
#//# glutAddSubMenu($name, $menu);
void
glutAddSubMenu(name, menu)
char * name
int menu
#//# glutChangeToMenuEntry($entry, $name, $value);
void
glutChangeToMenuEntry(entry, name, value)
int entry
char * name
int value
#//# glutChangeToSubMenu($entry, $name, $menu);
void
glutChangeToSubMenu(entry, name, menu)
int entry
char * name
int menu
#//# glutRemoveMenuItem($entry);
void
glutRemoveMenuItem(entry)
int entry
#//# glutAttachMenu(button);
void
glutAttachMenu(button)
int button
#//# glutDetachMenu(button);
void
glutDetachMenu(button)
int button
# Callbacks
#//# glutDisplayFunc(\&callback);
void
glutDisplayFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs_nullfail(Display, ("Display function must be specified"))
#if GLUT_API_VERSION >= 3
#//# glutOverlayDisplayFunc(\&callback);
void
glutOverlayDisplayFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(OverlayDisplay)
#endif
#//# glutReshapeFunc(\&callback);
void
glutReshapeFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Reshape)
#//# glutKeyboardFunc(\&callback);
void
glutKeyboardFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Keyboard)
#if GLUT_API_VERSION >= 4
#//# glutKeyboardUpFunc(\&callback);
void
glutKeyboardUpFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(KeyboardUp)
#//# glutWindowStatusFunc(\&callback);
void
glutWindowStatusFunc(handler=0, ...)
SV * handler
CODE:
{
#if defined HAVE_FREEGLUT
decl_gwh_xs(WindowStatus)
#endif
}
#endif
#//# glutMouseFunc(\&callback);
void
glutMouseFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Mouse)
#//# glutMouseWheelFunc(\&callback);
void
glutMouseWheelFunc(handler=0, ...)
SV * handler
CODE:
{
#if defined HAVE_FREEGLUT
decl_gwh_xs(MouseWheel)
#endif
}
#//# glutMotionFunc(\&callback);
void
glutMotionFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Motion)
#//# glutPassiveMotionFunc(\&callback);
void
glutPassiveMotionFunc(handler=0, ...)
SV * handler
CODE:
{
#if defined HAVE_FREEGLUT
decl_gwh_xs(PassiveMotion)
#endif
}
#//# glutVisibilityFunc(\&callback);
void
glutVisibilityFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Visibility)
#//# glutEntryFunc(\&callback);
void
glutEntryFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Entry)
#if GLUT_API_VERSION >= 2
#//# glutSpecialFunc(\&callback);
void
glutSpecialFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Special)
#//# glutJoystickFunc(\&callback); /* Open/FreeGLUT -chm */
# void /* Not implemented, don't know how */
# glutJoystickFunc(handler=0, ...)
# SV * handler
# CODE:
# decl_gwh_xs(Joystick)
#//# glutSpaceballMotionFunc(\&callback);
void
glutSpaceballMotionFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(SpaceballMotion)
#//# glutSpaceballRotateFunc(\&callback);
void
glutSpaceballRotateFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(SpaceballRotate)
#//# glutSpaceballButtonFunc(\&callback);
void
glutSpaceballButtonFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(SpaceballButton)
#//# glutButtonBoxFunc(\&callback);
void
glutButtonBoxFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(ButtonBox)
#//# glutDialsFunc(\&callback);
void
glutDialsFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(Dials)
#//# glutTabletMotionFunc(\&callback);
void
glutTabletMotionFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(TabletMotion)
#//# glutTabletButtonFunc(\&callback);
void
glutTabletButtonFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(TabletButton)
#endif
#if GLUT_API_VERSION >= 3
#//# glutMenuStatusFunc(\&callback);
void
glutMenuStatusFunc(handler=0, ...)
SV * handler
CODE:
decl_ggh_xs(MenuStatus)
#endif
#//# glutMenuStateFunc(\&callback);
void
glutMenuStateFunc(handler=0, ...)
SV * handler
CODE:
{
#if defined HAVE_FREEGLUT
decl_ggh_xs(MenuState)
#endif
}
#//# glutIdleFunc(\&callback);
void
glutIdleFunc(handler=0, ...)
SV * handler
CODE:
decl_ggh_xs(Idle)
#//# glutTimerFunc($msecs, \&callback);
void
glutTimerFunc(msecs, handler=0, ...)
unsigned int msecs
SV * handler
CODE:
{
if (!handler || !SvOK(handler)) {
croak("A handler must be specified");
} else {
AV * handler_data = newAV();
PackCallbackST(handler_data, 1);
SV * handler_data_sv = newRV_inc((SV*)handler_data);
if (!glut_timer_handlers)
glut_timer_handlers = newAV();
int handler_id = glut_timer_handlers_next_free;
if (handler_id == -1) {
handler_id = ((int) av_top_index(glut_timer_handlers))+1;
if (handler_id < 0)
croak("Limit of concurrent timers reached (MAX_INT)");
av_push(glut_timer_handlers, handler_data_sv);
} else {
SV** entry = av_fetch(glut_timer_handlers,handler_id,FALSE);
glut_timer_handlers_next_free = SvIV(*entry);
sv_setsv(*entry,sv_2mortal(handler_data_sv));
}
glutTimerFunc(msecs, generic_glut_timer_handler, handler_id);
}
ENSURE_callback_thread;}
# Colors
#//# glutSetColor($cell, $red, $green, $blue)
void
glutSetColor(cell, red, green, blue)
int cell
GLfloat red
GLfloat green
GLfloat blue
#//# glutGetColor($cell, $component);
GLfloat
glutGetColor(cell, component)
int cell
int component
#//# glutCopyColormap($win);
void
glutCopyColormap(win)
int win
# State
#//# glutGet($state);
int
glutGet(state)
GLenum state
#if GLUT_API_VERSION >= 3
#//# glutLayerGet(info);
int
glutLayerGet(info)
GLenum info
#endif
int
glutDeviceGet(info)
GLenum info
#if GLUT_API_VERSION >= 3
#//# glutGetModifiers();
int
glutGetModifiers()
#endif
#if GLUT_API_VERSION >= 2
#//# glutExtensionSupported($extension);
int
glutExtensionSupported(extension)
char * extension
#endif
# Font
#//# glutBitmapCharacter($font, $character);
void
glutBitmapCharacter(font, character)
void * font
int character
#//# glutStrokeCharacter($font, $character);
void
glutStrokeCharacter(font, character)
void * font
int character
#//# glutBitmapWidth($font, $character);
int
glutBitmapWidth(font, character)
void * font
int character
#//# glutStrokeWidth($font, $character);
int
glutStrokeWidth(font, character)
void * font
int character
#if GLUT_API_VERSION >= 3
#//# glutIgnoreKeyRepeat($ignore);
void
glutIgnoreKeyRepeat(ignore)
int ignore
#//# glutSetKeyRepeat($repeatMode);
void
glutSetKeyRepeat(repeatMode)
int repeatMode
#//# glutForceJoystickFunc();
void
glutForceJoystickFunc()
#endif
# Solids
#//# glutSolidSphere($radius, $slices, $stacks);
void
glutSolidSphere(radius, slices, stacks)
GLdouble radius
GLint slices
GLint stacks
#//# glutWireSphere($radius, $slices, $stacks);
void
glutWireSphere(radius, slices, stacks)
GLdouble radius
GLint slices
GLint stacks
#//# glutSolidCube($size);
void
glutSolidCube(size)
GLdouble size
#//# glutWireCube($size);
void
glutWireCube(size)
GLdouble size
#//# glutSolidCone($base, $height, $slices, $stacks);
void
glutSolidCone(base, height, slices, stacks)
GLdouble base
GLdouble height
GLint slices
GLint stacks
#//# glutWireCone($base, $height, $slices, $stacks);
void
glutWireCone(base, height, slices, stacks)
GLdouble base
GLdouble height
GLint slices
GLint stacks
#//# glutSolidTorus($innerRadius, $outerRadius, $nsides, $rings);
void
glutSolidTorus(innerRadius, outerRadius, nsides, rings)
GLdouble innerRadius
GLdouble outerRadius
GLint nsides
GLint rings
#//# glutWireTorus($innerRadius, $outerRadius, $nsides, $rings);
void
glutWireTorus(innerRadius, outerRadius, nsides, rings)
GLdouble innerRadius
GLdouble outerRadius
GLint nsides
GLint rings
#//# glutSolidDodecahedron();
void
glutSolidDodecahedron()
#//# glutWireDodecahedron();
void
glutWireDodecahedron()
#//# glutSolidOctahedron();
void
glutSolidOctahedron()
#//# glutWireOctahedron();
void
glutWireOctahedron()
#//# glutSolidTetrahedron();
void
glutSolidTetrahedron()
#//# glutWireTetrahedron();
void
glutWireTetrahedron()
#//# glutSolidIcosahedron();
void
glutSolidIcosahedron()
#//# glutWireIcosahedron();
void
glutWireIcosahedron()
#//# glutSolidTeapot(size);
void
glutSolidTeapot(size)
GLdouble size
#//# glutWireTeapot($size);
void
glutWireTeapot(size)
GLdouble size
#if GLUT_API_VERSION >= 4
#//# glutSpecialUpFunc(\&callback);
void
glutSpecialUpFunc(handler=0, ...)
SV * handler
CODE:
decl_gwh_xs(SpecialUp)
#//# glutGameModeString($string);
GLboolean
glutGameModeString(string)
char * string
CODE:
{
char mode[1024];
if (!string || !string[0])
{
int w = glutGet(0x00C8); // GLUT_SCREEN_WIDTH
int h = glutGet(0x00C9); // GLUT_SCREEN_HEIGHT
sprintf(mode,"%dx%d:%d@%d",w,h,32,60);
string = mode;
}
glutGameModeString(string);
RETVAL = glutGameModeGet(0x0001); // GLUT_GAME_MODE_POSSIBLE
}
OUTPUT:
RETVAL
#//# glutEnterGameMode();
int
glutEnterGameMode()
#//# glutLeaveGameMode();
void
glutLeaveGameMode()
#//# glutGameModeGet($mode);
int
glutGameModeGet(mode)
GLenum mode
#//# FreeGLUT/OpenGLUT feature
#//# int glutBitmapHeight (void *font)
int
glutBitmapHeight(font)
void * font
CODE:
{
#if defined HAVE_FREEGLUT
RETVAL = glutBitmapHeight(font);
#endif
}
OUTPUT:
RETVAL
#//# FreeGLUT/OpenGLUT feature
#//# int glutBitmapLength (void *font, const unsigned char *string)
int
glutBitmapLength(font, string)
void * font
const unsigned char * string
CODE:
{
#if defined HAVE_FREEGLUT
RETVAL = glutBitmapLength(font, string);
#endif
}
OUTPUT:
RETVAL
#//# FreeGLUT/OpenGLUT feature
#//# void glutBitmapString (void *font, const unsigned char *string)
void
glutBitmapString(font, string)
void * font
const unsigned char * string
CODE:
{
#if defined HAVE_FREEGLUT
glutBitmapString(font, string);
#else
int len, i;
len = (int) strlen((char *)string);
for (i = 0; i < len; i++) {
glutBitmapCharacter(font, string[i]);
}
#endif
}
#//# FreeGLUT/OpenGLUT feature
#//# void * glutGetProcAddress (const char *procName)
# void *
# glutGetProcAddress(procName)
# const char * procName
#//# FreeGLUT/OpenGLUT feature
#//# void glutMainLoopEvent (void)
void
glutMainLoopEvent()
CODE:
{
#if defined HAVE_AGL_GLUT
glutCheckLoop();
#elif defined HAVE_FREEGLUT
glutMainLoopEvent();
#endif
}
#//# void glutPostWindowOverlayRedisplay (int windowID)
void
glutPostWindowOverlayRedisplay(windowID)
int windowID
#//# void glutPostWindowRedisplay (int windowID)
void
glutPostWindowRedisplay(windowID)
int windowID
#//# void glutReportErrors (void)
void
glutReportErrors()
#//# void glutSolidCylinder (GLdouble radius, GLdouble height, GLint slices, GLint stacks)
void
glutSolidCylinder(radius, height, slices, stacks)
GLdouble radius
GLdouble height
GLint slices
GLint stacks
CODE:
{
#if defined HAVE_FREEGLUT
glutSolidCylinder(radius, height, slices, stacks);
#endif
}
#//# void glutSolidRhombicDodecahedron (void)
void
glutSolidRhombicDodecahedron()
CODE:
{
#if defined HAVE_FREEGLUT
glutSolidRhombicDodecahedron();
#endif
}
#//# float glutStrokeHeight (void *font)
GLfloat
glutStrokeHeight(font)
void * font
CODE:
{
#if defined HAVE_FREEGLUT
RETVAL = glutStrokeHeight(font);
#endif
}
OUTPUT:
RETVAL
#//# float glutStrokeLength (void *font, const unsigned char *string)
GLfloat
glutStrokeLength(font, string)
void * font
const unsigned char * string
CODE:
{
#if defined HAVE_FREEGLUT
glutStrokeLength(font, string);
#endif
}
OUTPUT:
RETVAL
#//# void glutStrokeString (void *fontID, const unsigned char *string)
void
glutStrokeString(font, string)
void * font
const unsigned char * string
CODE:
{
#if defined HAVE_FREEGLUT
glutStrokeString(font, string);
#endif
}
#//# void glutWarpPointer (int x, int y)
void
glutWarpPointer(x, y)
int x
int y
#//# void glutWireCylinder (GLdouble radius, GLdouble height, GLint slices, GLint stacks)
void
glutWireCylinder(radius, height, slices, stacks)
GLdouble radius
GLdouble height
GLint slices
GLint stacks
CODE:
{
#if defined HAVE_FREEGLUT
glutWireCylinder(radius, height, slices, stacks);
#endif
}
#//# void glutWireRhombicDodecahedron (void)
void
glutWireRhombicDodecahedron()
CODE:
{
#if defined HAVE_FREEGLUT
glutWireRhombicDodecahedron();
#endif
}
#endif
# /* FreeGLUT APIs */
#//# glutSetOption($option_flag, $value);
void
glutSetOption(option_flag, value)
GLenum option_flag
int value
CODE:
{
#if defined HAVE_FREEGLUT
glutSetOption(option_flag, value);
#endif
}
#//# glutLeaveMainLoop();
void
glutLeaveMainLoop()
CODE:
{
#if defined HAVE_FREEGLUT
glutLeaveMainLoop();
#else
int win = glutGetWindow();
glutDestroyWindow(win);
destroy_glut_win_handlers(win);
#endif
}
#//# glutMenuDestroyFunc(\&callback);
void
glutMenuDestroyFunc(handler=0, ...)
SV * handler
CODE:
{
#if defined HAVE_FREEGLUT
decl_gwh_xs(MenuDestroy)
#endif
}
#//# glutCloseFunc(\&callback);
void
glutCloseFunc(handler=0, ...)
SV * handler
CODE:
{
if (_done_glutCloseFunc_warn == 0) {
warn("glutCloseFunc: not implemented\n");
_done_glutCloseFunc_warn++;
}
}
|