Permalink
Browse files

more fixes

  • Loading branch information...
1 parent 2ea23c9 commit c874c71b7e934ae275b2e9a9205d98674b6f6773 @rhencke committed Jul 7, 2012
Showing with 109 additions and 111 deletions.
  1. +0 −1 examples/asteroids.go
  2. +0 −1 examples/fontdemo.go
  3. +0 −1 examples/simple.go
  4. +73 −70 glut.go
  5. +4 −6 support.c
  6. +32 −32 support.h
@@ -357,7 +357,6 @@ func initWindow() {
}
func main() {
- glut.Init()
glut.InitDisplayMode(glut.DOUBLE | glut.RGB)
// FIXME: gamemode causes crash
@@ -72,7 +72,6 @@ func reshape(w, h int) {
}
func main() {
- glut.Init()
glut.InitDisplayMode(glut.SINGLE | glut.RGB)
glut.InitWindowSize(465, 250)
glut.CreateWindow("GLUT bitmap & stroke font example")
View
@@ -51,7 +51,6 @@ func display() {
}
func main() {
- glut.Init()
glut.CreateWindow("single triangle")
glut.DisplayFunc(display)
glut.ReshapeFunc(reshape)
View
@@ -5,6 +5,7 @@ package glut
import (
"os"
+ "runtime"
"unsafe"
"github.com/banthar/gl"
@@ -259,7 +260,9 @@ var gameWindow *Window
// - Initialization
-func Init() {
+func init() {
+ runtime.LockOSThread()
+
argc := C.int(len(os.Args))
argv := make([]*C.char, argc)
for i, arg := range os.Args {
@@ -946,117 +949,117 @@ func GameModeGet(mode gl.GLenum) int {
// - Callbacks
-//export internalDisplayFunc
-func internalDisplayFunc() {
- winFuncs[GetWindow()].display()
+//export InternalButtonBoxFunc
+func InternalButtonBoxFunc(button, state int) {
+ winFuncs[GetWindow()].buttonBox(button, state)
}
-//export internalOverlayDisplayFunc
-func internalOverlayDisplayFunc() {
- winFuncs[GetWindow()].overlayDisplay()
+//export InternalDialsFunc
+func InternalDialsFunc(dial, value int) {
+ winFuncs[GetWindow()].dials(dial, value)
}
-//export internalReshapeFunc
-func internalReshapeFunc(width, height int) {
- winFuncs[GetWindow()].reshape(width, height)
+//export InternalDisplayFunc
+func InternalDisplayFunc() {
+ winFuncs[GetWindow()].display()
}
-//export internalKeyboardFunc
-func internalKeyboardFunc(key uint8, x, y int) {
- winFuncs[GetWindow()].keyboard(key, x, y)
+//export InternalEntryFunc
+func InternalEntryFunc(state int) {
+ winFuncs[GetWindow()].entry(state)
}
-//export internalMouseFunc
-func internalMouseFunc(button, state, x, y int) {
- winFuncs[GetWindow()].mouse(button, state, x, y)
+//export InternalIdleFunc
+func InternalIdleFunc() {
+ idleFunc()
}
-//export internalMotionFunc
-func internalMotionFunc(x, y int) {
- winFuncs[GetWindow()].motion(x, y)
+//export InternalJoystickFunc
+func InternalJoystickFunc(buttonMask uint, x, y, z int) {
+ winFuncs[GetWindow()].joystick(buttonMask, x, y, z)
}
-//export internalPassiveMotionFunc
-func internalPassiveMotionFunc(x, y int) {
- winFuncs[GetWindow()].passiveMotion(x, y)
+//export InternalKeyboardFunc
+func InternalKeyboardFunc(key uint8, x, y int) {
+ winFuncs[GetWindow()].keyboard(key, x, y)
}
-//export internalVisibilityFunc
-func internalVisibilityFunc(state int) {
- winFuncs[GetWindow()].visibility(state)
+//export InternalKeyboardUpFunc
+func InternalKeyboardUpFunc(key uint8, x, y int) {
+ winFuncs[GetWindow()].keyboardUp(key, x, y)
}
-//export internalEntryFunc
-func internalEntryFunc(state int) {
- winFuncs[GetWindow()].entry(state)
+//export InternalMenuFunc
+func InternalMenuFunc(state int) {
+ menuFuncs[GetMenu()](state)
}
-//export internalSpecialFunc
-func internalSpecialFunc(key, x, y int) {
- winFuncs[GetWindow()].special(key, x, y)
+//export InternalMenuStatusFunc
+func InternalMenuStatusFunc(status, x, y int) {
+ winFuncs[GetWindow()].menuStatus(status, x, y)
}
-//export internalSpaceballMotionFunc
-func internalSpaceballMotionFunc(x, y, z int) {
- winFuncs[GetWindow()].spaceballMotion(x, y, z)
+//export InternalMotionFunc
+func InternalMotionFunc(x, y int) {
+ winFuncs[GetWindow()].motion(x, y)
}
-//export internalSpaceballRotateFunc
-func internalSpaceballRotateFunc(x, y, z int) {
- winFuncs[GetWindow()].spaceballRotate(x, y, z)
+//export InternalMouseFunc
+func InternalMouseFunc(button, state, x, y int) {
+ winFuncs[GetWindow()].mouse(button, state, x, y)
}
-//export internalSpaceballButtonFunc
-func internalSpaceballButtonFunc(button, state int) {
- winFuncs[GetWindow()].spaceballButton(button, state)
+//export InternalOverlayDisplayFunc
+func InternalOverlayDisplayFunc() {
+ winFuncs[GetWindow()].overlayDisplay()
}
-//export internalButtonBoxFunc
-func internalButtonBoxFunc(button, state int) {
- winFuncs[GetWindow()].buttonBox(button, state)
+//export InternalPassiveMotionFunc
+func InternalPassiveMotionFunc(x, y int) {
+ winFuncs[GetWindow()].passiveMotion(x, y)
}
-//export internalDialsFunc
-func internalDialsFunc(dial, value int) {
- winFuncs[GetWindow()].dials(dial, value)
+//export InternalReshapeFunc
+func InternalReshapeFunc(width, height int) {
+ winFuncs[GetWindow()].reshape(width, height)
}
-//export internalTabletMotionFunc
-func internalTabletMotionFunc(x, y int) {
- winFuncs[GetWindow()].tabletMotion(x, y)
+//export InternalSpaceballButtonFunc
+func InternalSpaceballButtonFunc(button, state int) {
+ winFuncs[GetWindow()].spaceballButton(button, state)
}
-//export internalTabletButtonFunc
-func internalTabletButtonFunc(button, state, x, y int) {
- winFuncs[GetWindow()].tabletButton(button, state, x, y)
+//export InternalSpaceballMotionFunc
+func InternalSpaceballMotionFunc(x, y, z int) {
+ winFuncs[GetWindow()].spaceballMotion(x, y, z)
}
-//export internalMenuStatusFunc
-func internalMenuStatusFunc(status, x, y int) {
- winFuncs[GetWindow()].menuStatus(status, x, y)
+//export InternalSpaceballRotateFunc
+func InternalSpaceballRotateFunc(x, y, z int) {
+ winFuncs[GetWindow()].spaceballRotate(x, y, z)
}
-//export internalIdleFunc
-func internalIdleFunc() {
- idleFunc()
+//export InternalSpecialFunc
+func InternalSpecialFunc(key, x, y int) {
+ winFuncs[GetWindow()].special(key, x, y)
}
-//export internalMenuFunc
-func internalMenuFunc(state int) {
- menuFuncs[GetMenu()](state)
+//export InternalSpecialUpFunc
+func InternalSpecialUpFunc(key, x, y int) {
+ winFuncs[GetWindow()].specialUp(key, x, y)
}
-//export internalKeyboardUpFunc
-func internalKeyboardUpFunc(key uint8, x, y int) {
- winFuncs[GetWindow()].keyboardUp(key, x, y)
+//export InternalTabletButtonFunc
+func InternalTabletButtonFunc(button, state, x, y int) {
+ winFuncs[GetWindow()].tabletButton(button, state, x, y)
}
-//export internalSpecialUpFunc
-func internalSpecialUpFunc(key, x, y int) {
- winFuncs[GetWindow()].specialUp(key, x, y)
+//export InternalTabletMotionFunc
+func InternalTabletMotionFunc(x, y int) {
+ winFuncs[GetWindow()].tabletMotion(x, y)
}
-//export internalJoystickFunc
-func internalJoystickFunc(buttonMask uint, x, y, z int) {
- winFuncs[GetWindow()].joystick(buttonMask, x, y, z)
+//export InternalVisibilityFunc
+func InternalVisibilityFunc(state int) {
+ winFuncs[GetWindow()].visibility(state)
}
View
@@ -4,11 +4,11 @@
# include <GL/glut.h>
#endif
#include <stdlib.h>
+#include "_cgo_export.h"
// DEFINE_FUNCS is needed because I'm unsure how to pass C function pointers in Go.
#define DEFINE_FUNCS(x, ...) \
-extern void internal##x##Func(__VA_ARGS__); \
-void set##x##Func() { glut##x##Func(internal##x##Func); } \
+void set##x##Func() { glut##x##Func(Internal##x##Func); } \
void clear##x##Func() { glut##x##Func(0); } \
DEFINE_FUNCS(Display)
@@ -35,13 +35,11 @@ DEFINE_FUNCS(KeyboardUp, unsigned char key, int x, int y)
DEFINE_FUNCS(SpecialUp, int key, int x, int y)
// glutCreateMenu callback
-extern void internalMenuFunc(int value);
-int goCreateMenu() { return glutCreateMenu(internalMenuFunc); }
+int goCreateMenu() { return glutCreateMenu(InternalMenuFunc); }
int goCreateMenuWithoutCallback() { return glutCreateMenu(0); }
// glutJoystickFunc callback
-extern void internalJoystickFunc(unsigned int buttonMask, int x, int y, int z);
-void setJoystickFunc(int pollInterval) { glutJoystickFunc(internalJoystickFunc, pollInterval); }
+void setJoystickFunc(int pollInterval) { glutJoystickFunc(InternalJoystickFunc, pollInterval); }
void clearJoystickFunc(int pollInterval) { glutJoystickFunc(0, pollInterval); }
// cgo does not correctly interpret the GLUT font constants, so we try a different approach.
View
@@ -1,30 +1,30 @@
// DEFINE_FUNCS is needed because I'm unsure how to pass C function pointers in Go.
-#define DEFINE_FUNCS(x, ...) \
+#define DECLARE_FUNCS(x, ...) \
extern void set##x##Func(); \
extern void clear##x##Func();
-DEFINE_FUNCS(Display)
-DEFINE_FUNCS(OverlayDisplay)
-DEFINE_FUNCS(Reshape, int width, int height)
-DEFINE_FUNCS(Keyboard, unsigned char key, int x, int y)
-DEFINE_FUNCS(Mouse, int button, int state, int x, int y)
-DEFINE_FUNCS(Motion, int x, int y)
-DEFINE_FUNCS(PassiveMotion, int x, int y)
-DEFINE_FUNCS(Visibility, int state)
-DEFINE_FUNCS(Entry, int state)
-DEFINE_FUNCS(Special, int key, int x, int y)
-DEFINE_FUNCS(SpaceballMotion, int x, int y, int z)
-DEFINE_FUNCS(SpaceballRotate, int x, int y, int z)
-DEFINE_FUNCS(SpaceballButton, int button, int state)
+DECLARE_FUNCS(Display)
+DECLARE_FUNCS(OverlayDisplay)
+DECLARE_FUNCS(Reshape, int width, int height)
+DECLARE_FUNCS(Keyboard, unsigned char key, int x, int y)
+DECLARE_FUNCS(Mouse, int button, int state, int x, int y)
+DECLARE_FUNCS(Motion, int x, int y)
+DECLARE_FUNCS(PassiveMotion, int x, int y)
+DECLARE_FUNCS(Visibility, int state)
+DECLARE_FUNCS(Entry, int state)
+DECLARE_FUNCS(Special, int key, int x, int y)
+DECLARE_FUNCS(SpaceballMotion, int x, int y, int z)
+DECLARE_FUNCS(SpaceballRotate, int x, int y, int z)
+DECLARE_FUNCS(SpaceballButton, int button, int state)
/* just in case you're on an SGI box.. :) */
-DEFINE_FUNCS(ButtonBox, int button, int state)
-DEFINE_FUNCS(Dials, int dial, int value)
-DEFINE_FUNCS(TabletMotion, int x, int y)
-DEFINE_FUNCS(TabletButton, int button, int state, int x, int y)
-DEFINE_FUNCS(MenuStatus, int status, int x, int y)
-DEFINE_FUNCS(Idle)
-DEFINE_FUNCS(KeyboardUp, unsigned char key, int x, int y)
-DEFINE_FUNCS(SpecialUp, int key, int x, int y)
+DECLARE_FUNCS(ButtonBox, int button, int state)
+DECLARE_FUNCS(Dials, int dial, int value)
+DECLARE_FUNCS(TabletMotion, int x, int y)
+DECLARE_FUNCS(TabletButton, int button, int state, int x, int y)
+DECLARE_FUNCS(MenuStatus, int status, int x, int y)
+DECLARE_FUNCS(Idle)
+DECLARE_FUNCS(KeyboardUp, unsigned char key, int x, int y)
+DECLARE_FUNCS(SpecialUp, int key, int x, int y)
// glutCreateMenu callback
extern int goCreateMenu();
@@ -35,14 +35,14 @@ extern void setJoystickFunc(int pollInterval);
extern void clearJoystickFunc(int pollInterval);
// cgo does not correctly interpret the GLUT font constants, so we try a different approach.
-#define DEFINE_FONT(x) extern void* go_##x();
+#define DECLARE_FONT(x) extern void* go_##x();
-DEFINE_FONT(GLUT_STROKE_MONO_ROMAN)
-DEFINE_FONT(GLUT_STROKE_ROMAN)
-DEFINE_FONT(GLUT_BITMAP_9_BY_15)
-DEFINE_FONT(GLUT_BITMAP_8_BY_13)
-DEFINE_FONT(GLUT_BITMAP_TIMES_ROMAN_10)
-DEFINE_FONT(GLUT_BITMAP_TIMES_ROMAN_24)
-DEFINE_FONT(GLUT_BITMAP_HELVETICA_10)
-DEFINE_FONT(GLUT_BITMAP_HELVETICA_12)
-DEFINE_FONT(GLUT_BITMAP_HELVETICA_18)
+DECLARE_FONT(GLUT_STROKE_MONO_ROMAN)
+DECLARE_FONT(GLUT_STROKE_ROMAN)
+DECLARE_FONT(GLUT_BITMAP_9_BY_15)
+DECLARE_FONT(GLUT_BITMAP_8_BY_13)
+DECLARE_FONT(GLUT_BITMAP_TIMES_ROMAN_10)
+DECLARE_FONT(GLUT_BITMAP_TIMES_ROMAN_24)
+DECLARE_FONT(GLUT_BITMAP_HELVETICA_10)
+DECLARE_FONT(GLUT_BITMAP_HELVETICA_12)
+DECLARE_FONT(GLUT_BITMAP_HELVETICA_18)

0 comments on commit c874c71

Please sign in to comment.