MCPcopy
hub / github.com/g3n/engine / Init

Function Init

window/glfw.go:217–366  ·  view source on GitHub ↗

Init initializes the GlfwWindow singleton with the specified width, height, and title.

(width, height int, title string)

Source from the content-addressed store, hash-verified

215
216// Init initializes the GlfwWindow singleton with the specified width, height, and title.
217func Init(width, height int, title string) error {
218
219 // Panic if already created
220 if win != nil {
221 panic(fmt.Errorf("can only call window.Init() once"))
222 }
223
224 // OpenGL functions must be executed in the same thread where
225 // the context was created (by wmgr.CreateWindow())
226 runtime.LockOSThread()
227
228 // Create wrapper window with dispatcher
229 w := new(GlfwWindow)
230 w.Dispatcher.Initialize()
231 var err error
232
233 // Initialize GLFW
234 err = glfw.Init()
235 if err != nil {
236 return err
237 }
238
239 // Set window hints
240 glfw.WindowHint(glfw.ContextVersionMajor, 3)
241 glfw.WindowHint(glfw.ContextVersionMinor, 3)
242 glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
243 glfw.WindowHint(glfw.Samples, 8)
244 // Set OpenGL forward compatible context only for OSX because it is required for OSX.
245 // When this is set, glLineWidth(width) only accepts width=1.0 and generates an error
246 // for any other values although the spec says it should ignore unsupported widths
247 // and generate an error only when width <= 0.
248 if runtime.GOOS == "darwin" {
249 glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
250 }
251
252 // Create window and set it as the current context.
253 // The window is created always as not full screen because if it is
254 // created as full screen it not possible to revert it to windowed mode.
255 // At the end of this function, the window will be set to full screen if requested.
256 w.Window, err = glfw.CreateWindow(width, height, title, nil, nil)
257 if err != nil {
258 return err
259 }
260 w.MakeContextCurrent()
261
262 // Create OpenGL state
263 w.gls, err = gls.New()
264 if err != nil {
265 return err
266 }
267
268 // Compute and store scale
269 fbw, fbh := w.GetFramebufferSize()
270 w.scaleX = float64(fbw) / float64(width)
271 w.scaleY = float64(fbh) / float64(height)
272
273 // Create map for cursors
274 w.cursors = make(map[Cursor]*glfw.Cursor)

Callers

nothing calls this directly

Calls 10

NewFunction · 0.92
MustAssetFunction · 0.92
KeyTypeAlias · 0.85
ModifierKeyTypeAlias · 0.85
MouseButtonTypeAlias · 0.85
GetFramebufferSizeMethod · 0.65
CreateCursorMethod · 0.65
DispatchMethod · 0.65
InitializeMethod · 0.45
InitMethod · 0.45

Tested by

no test coverage detected