Beispiel #1
0
//CreateWindow creates a window and its associated context. Most of the options
//controlling how the window and its context should be created are specified
//through Hint.
//
//Successful creation does not change which context is current. Before you can
//use the newly created context, you need to make it current using
//MakeContextCurrent.
//
//Note that the created window and context may differ from what you requested,
//as not all parameters and hints are hard constraints. This includes the size
//of the window, especially for full screen windows. To retrieve the actual
//attributes of the created window and context, use queries like
//GetWindowAttrib and GetWindowSize.
//
//To create the window at a specific position, make it initially invisible using
//the Visible window hint, set its position and then show it.
//
//If a fullscreen window is active, the screensaver is prohibited from starting.
//
//Windows: If the executable has an icon resource named GLFW_ICON, it will be
//set as the icon for the window. If no such icon is present, the IDI_WINLOGO
//icon will be used instead.
//
//Mac OS X: The GLFW window has no icon, as it is not a document window, but the
//dock icon will be the same as the application bundle's icon. Also, the first
//time a window is opened the menu bar is populated with common commands like
//Hide, Quit and About. The (minimal) about dialog uses information from the
//application's bundle. For more information on bundles, see the Bundle
//Programming Guide provided by Apple.
//
//This function may only be called from the main thread. See
//https://code.google.com/p/go-wiki/wiki/LockOSThread
func CreateWindow(width, height int, title string, monitor *Monitor, share *Window) (*Window, error) {
	var (
		m *C.GLFWmonitor
		s *C.GLFWwindow
	)

	t := C.CString(title)
	defer C.free(unsafe.Pointer(t))

	if monitor != nil {
		m = monitor.data
	}

	if share != nil {
		s = share.data
	}

	w := C.glfwCreateWindow(C.int(width), C.int(height), t, m, s)

	if w == nil {
		return nil, errors.New("Can't create window.")
	}
	wnd := &Window{data: w}
	windows.put(wnd)
	return wnd, nil
}
Beispiel #2
0
func NewWindow(width, height int, title string) *Window {
	win := C.glfwCreateWindow(C.int(width), C.int(height), C.CString(title), nil, nil)
	if win == nil {
		panic("GLFW:  Failed to create window.")
	}
	w := &Window{w: win}
	C.glfwSetWindowUserPointer(win, unsafe.Pointer(w))
	windows.Lock()
	windows.m[win] = w
	windows.Unlock()
	return w
}
Beispiel #3
0
Datei: glfw.go Projekt: maun/glfw
// Window handling
func CreateWindow(width, height, mode int, title string, share Window) (window Window, err error) {
	csTitle := C.CString(title)
	window = Window(C.glfwCreateWindow(
		C.int(width), C.int(height),
		C.int(mode), csTitle,
		C.GLFWwindow(share)))
	C.free(unsafe.Pointer(csTitle))

	if window == nil {
		err = errors.New("Failed to open window")
	}
	return
}