Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 582a917773
Fetching contributors…

Cannot retrieve contributors at this time

file 1065 lines (869 sloc) 26.288 kb
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
// The glut package provides a platform-independent window system for OpenGL, through the system's native GLUT or freeglut library.
// It also provides convenience functions for drawing teapots.

package glut

import (
"os"
"runtime"
"unsafe"

"github.com/banthar/gl"
)

// #cgo darwin LDFLAGS: -framework GLUT
// #cgo linux LDFLAGS: -lglut
// #cgo windows LDFLAGS: -lglut32
// #ifdef __APPLE__
// # include <GLUT/glut.h>
// #else
// # include <GL/glut.h>
// #endif
// #include <stdlib.h>
// #include "support.h"
import "C"

type (
Window C.int
BitmapFont C.int
StrokeFont C.int
Menu C.int
)

type windowFuncs struct {
display func()
overlayDisplay func()
reshape func(width, height int)
keyboard func(key byte, x, y int)
mouse func(button, state, x, y int)
motion func(x, y int)
passiveMotion func(x, y int)
visibility func(state int)
entry func(state int)
special func(key, x, y int)
spaceballMotion func(x, y, z int)
spaceballRotate func(x, y, z int)
spaceballButton func(button, state int)
buttonBox func(button, state int)
dials func(dial, value int)
tabletMotion func(x, y int)
tabletButton func(button, state, x, y int)
menuStatus func(status, x, y int)
idle func()
windowStatus func(state int)
keyboardUp func(key byte, x, y int)
specialUp func(key, x, y int)
joystick func(buttonMask uint, x, y, z int)
}

const (
RGB = C.GLUT_RGB
RGBA = C.GLUT_RGBA
INDEX = C.GLUT_INDEX
SINGLE = C.GLUT_SINGLE
DOUBLE = C.GLUT_DOUBLE
ACCUM = C.GLUT_ACCUM
ALPHA = C.GLUT_ALPHA
DEPTH = C.GLUT_DEPTH
STENCIL = C.GLUT_STENCIL
MULTISAMPLE = C.GLUT_MULTISAMPLE
STEREO = C.GLUT_STEREO
LUMINANCE = C.GLUT_LUMINANCE

LEFT_BUTTON = C.GLUT_LEFT_BUTTON
MIDDLE_BUTTON = C.GLUT_MIDDLE_BUTTON
RIGHT_BUTTON = C.GLUT_RIGHT_BUTTON

DOWN = C.GLUT_DOWN
UP = C.GLUT_UP

KEY_F1 = C.GLUT_KEY_F1
KEY_F2 = C.GLUT_KEY_F2
KEY_F3 = C.GLUT_KEY_F3
KEY_F4 = C.GLUT_KEY_F4
KEY_F5 = C.GLUT_KEY_F5
KEY_F6 = C.GLUT_KEY_F6
KEY_F7 = C.GLUT_KEY_F7
KEY_F8 = C.GLUT_KEY_F8
KEY_F9 = C.GLUT_KEY_F9
KEY_F10 = C.GLUT_KEY_F10
KEY_F11 = C.GLUT_KEY_F11
KEY_F12 = C.GLUT_KEY_F12

KEY_LEFT = C.GLUT_KEY_LEFT
KEY_UP = C.GLUT_KEY_UP
KEY_RIGHT = C.GLUT_KEY_RIGHT
KEY_DOWN = C.GLUT_KEY_DOWN
KEY_PAGE_UP = C.GLUT_KEY_PAGE_UP
KEY_PAGE_DOWN = C.GLUT_KEY_PAGE_DOWN
KEY_HOME = C.GLUT_KEY_HOME
KEY_END = C.GLUT_KEY_END
KEY_INSERT = C.GLUT_KEY_INSERT

LEFT = C.GLUT_LEFT
ENTERED = C.GLUT_ENTERED

MENU_NOT_IN_USE = C.GLUT_MENU_NOT_IN_USE
MENU_IN_USE = C.GLUT_MENU_IN_USE

NOT_VISIBLE = C.GLUT_NOT_VISIBLE
VISIBLE = C.GLUT_VISIBLE

HIDDEN = C.GLUT_HIDDEN
FULLY_RETAINED = C.GLUT_FULLY_RETAINED
PARTIALLY_RETAINED = C.GLUT_PARTIALLY_RETAINED
FULLY_COVERED = C.GLUT_FULLY_COVERED

RED = C.GLUT_RED
GREEN = C.GLUT_GREEN
BLUE = C.GLUT_BLUE

NORMAL = C.GLUT_NORMAL
OVERLAY = C.GLUT_OVERLAY

STROKE_ROMAN StrokeFont = iota //C.GLUT_STROKE_ROMAN
STROKE_MONO_ROMAN StrokeFont = iota //C.GLUT_STROKE_MONO_ROMAN
BITMAP_9_BY_15 BitmapFont = iota //C.GLUT_BITMAP_9_BY_15
BITMAP_8_BY_13 BitmapFont = iota //C.GLUT_BITMAP_8_BY_13
BITMAP_TIMES_ROMAN_10 BitmapFont = iota //C.GLUT_BITMAP_TIMES_ROMAN_10
BITMAP_TIMES_ROMAN_24 BitmapFont = iota //C.GLUT_BITMAP_TIMES_ROMAN_24
BITMAP_HELVETICA_10 BitmapFont = iota //C.GLUT_BITMAP_HELVETICA_10
BITMAP_HELVETICA_12 BitmapFont = iota //C.GLUT_BITMAP_HELVETICA_12
BITMAP_HELVETICA_18 BitmapFont = iota //C.GLUT_BITMAP_HELVETICA_18

WINDOW_X = C.GLUT_WINDOW_X
WINDOW_Y = C.GLUT_WINDOW_Y
WINDOW_WIDTH = C.GLUT_WINDOW_WIDTH
WINDOW_HEIGHT = C.GLUT_WINDOW_HEIGHT
WINDOW_BUFFER_SIZE = C.GLUT_WINDOW_BUFFER_SIZE
WINDOW_STENCIL_SIZE = C.GLUT_WINDOW_STENCIL_SIZE
WINDOW_DEPTH_SIZE = C.GLUT_WINDOW_DEPTH_SIZE
WINDOW_RED_SIZE = C.GLUT_WINDOW_RED_SIZE
WINDOW_GREEN_SIZE = C.GLUT_WINDOW_GREEN_SIZE
WINDOW_BLUE_SIZE = C.GLUT_WINDOW_BLUE_SIZE
WINDOW_ALPHA_SIZE = C.GLUT_WINDOW_ALPHA_SIZE
WINDOW_ACCUM_RED_SIZE = C.GLUT_WINDOW_ACCUM_RED_SIZE
WINDOW_ACCUM_GREEN_SIZE = C.GLUT_WINDOW_ACCUM_GREEN_SIZE
WINDOW_ACCUM_BLUE_SIZE = C.GLUT_WINDOW_ACCUM_BLUE_SIZE
WINDOW_ACCUM_ALPHA_SIZE = C.GLUT_WINDOW_ACCUM_ALPHA_SIZE
WINDOW_DOUBLEBUFFER = C.GLUT_WINDOW_DOUBLEBUFFER
WINDOW_RGBA = C.GLUT_WINDOW_RGBA
WINDOW_PARENT = C.GLUT_WINDOW_PARENT
WINDOW_NUM_CHILDREN = C.GLUT_WINDOW_NUM_CHILDREN
WINDOW_COLORMAP_SIZE = C.GLUT_WINDOW_COLORMAP_SIZE
WINDOW_NUM_SAMPLES = C.GLUT_WINDOW_NUM_SAMPLES
WINDOW_STEREO = C.GLUT_WINDOW_STEREO
WINDOW_CURSOR = C.GLUT_WINDOW_CURSOR
SCREEN_WIDTH = C.GLUT_SCREEN_WIDTH
SCREEN_HEIGHT = C.GLUT_SCREEN_HEIGHT
SCREEN_WIDTH_MM = C.GLUT_SCREEN_WIDTH_MM
SCREEN_HEIGHT_MM = C.GLUT_SCREEN_HEIGHT_MM
MENU_NUM_ITEMS = C.GLUT_MENU_NUM_ITEMS
DISPLAY_MODE_POSSIBLE = C.GLUT_DISPLAY_MODE_POSSIBLE
INIT_WINDOW_X = C.GLUT_INIT_WINDOW_X
INIT_WINDOW_Y = C.GLUT_INIT_WINDOW_Y
INIT_WINDOW_WIDTH = C.GLUT_INIT_WINDOW_WIDTH
INIT_WINDOW_HEIGHT = C.GLUT_INIT_WINDOW_HEIGHT
INIT_DISPLAY_MODE = C.GLUT_INIT_DISPLAY_MODE
ELAPSED_TIME = C.GLUT_ELAPSED_TIME
WINDOW_FORMAT_ID = C.GLUT_WINDOW_FORMAT_ID

HAS_KEYBOARD = C.GLUT_HAS_KEYBOARD
HAS_MOUSE = C.GLUT_HAS_MOUSE
HAS_SPACEBALL = C.GLUT_HAS_SPACEBALL
HAS_DIAL_AND_BUTTON_BOX = C.GLUT_HAS_DIAL_AND_BUTTON_BOX
HAS_TABLET = C.GLUT_HAS_TABLET
NUM_MOUSE_BUTTONS = C.GLUT_NUM_MOUSE_BUTTONS
NUM_SPACEBALL_BUTTONS = C.GLUT_NUM_SPACEBALL_BUTTONS
NUM_BUTTON_BOX_BUTTONS = C.GLUT_NUM_BUTTON_BOX_BUTTONS
NUM_DIALS = C.GLUT_NUM_DIALS
NUM_TABLET_BUTTONS = C.GLUT_NUM_TABLET_BUTTONS
DEVICE_IGNORE_KEY_REPEAT = C.GLUT_DEVICE_IGNORE_KEY_REPEAT
DEVICE_KEY_REPEAT = C.GLUT_DEVICE_KEY_REPEAT
HAS_JOYSTICK = C.GLUT_HAS_JOYSTICK
OWNS_JOYSTICK = C.GLUT_OWNS_JOYSTICK
JOYSTICK_BUTTONS = C.GLUT_JOYSTICK_BUTTONS
JOYSTICK_AXES = C.GLUT_JOYSTICK_AXES
JOYSTICK_POLL_RATE = C.GLUT_JOYSTICK_POLL_RATE

OVERLAY_POSSIBLE = C.GLUT_OVERLAY_POSSIBLE
LAYER_IN_USE = C.GLUT_LAYER_IN_USE
HAS_OVERLAY = C.GLUT_HAS_OVERLAY
TRANSPARENT_INDEX = C.GLUT_TRANSPARENT_INDEX
NORMAL_DAMAGED = C.GLUT_NORMAL_DAMAGED
OVERLAY_DAMAGED = C.GLUT_OVERLAY_DAMAGED

VIDEO_RESIZE_POSSIBLE = C.GLUT_VIDEO_RESIZE_POSSIBLE
VIDEO_RESIZE_IN_USE = C.GLUT_VIDEO_RESIZE_IN_USE
VIDEO_RESIZE_X_DELTA = C.GLUT_VIDEO_RESIZE_X_DELTA
VIDEO_RESIZE_Y_DELTA = C.GLUT_VIDEO_RESIZE_Y_DELTA
VIDEO_RESIZE_WIDTH_DELTA = C.GLUT_VIDEO_RESIZE_WIDTH_DELTA
VIDEO_RESIZE_HEIGHT_DELTA = C.GLUT_VIDEO_RESIZE_HEIGHT_DELTA
VIDEO_RESIZE_X = C.GLUT_VIDEO_RESIZE_X
VIDEO_RESIZE_Y = C.GLUT_VIDEO_RESIZE_Y
VIDEO_RESIZE_WIDTH = C.GLUT_VIDEO_RESIZE_WIDTH
VIDEO_RESIZE_HEIGHT = C.GLUT_VIDEO_RESIZE_HEIGHT

ACTIVE_SHIFT = C.GLUT_ACTIVE_SHIFT
ACTIVE_CTRL = C.GLUT_ACTIVE_CTRL
ACTIVE_ALT = C.GLUT_ACTIVE_ALT

CURSOR_RIGHT_ARROW = C.GLUT_CURSOR_RIGHT_ARROW
CURSOR_LEFT_ARROW = C.GLUT_CURSOR_LEFT_ARROW
CURSOR_INFO = C.GLUT_CURSOR_INFO
CURSOR_DESTROY = C.GLUT_CURSOR_DESTROY
CURSOR_HELP = C.GLUT_CURSOR_HELP
CURSOR_CYCLE = C.GLUT_CURSOR_CYCLE
CURSOR_SPRAY = C.GLUT_CURSOR_SPRAY
CURSOR_WAIT = C.GLUT_CURSOR_WAIT
CURSOR_TEXT = C.GLUT_CURSOR_TEXT
CURSOR_CROSSHAIR = C.GLUT_CURSOR_CROSSHAIR
CURSOR_UP_DOWN = C.GLUT_CURSOR_UP_DOWN
CURSOR_LEFT_RIGHT = C.GLUT_CURSOR_LEFT_RIGHT
CURSOR_TOP_SIDE = C.GLUT_CURSOR_TOP_SIDE
CURSOR_BOTTOM_SIDE = C.GLUT_CURSOR_BOTTOM_SIDE
CURSOR_LEFT_SIDE = C.GLUT_CURSOR_LEFT_SIDE
CURSOR_RIGHT_SIDE = C.GLUT_CURSOR_RIGHT_SIDE
CURSOR_TOP_LEFT_CORNER = C.GLUT_CURSOR_TOP_LEFT_CORNER
CURSOR_TOP_RIGHT_CORNER = C.GLUT_CURSOR_TOP_RIGHT_CORNER
CURSOR_BOTTOM_RIGHT_CORNER = C.GLUT_CURSOR_BOTTOM_RIGHT_CORNER
CURSOR_BOTTOM_LEFT_CORNER = C.GLUT_CURSOR_BOTTOM_LEFT_CORNER
CURSOR_INHERIT = C.GLUT_CURSOR_INHERIT
CURSOR_NONE = C.GLUT_CURSOR_NONE
CURSOR_FULL_CROSSHAIR = C.GLUT_CURSOR_FULL_CROSSHAIR

KEY_REPEAT_OFF = C.GLUT_KEY_REPEAT_OFF
KEY_REPEAT_ON = C.GLUT_KEY_REPEAT_ON
KEY_REPEAT_DEFAULT = C.GLUT_KEY_REPEAT_DEFAULT

JOYSTICK_BUTTON_A = C.GLUT_JOYSTICK_BUTTON_A
JOYSTICK_BUTTON_B = C.GLUT_JOYSTICK_BUTTON_B
JOYSTICK_BUTTON_C = C.GLUT_JOYSTICK_BUTTON_C
JOYSTICK_BUTTON_D = C.GLUT_JOYSTICK_BUTTON_D

GAME_MODE_ACTIVE = C.GLUT_GAME_MODE_ACTIVE
GAME_MODE_POSSIBLE = C.GLUT_GAME_MODE_POSSIBLE
GAME_MODE_WIDTH = C.GLUT_GAME_MODE_WIDTH
GAME_MODE_HEIGHT = C.GLUT_GAME_MODE_HEIGHT
GAME_MODE_PIXEL_DEPTH = C.GLUT_GAME_MODE_PIXEL_DEPTH
GAME_MODE_REFRESH_RATE = C.GLUT_GAME_MODE_REFRESH_RATE
GAME_MODE_DISPLAY_CHANGED = C.GLUT_GAME_MODE_DISPLAY_CHANGED
)

var (
idleFunc func()
winFuncs = make(map[Window]*windowFuncs)
menuFuncs = make(map[Menu]func(value int))
)

var gameWindow *Window

// - Initialization

func init() {
runtime.LockOSThread()

argc := C.int(len(os.Args))
argv := make([]*C.char, argc)
for i, arg := range os.Args {
argv[i] = C.CString(arg)
}

C.glutInit(&argc, &argv[0])

for _, arg := range argv {
C.free(unsafe.Pointer(arg))
}
}

func InitWindowPosition(x, y int) {
C.glutInitWindowPosition(C.int(x), C.int(y))
}

func InitWindowSize(width, height int) {
C.glutInitWindowSize(C.int(width), C.int(height))
}

func InitDisplayMode(mode uint) {
C.glutInitDisplayMode(C.uint(mode))
}

func InitDisplayString(str string) {
cstr := C.CString(str)
C.glutInitDisplayString(cstr)
C.free(unsafe.Pointer(cstr))
}

// - Beginning Event Processing

func MainLoop() {
C.glutMainLoop()
}

// - Window Management

func registerWindow(w Window) {
winFuncs[w] = new(windowFuncs)
}

func unregisterWindow(w Window) {
delete(winFuncs, w)
}

func CreateWindow(title string) (w Window) {
ctitle := C.CString(title)
w = Window(C.glutCreateWindow(ctitle))
C.free(unsafe.Pointer(ctitle))

registerWindow(w)

return
}

func (w Window) CreateSubWindow(x, y, width, height int) Window {
neww := Window(C.glutCreateSubWindow(C.int(w), C.int(x), C.int(y), C.int(width), C.int(height)))

registerWindow(neww)

return neww
}

func SetWindow(window Window) {
C.glutSetWindow(C.int(window))
}

func GetWindow() Window {
return Window(C.glutGetWindow())
}

func (w Window) Destroy() {
C.glutDestroyWindow(C.int(w))

unregisterWindow(w)
}

func PostRedisplay() {
C.glutPostRedisplay()
}

func (w Window) PostRedisplay() {
C.glutPostWindowRedisplay(C.int(w))
}

func SwapBuffers() {
C.glutSwapBuffers()
}

func PositionWindow(x, y int) {
C.glutPositionWindow(C.int(x), C.int(y))
}

func ReshapeWindow(width, height int) {
C.glutReshapeWindow(C.int(width), C.int(height))
}

func FullScreen() {
C.glutFullScreen()
}

func PopWindow() {
C.glutPopWindow()
}

func PushWindow() {
C.glutPushWindow()
}

func ShowWindow() {
C.glutShowWindow()
}

func HideWindow() {
C.glutHideWindow()
}

func IconifyWindow() {
C.glutIconifyWindow()
}

func SetWindowTitle(name string) {
cname := C.CString(name)
C.glutSetWindowTitle(cname)
C.free(unsafe.Pointer(cname))
}

func SetIconTitle(name string) {
cname := C.CString(name)
C.glutSetIconTitle(cname)
C.free(unsafe.Pointer(cname))
}

func SetCursor(cursor int) {
C.glutSetCursor(C.int(cursor))
}

func WarpPointer(x, y int) {
C.glutWarpPointer(C.int(x), C.int(y))
}

// - Overlay Management

func EstablishOverlay() {
C.glutEstablishOverlay()
}

func UseLayer(layer gl.GLenum) {
C.glutUseLayer(C.GLenum(layer))
}

func RemoveOverlay() {
C.glutRemoveOverlay()
}

func PostOverlayRedisplay() {
C.glutPostOverlayRedisplay()
}

func (w Window) PostOverlayRedisplay() {
C.glutPostWindowOverlayRedisplay(C.int(w))
}

func ShowOverlay() {
C.glutShowOverlay()
}

func HideOverlay() {
C.glutHideOverlay()
}

// - Menu Management

func CreateMenu(menu func(value int)) (m Menu) {
if menu != nil {
m = Menu(C.goCreateMenu())
} else {
m = Menu(C.goCreateMenuWithoutCallback())
}

menuFuncs[m] = menu

return
}

func SetMenu(menu Menu) {
C.glutSetMenu(C.int(menu))
}

func GetMenu() Menu {
return Menu(C.glutGetMenu())
}

func (m Menu) Destroy() {
C.glutDestroyMenu(C.int(m))
delete(menuFuncs, m)
}

func AddMenuEntry(name string, value int) {
cname := C.CString(name)
C.glutAddMenuEntry(cname, C.int(value))
C.free(unsafe.Pointer(cname))
}

func AddSubMenu(name string, value Menu) {
cname := C.CString(name)
C.glutAddSubMenu(cname, C.int(value))
C.free(unsafe.Pointer(cname))
}

func ChangeToMenuEntry(entry int, name string, value int) {
cname := C.CString(name)
C.glutChangeToMenuEntry(C.int(entry), cname, C.int(value))
C.free(unsafe.Pointer(cname))
}

func ChangeToSubMenu(entry int, name string, value int) {
cname := C.CString(name)
C.glutChangeToSubMenu(C.int(entry), cname, C.int(value))
C.free(unsafe.Pointer(cname))
}

func RemoveMenuItem(entry int) {
C.glutRemoveMenuItem(C.int(entry))
}

func AttachMenu(button int) {
C.glutAttachMenu(C.int(button))
}

func DetachMenu(button int) {
C.glutDetachMenu(C.int(button))
}

// - Callback Registration

func DisplayFunc(display func()) {
if display == nil {
panic("nil display func") // glut forbids this
}
winFuncs[GetWindow()].display = display
C.setDisplayFunc()
}

func OverlayDisplayFunc(overlayDisplay func()) {
winFuncs[GetWindow()].overlayDisplay = overlayDisplay
if overlayDisplay != nil {
C.setOverlayDisplayFunc()
} else {
C.clearOverlayDisplayFunc()
}
}

func ReshapeFunc(reshape func(width, height int)) {
winFuncs[GetWindow()].reshape = reshape
if reshape != nil {
C.setReshapeFunc()
} else {
C.clearReshapeFunc()
}
}

func KeyboardFunc(keyboard func(key byte, x, y int)) {
winFuncs[GetWindow()].keyboard = keyboard
if keyboard != nil {
C.setKeyboardFunc()
} else {
C.clearKeyboardFunc()
}
}

func MouseFunc(mouse func(button, state, x, y int)) {
winFuncs[GetWindow()].mouse = mouse
if mouse != nil {
C.setMouseFunc()
} else {
C.clearMouseFunc()
}
}

func MotionFunc(motion func(x, y int)) {
winFuncs[GetWindow()].motion = motion
if motion != nil {
C.setMotionFunc()
} else {
C.clearMotionFunc()
}
}

func PassiveMotionFunc(passiveMotion func(x, y int)) {
winFuncs[GetWindow()].passiveMotion = passiveMotion
if passiveMotion != nil {
C.setPassiveMotionFunc()
} else {
C.clearPassiveMotionFunc()
}
}

func VisibilityFunc(visibility func(state int)) {
winFuncs[GetWindow()].visibility = visibility
if visibility != nil {
C.setVisibilityFunc()
} else {
C.clearVisibilityFunc()
}
}

func EntryFunc(entry func(state int)) {
winFuncs[GetWindow()].entry = entry
if entry != nil {
C.setEntryFunc()
} else {
C.clearEntryFunc()
}
}

func SpecialFunc(special func(key, x, y int)) {
winFuncs[GetWindow()].special = special
if special != nil {
C.setSpecialFunc()
} else {
C.clearSpecialFunc()
}
}

func SpaceballMotionFunc(spaceballMotion func(x, y, z int)) {
winFuncs[GetWindow()].spaceballMotion = spaceballMotion
if spaceballMotion != nil {
C.setSpaceballMotionFunc()
} else {
C.clearSpaceballMotionFunc()
}
}

func SpaceballRotateFunc(spaceballRotate func(x, y, z int)) {
winFuncs[GetWindow()].spaceballRotate = spaceballRotate
if spaceballRotate != nil {
C.setSpaceballRotateFunc()
} else {
C.clearSpaceballRotateFunc()
}
}

func SpaceballButtonFunc(spaceballButton func(button, state int)) {
winFuncs[GetWindow()].spaceballButton = spaceballButton
if spaceballButton != nil {
C.setSpaceballButtonFunc()
} else {
C.clearSpaceballButtonFunc()
}
}

func ButtonBoxFunc(buttonBox func(button, state int)) {
winFuncs[GetWindow()].buttonBox = buttonBox
if buttonBox != nil {
C.setButtonBoxFunc()
} else {
C.clearButtonBoxFunc()
}
}

func DialsFunc(dials func(dial, value int)) {
winFuncs[GetWindow()].dials = dials
if dials != nil {
C.setDialsFunc()
} else {
C.clearDialsFunc()
}
}

func TabletMotionFunc(tabletMotion func(x, y int)) {
winFuncs[GetWindow()].tabletMotion = tabletMotion
if tabletMotion != nil {
C.setTabletMotionFunc()
} else {
C.clearTabletMotionFunc()
}
}

func TabletButtonFunc(tabletButton func(button, state, x, y int)) {
winFuncs[GetWindow()].tabletButton = tabletButton
if tabletButton != nil {
C.setTabletButtonFunc()
} else {
C.clearTabletButtonFunc()
}
}

func MenuStatusFunc(menuStatus func(status, x, y int)) {
winFuncs[GetWindow()].menuStatus = menuStatus
if menuStatus != nil {
C.setMenuStatusFunc()
} else {
C.clearMenuStatusFunc()
}
}

func IdleFunc(idle func()) {
idleFunc = idle
if idle != nil {
C.setIdleFunc()
} else {
C.clearIdleFunc()
}
}

func KeyboardUpFunc(keyboardUp func(key byte, x, y int)) {
winFuncs[GetWindow()].keyboardUp = keyboardUp
if keyboardUp != nil {
C.setKeyboardUpFunc()
} else {
C.clearKeyboardUpFunc()
}
}

func SpecialUpFunc(specialUp func(key, x, y int)) {
winFuncs[GetWindow()].specialUp = specialUp
if specialUp != nil {
C.setSpecialUpFunc()
} else {
C.clearSpecialUpFunc()
}
}

func JoystickFunc(joystick func(buttonMask uint, x, y, z int), pollInterval int) {
winFuncs[GetWindow()].joystick = joystick
if joystick != nil {
C.setJoystickFunc(C.int(pollInterval))
} else {
C.clearJoystickFunc(C.int(pollInterval))
}
}

// - Color Index Colormap Management

func SetColor(cell int, red, green, blue gl.GLfloat) {
C.glutSetColor(C.int(cell), C.GLfloat(red), C.GLfloat(green), C.GLfloat(blue))
}

func GetColor(cell int) (red, green, blue gl.GLfloat) {
ccell := C.int(cell)

red = gl.GLfloat(C.glutGetColor(ccell, RED))
green = gl.GLfloat(C.glutGetColor(ccell, GREEN))
blue = gl.GLfloat(C.glutGetColor(ccell, BLUE))

return
}

func CopyColormap(win Window) {
C.glutCopyColormap(C.int(win))
}

// - State Retrieval

func Get(state gl.GLenum) int {
return int(C.glutGet(C.GLenum(state)))
}

func LayerGet(info gl.GLenum) int {
return int(C.glutLayerGet(C.GLenum(info)))
}

func DeviceGet(info gl.GLenum) int {
return int(C.glutDeviceGet(C.GLenum(info)))
}

func GetModifiers() int {
return int(C.glutGetModifiers())
}

func ExtensionSupported(extension string) (supported bool) {
cextension := C.CString(extension)
supported = C.glutExtensionSupported(cextension) != 0
C.free(unsafe.Pointer(cextension))
return
}

// - Font Rendering

func fontaddr(f int) unsafe.Pointer {
switch f {
case int(STROKE_ROMAN):
return unsafe.Pointer(C.go_GLUT_STROKE_ROMAN())
case int(STROKE_MONO_ROMAN):
return unsafe.Pointer(C.go_GLUT_STROKE_MONO_ROMAN())
case int(BITMAP_9_BY_15):
return unsafe.Pointer(C.go_GLUT_BITMAP_9_BY_15())
case int(BITMAP_8_BY_13):
return unsafe.Pointer(C.go_GLUT_BITMAP_8_BY_13())
case int(BITMAP_TIMES_ROMAN_10):
return unsafe.Pointer(C.go_GLUT_BITMAP_TIMES_ROMAN_10())
case int(BITMAP_TIMES_ROMAN_24):
return unsafe.Pointer(C.go_GLUT_BITMAP_TIMES_ROMAN_24())
case int(BITMAP_HELVETICA_10):
return unsafe.Pointer(C.go_GLUT_BITMAP_HELVETICA_10())
case int(BITMAP_HELVETICA_12):
return unsafe.Pointer(C.go_GLUT_BITMAP_HELVETICA_12())
case int(BITMAP_HELVETICA_18):
return unsafe.Pointer(C.go_GLUT_BITMAP_HELVETICA_18())
}
panic("unknown font")
}

func (b BitmapFont) Character(character rune) {
C.glutBitmapCharacter(fontaddr(int(b)), C.int(character))
}

func (b BitmapFont) Width(character rune) int {
return int(C.glutBitmapWidth(fontaddr(int(b)), C.int(character)))
}

func (b BitmapFont) Length(str string) int {
cstr := C.CString(str)
strlen := C.glutBitmapLength(fontaddr(int(b)), (*C.uchar)(unsafe.Pointer(cstr)))
C.free(unsafe.Pointer(cstr))
return int(strlen)
}

func (s StrokeFont) Character(character rune) {
C.glutStrokeCharacter(fontaddr(int(s)), C.int(character))
}

func (s StrokeFont) Width(character rune) int {
return int(C.glutStrokeWidth(fontaddr(int(s)), C.int(character)))
}

func (s StrokeFont) Length(str string) int {
cstr := C.CString(str)
strlen := C.glutStrokeLength(fontaddr(int(s)), (*C.uchar)(unsafe.Pointer(cstr)))
C.free(unsafe.Pointer(cstr))
return int(strlen)
}

// - Geometric Object Rendering

func SolidSphere(radius gl.GLdouble, slices, stacks gl.GLint) {
C.glutSolidSphere(C.GLdouble(radius), C.GLint(slices), C.GLint(stacks))
}

func WireSphere(radius gl.GLdouble, slices, stacks gl.GLint) {
C.glutWireSphere(C.GLdouble(radius), C.GLint(slices), C.GLint(stacks))
}

func SolidCube(size gl.GLdouble) {
C.glutSolidCube(C.GLdouble(size))
}

func WireCube(size gl.GLdouble) {
C.glutWireCube(C.GLdouble(size))
}

func SolidCone(base, height gl.GLdouble, slices, stacks gl.GLint) {
C.glutSolidCone(C.GLdouble(base), C.GLdouble(height), C.GLint(slices), C.GLint(stacks))
}

func WireCone(base, height gl.GLdouble, slices, stacks gl.GLint) {
C.glutWireCone(C.GLdouble(base), C.GLdouble(height), C.GLint(slices), C.GLint(stacks))
}

func SolidTorus(innerRadius, outerRadius gl.GLdouble, nsides, rings gl.GLint) {
C.glutSolidTorus(C.GLdouble(innerRadius), C.GLdouble(outerRadius), C.GLint(nsides), C.GLint(rings))
}

func WireTorus(innerRadius, outerRadius gl.GLdouble, nsides, rings gl.GLint) {
C.glutWireTorus(C.GLdouble(innerRadius), C.GLdouble(outerRadius), C.GLint(nsides), C.GLint(rings))
}

func SolidDodecahedron() {
C.glutSolidDodecahedron()
}

func WireDodecahedron() {
C.glutWireDodecahedron()
}

func SolidOctahedron() {
C.glutSolidOctahedron()
}

func WireOctahedron() {
C.glutWireOctahedron()
}

func SolidTetrahedron() {
C.glutSolidTetrahedron()
}

func WireTetrahedron() {
C.glutWireTetrahedron()
}

func SolidIcosahedron() {
C.glutSolidIcosahedron()
}

func WireIcosahedron() {
C.glutWireIcosahedron()
}

// And, of course:
func SolidTeapot(size gl.GLdouble) {
C.glutSolidTeapot(C.GLdouble(size))
}

func WireTeapot(size gl.GLdouble) {
C.glutWireTeapot(C.GLdouble(size))
}

// - Video Resize

func VideoResizeGet(param gl.GLenum) int {
return int(C.glutVideoResizeGet(C.GLenum(param)))
}

func SetupVideoResizing() {
C.glutSetupVideoResizing()
}

func StopVideoResizing() {
C.glutStopVideoResizing()
}

func VideoResize(x, y, width, height int) {
C.glutVideoResize(C.int(x), C.int(y), C.int(width), C.int(height))
}

func VideoPan(x, y, width, height int) {
C.glutVideoPan(C.int(x), C.int(y), C.int(width), C.int(height))
}

// - Debugging

func ReportErrors() {
C.glutReportErrors()
}

// - Device Control

func IgnoreKeyRepeat(ignore int) {
C.glutIgnoreKeyRepeat(C.int(ignore))
}

func SetKeyRepeat(repeatMode int) {
C.glutSetKeyRepeat(C.int(repeatMode))
}

func ForceJoystickFunc() {
C.glutForceJoystickFunc()
}

// - Game Mode

func GameModeString(str string) {
cstr := C.CString(str)
C.glutGameModeString(cstr)
C.free(unsafe.Pointer(cstr))
}

func EnterGameMode() Window {
w := Window(C.glutEnterGameMode())

if gameWindow != nil {
unregisterWindow(*gameWindow)
}
registerWindow(w)
gameWindow = &w

return w
}

func LeaveGameMode() {
C.glutLeaveGameMode()

unregisterWindow(*gameWindow)
gameWindow = nil
}

func GameModeGet(mode gl.GLenum) int {
return int(C.glutGameModeGet(C.GLenum(mode)))
}

// - Callbacks

//export internalButtonBoxFunc
func internalButtonBoxFunc(button, state int) {
winFuncs[GetWindow()].buttonBox(button, state)
}

//export internalDialsFunc
func internalDialsFunc(dial, value int) {
winFuncs[GetWindow()].dials(dial, value)
}

//export internalDisplayFunc
func internalDisplayFunc() {
winFuncs[GetWindow()].display()
}

//export internalEntryFunc
func internalEntryFunc(state int) {
winFuncs[GetWindow()].entry(state)
}

//export internalIdleFunc
func internalIdleFunc() {
idleFunc()
}

//export internalJoystickFunc
func internalJoystickFunc(buttonMask uint, x, y, z int) {
winFuncs[GetWindow()].joystick(buttonMask, x, y, z)
}

//export internalKeyboardFunc
func internalKeyboardFunc(key uint8, x, y int) {
winFuncs[GetWindow()].keyboard(key, x, y)
}

//export internalKeyboardUpFunc
func internalKeyboardUpFunc(key uint8, x, y int) {
winFuncs[GetWindow()].keyboardUp(key, x, y)
}

//export internalMenuFunc
func internalMenuFunc(state int) {
menuFuncs[GetMenu()](state)
}

//export internalMenuStatusFunc
func internalMenuStatusFunc(status, x, y int) {
winFuncs[GetWindow()].menuStatus(status, x, y)
}

//export internalMotionFunc
func internalMotionFunc(x, y int) {
winFuncs[GetWindow()].motion(x, y)
}

//export internalMouseFunc
func internalMouseFunc(button, state, x, y int) {
winFuncs[GetWindow()].mouse(button, state, x, y)
}

//export internalOverlayDisplayFunc
func internalOverlayDisplayFunc() {
winFuncs[GetWindow()].overlayDisplay()
}

//export internalPassiveMotionFunc
func internalPassiveMotionFunc(x, y int) {
winFuncs[GetWindow()].passiveMotion(x, y)
}

//export internalReshapeFunc
func internalReshapeFunc(width, height int) {
winFuncs[GetWindow()].reshape(width, height)
}

//export internalSpaceballButtonFunc
func internalSpaceballButtonFunc(button, state int) {
winFuncs[GetWindow()].spaceballButton(button, state)
}

//export internalSpaceballMotionFunc
func internalSpaceballMotionFunc(x, y, z int) {
winFuncs[GetWindow()].spaceballMotion(x, y, z)
}

//export internalSpaceballRotateFunc
func internalSpaceballRotateFunc(x, y, z int) {
winFuncs[GetWindow()].spaceballRotate(x, y, z)
}

//export internalSpecialFunc
func internalSpecialFunc(key, x, y int) {
winFuncs[GetWindow()].special(key, x, y)
}

//export internalSpecialUpFunc
func internalSpecialUpFunc(key, x, y int) {
winFuncs[GetWindow()].specialUp(key, x, y)
}

//export internalTabletButtonFunc
func internalTabletButtonFunc(button, state, x, y int) {
winFuncs[GetWindow()].tabletButton(button, state, x, y)
}

//export internalTabletMotionFunc
func internalTabletMotionFunc(x, y int) {
winFuncs[GetWindow()].tabletMotion(x, y)
}

//export internalVisibilityFunc
func internalVisibilityFunc(state int) {
winFuncs[GetWindow()].visibility(state)
}
Something went wrong with that request. Please try again.