Exemplo n.º 1
0
func main() {
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	window, err := glfw.CreateWindow(640, 480, "tut03", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	t0 := time.Now()
	program := initResources()
	for {
		curFade = float32(math.Sin(time.Now().Sub(t0).Seconds()*2*math.Pi/5)/2 + 0.5)
		onDisplay(program)
		window.SwapBuffers()
		glfw.PollEvents()
	}

	gl.DeleteProgram(program)
	gl.DeleteBuffers(1, &vboTriangle)
}
Exemplo n.º 2
0
func main() {
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to inifitialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	window, err := glfw.CreateWindow(windowWidth, windowHeight, "basic shaders", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	// Initialize Glow (go function bindings)
	if err := gl.Init(); err != nil {
		panic(err)
	}

	window.SetKeyCallback(keyCallback)

	err = programLoop(window)
	if err != nil {
		log.Fatal(err)
	}
}
Exemplo n.º 3
0
func main() {
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	window, err := glfw.CreateWindow(640, 480, "tut01", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	program, coords := initResources()
	for {
		onDisplay(program, uint32(coords))
		window.SwapBuffers()
	}
}
Exemplo n.º 4
0
func CreateContext(width int, height int) (*Context, error) {
	if err := glfw.Init(); err != nil {
		fmt.Println("failed to initialize glfw:", err)
	}

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	window, err := glfw.CreateWindow(width, height, "flamingo", nil, nil)

	if err != nil {
		glfw.Terminate()
		return nil, err
	}

	window.MakeContextCurrent()

	// Initialize Glow
	if err = gl.Init(); err != nil {
		glfw.Terminate()
		return nil, err
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)

	return &Context{window}, nil
}
Exemplo n.º 5
0
func checkMon() {
	monitors = glfw.GetMonitors()
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.AutoIconify, glfw.False)
	glfw.WindowHint(glfw.Decorated, glfw.False)

	if i := len(monitors); i < 2 {
		fmt.Println("You only have 1 monitor!!!!!!!!!!! :-P")
		monWidth = 800
		monHeight = 600

		win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
		if err != nil {
			panic(err)
		}
		projMonitor = monitors[0]
	} else {
		fmt.Printf("You have %d monitors\n", i)
		monWidth = monitors[1].GetVideoMode().Width
		monHeight = monitors[1].GetVideoMode().Height
		win, err = glfw.CreateWindow(monWidth, monHeight, "Cube", nil, nil)
		win.SetPos(monitors[1].GetPos())
		fmt.Printf("Width: %d  Height: %d \n", monWidth, monHeight)
		if err != nil {
			panic(err)
		}
		projMonitor = monitors[1]

	}
	monitorInfo()

}
Exemplo n.º 6
0
func main() {
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	window, err := glfw.CreateWindow(800, 600, "Cube", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	texture = newTexture("square.png")
	defer gl.DeleteTextures(1, &texture)

	setupScene()
	for !window.ShouldClose() {
		drawScene()
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 7
0
func (c *Context) SetResizable(val bool) {
	if val {
		glfw.WindowHint(glfw.Resizable, 1)
	} else {
		glfw.WindowHint(glfw.Resizable, 0)
	}
}
Exemplo n.º 8
0
func main() {

	width := 1024
	height := 768
	title := "Simple Triangle"

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Samples, 4)             // 4x antialiasing
	glfw.WindowHint(glfw.ContextVersionMajor, 3) // We want OpenGL 3.3
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)    // To make MacOS happy; should not be needed
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) //We don't want the old OpenGL
	window, err := glfw.CreateWindow(width, height, title, nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}
	window.SetKeyCallback(keypress)
	window.SetMouseButtonCallback(mousepress)
	gl.Viewport(0, 0, 1024, 768)
	for !window.ShouldClose() {
		draw()
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 9
0
func main() {

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	window, err := glfw.CreateWindow(800, 600, "Create Window Example", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	window.SetKeyCallback(keypress)
	window.SetMouseButtonCallback(mousepress)

	gl.Viewport(0, 0, 800, 600)

	for !window.ShouldClose() {
		draw()
		window.SwapBuffers()
		glfw.PollEvents()
	}

}
Exemplo n.º 10
0
Arquivo: gl.go Projeto: gmacd/rt
func (glr *GlRenderer) initSystem() {
	// Lock goroutine to main thread - required for GL
	runtime.LockOSThread()

	var err error
	if err = glfw.Init(); err != nil {
		panic(err)
	}

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	glr.window, err = glfw.CreateWindow(glr.width, glr.height, "rt", nil, nil)
	if err != nil {
		panic(err)
	}
	glr.window.MakeContextCurrent()

	if err = gl.Init(); err != nil {
		panic(err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)
}
Exemplo n.º 11
0
func main() {
	flag.Parse()

	go func() {
		http.ListenAndServe("localhost:6060", nil)
	}()

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.True)
	glfw.WindowHint(glfw.Visible, glfw.False) // do not steal focus

	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)

	window, err := glfw.CreateWindow(800, 600, "Spector", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.Restore()
	window.SetPos(32, 64)

	if err := gl.Init(); err != nil {
		panic(err)
	}

	state := NewState()
	for !window.ShouldClose() {
		if window.GetKey(glfw.KeyEscape) == glfw.Press {
			return
		}
		if window.GetKey(glfw.KeyR) == glfw.Press {
			state.Stop()
			state = NewState()
		}

		start := time.Now()
		state.Update(1.0 / 60.0)
		updateTime := time.Since(start)

		start = time.Now()
		state.Render(window)
		renderTime := time.Since(start)

		text := fmt.Sprintf("update: %.2fms render: %.2fms",
			float32(updateTime)/float32(time.Millisecond),
			float32(renderTime)/float32(time.Millisecond))
		w, h := window.GetSize()
		state.Backend.SetFontColor(ui.ColorHex(0xFF0000FF))
		size := state.Backend.Measure(text)
		state.Backend.Text(text, ui.Block(float32(w)-size.X, float32(h)-size.Y, size.X, size.Y))

		window.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 12
0
// InitGraphics creates an OpenGL window and initializes the required graphics libraries.
// It will either succeed or panic.
func (app *ExampleApp) InitGraphics(title string, w int, h int) {
	err := glfw.Init()
	if err != nil {
		panic("Can't init glfw! " + err.Error())
	}

	// request a OpenGL 3.3 core context
	glfw.WindowHint(glfw.Samples, 0)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)

	// do the actual window creation
	app.MainWindow, err = glfw.CreateWindow(w, h, title, nil, nil)
	if err != nil {
		panic("Failed to create the main window! " + err.Error())
	}
	app.MainWindow.MakeContextCurrent()
	glfw.SwapInterval(0)

	// make sure that all of the GL functions are initialized
	err = gl.Init()
	if err != nil {
		panic("Failed to initialize GL! " + err.Error())
	}

	// set the app window dimensions
	app.Width = w
	app.Height = h

	gl.FrontFace(gl.CCW)
	gl.CullFace(gl.BACK)
	gl.Enable(gl.CULL_FACE)
}
Exemplo n.º 13
0
func setupWindowOptions() {
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
}
Exemplo n.º 14
0
func (self *Application) run() error {
	if err := glfw.Init(); err != nil {
		return err
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	window, err := glfw.CreateWindow(512, 512, "GL", nil, nil)
	if err != nil {
		return err
	}

	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		return err
	}

	if err := self.setup(); err != nil {
		return err
	}

	for !window.ShouldClose() {
		self.display()
		window.SwapBuffers()
		glfw.PollEvents()
	}

	return nil
}
Exemplo n.º 15
0
func Init() {
	runtime.LockOSThread()

	err := glfw.Init()
	if err != nil {
		panic(fmt.Sprintf("glfw.Init() fails: %v", err))
	}
	glfw.WindowHint(glfw.Visible, glfw.False)
	glfw.WindowHint(glfw.Resizable, glfw.False)

	// As start, create an window with temporary size to create OpenGL context thread.
	window, err := glfw.CreateWindow(16, 16, "", nil, nil)
	if err != nil {
		panic(err)
	}

	u := &userInterface{
		window: window,
		funcs:  make(chan func()),
	}
	go func() {
		runtime.LockOSThread()
		u.window.MakeContextCurrent()
		glfw.SwapInterval(1)
		for f := range u.funcs {
			f()
		}
	}()

	currentUI = u
}
Exemplo n.º 16
0
func CreateRenderer(windowWidth, windowHeight int) *Renderer {

	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	// defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	if windowWidth == 0 && windowHeight == 0 {
		windowWidth, windowHeight = glfw.GetPrimaryMonitor().GetPhysicalSize()
	}
	fmt.Println("Window Width -", windowWidth, "Window Height -", windowHeight)
	window, err := glfw.CreateWindow(windowWidth, windowHeight, "Karma", glfw.GetPrimaryMonitor(), nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.SetKeyCallback(testCallback)

	// Initialize Glow
	if err := gl.Init(); err != nil {
		panic(err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	fmt.Println("OpenGL version", version)

	shaders := Shaders{}

	textureFlatUniforms := []string{"projection", "camera", "modelView", "tex"}
	textureFlatAttributes := []string{"vert", "vertTexCoord"}

	fmt.Println(textureFlatUniforms)
	fmt.Println(textureFlatAttributes)

	shader, err := createProgram("./assets/shaders/texture_flat.vs", "./assets/shaders/texture_flat.fs", textureFlatUniforms, textureFlatAttributes)
	if err != nil {
		panic(err)
	}
	shaders.textureFlat = shader

	meshes := []*Mesh{}

	previousTime := glfw.GetTime()

	return &Renderer{
		PreviousTime: previousTime,
		Window:       window,
		Shaders:      &shaders,
		Meshes:       meshes,
	}
}
Exemplo n.º 17
0
func main() {
	err := glfw.Init()
	if err != nil {
		panic(err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.True)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)

	window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()

	window.MakeContextCurrent()

	glfw.SwapInterval(1)

	window.SetSizeCallback(func(w *glfw.Window, width int, height int) {
		fmt.Printf("resize: %d, %d\n", width, height)
		gl.Viewport(0, 0, int32(width), int32(height))
	})
	window.SetCursorPosCallback(func(w *glfw.Window, xpos float64, ypos float64) {
		fmt.Printf("mouse: %f, %f\n", xpos, ypos)
	})
	window.SetFocusCallback(func(w *glfw.Window, focused bool) {
		fmt.Printf("focus: %t\n", focused)
	})
	window.SetKeyCallback(func(w *glfw.Window, key glfw.Key, scancode int, action glfw.Action, mods glfw.ModifierKey) {
		if key == glfw.KeyEscape {
			window.SetShouldClose(true)
		}
		fmt.Printf("key\n")
	})
	window.SetMouseButtonCallback(func(w *glfw.Window, button glfw.MouseButton, action glfw.Action, mod glfw.ModifierKey) {
		fmt.Printf("mouse\n")
	})
	window.SetCharCallback(func(w *glfw.Window, char rune) {
		fmt.Printf("char: '%c'\n", char)
	})

	if err := gl.Init(); err != nil {
		panic(err)
	}

	for !window.ShouldClose() {
		draw()
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
Exemplo n.º 18
0
func main() {
	flag.Parse()

	if *filename == "REQUIRED" {
		print("You must include a filename to load. See --help.\n")
		os.Exit(-2)
	}

	runtime.LockOSThread()
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to initialize glfw:", err)
	}
	defer glfw.Terminate()

    	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	window, err := glfw.CreateWindow(640, 320, "chip8", nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()

	if err := gl.Init(); err != nil {
		panic(err)
	}

	gl.ClearColor(0, 0, 0, 0)
	gl.MatrixMode(gl.PROJECTION)

	gl.Ortho(0, 64, 32, 0, 0, 1)

	myChip8.initialize()

	myChip8.loadGame(*filename)

	for !window.ShouldClose() {

		myChip8.emulateCycle(window)

		if(myChip8.drawFlag) {
			myChip8.drawGraphics()
      		window.SwapBuffers()
			time.Sleep(0 * time.Millisecond)
		}

        glfw.PollEvents()
		myChip8.setKeys(window);
	} 
}
Exemplo n.º 19
0
func initGraphics() error {
	if err := gl.Init(); err != nil {
		return err
	}

	if err := glfw.Init(); err != nil {
		return err
	}

	glfw.WindowHint(glfw.Resizable, glfw.False)

	var err error
	window, err = glfw.CreateWindow(64*scaleRatio, 32*scaleRatio, "CHIP-8 Emulator", nil, nil)

	if err != nil {
		return err
	}

	window.MakeContextCurrent()

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, 64, 32, 0, 0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	clear()
	window.SwapBuffers()

	return nil
}
Exemplo n.º 20
0
func initialize() (*opengl.Context, error) {
	runtime.LockOSThread()

	if err := glfw.Init(); err != nil {
		return nil, err
	}
	glfw.WindowHint(glfw.Visible, glfw.False)
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)

	// As start, create an window with temporary size to create OpenGL context thread.
	window, err := glfw.CreateWindow(16, 16, "", nil, nil)
	if err != nil {
		return nil, err
	}

	u := &userInterface{
		window:      window,
		funcs:       make(chan func()),
		sizeChanged: true,
	}
	ch := make(chan error)
	go func() {
		runtime.LockOSThread()
		u.window.MakeContextCurrent()
		glfw.SwapInterval(1)
		var err error
		u.context, err = opengl.NewContext()
		if err != nil {
			ch <- err
		}
		close(ch)
		u.context.Loop()
	}()
	currentUI = u
	if err := <-ch; err != nil {
		return nil, err
	}
	if err := u.context.Init(); err != nil {
		return nil, err
	}

	return u.context, nil
}
Exemplo n.º 21
0
func setWindowHints() {
	// glfw.WindowHint(glfw.Samples, 4)
	// // Create a context to specify the version of OpenGl to 3.3
	// glfw.WindowHint(glfw.ContextVersionMajor, 3)
	// glfw.WindowHint(glfw.ContextVersionMinor, 3)
	// Disable window resize
	glfw.WindowHint(glfw.Resizable, 0)
	// Following two are needed for mac since it by default uses OpenGl 2.2
	// glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile) // remove any deprecated code from older version
	// glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True)
}
Exemplo n.º 22
0
// createWindow initializes the graphics libraries and creates the main window for the game.
// it pulls the settings for the window from the options structure passed in.
func createWindow(options *Options) (*glfw.Window, error) {
	// GLFW must be initialized before it's called
	err := glfw.Init()
	if err != nil {
		return nil, fmt.Errorf("Can't init glfw! %v", err)
	}

	// request a OpenGL 3.3 core context
	glfw.WindowHint(glfw.Samples, 0)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)

	// do the actual window creation
	mainWindow, err := glfw.CreateWindow(options.WindowWidth, options.WindowHeight, appWindowName, nil, nil)
	if err != nil {
		return nil, fmt.Errorf("Failed to create the main window! %v", err)
	}

	mainWindow.MakeContextCurrent()

	// set vsync options
	if options.VSyncEnabled {
		glfw.SwapInterval(1)
	} else {
		glfw.SwapInterval(0)
	}

	// make sure that all of the GL functions are initialized
	err = gl.Init()
	if err != nil {
		return nil, fmt.Errorf("Can't init gl! %v", err)
	}

	// write out the gl version for debug purposes
	version := gl.GoStr(gl.GetString(gl.VERSION))
	groggy.Log("INFO", "OpenGL version ", version)

	return mainWindow, nil
}
Exemplo n.º 23
0
//
// set OpenGl Version
// Sets the openGL version to the window
//
func setOpenGlVersion() {
	glfw.WindowHint(glfw.Samples, 4)             // Anti Aliasing (16 for nice Screenshots)
	glfw.WindowHint(glfw.ContextVersionMajor, 3) // Mac will use the latest available, even if 3.3 is selected
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)    // Necessary for OS X (This removes any deprecated API in 4.1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // Necessary for OS X
	glfw.WindowHint(glfw.OpenGLDebugContext, glfw.False)

	glfw.WindowHint(glfw.Resizable, glfw.True)
}
Exemplo n.º 24
0
func createWindow() *glfw.Window {
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	window, err := glfw.CreateWindow(windowWidth, windowHeight, "Frame Assault", nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()
	window.SetKeyCallback(onKey)
	window.SetMouseButtonCallback(onMouseButton)
	window.SetCloseCallback(onClose)
	window.SetScrollCallback(onScroll)
	window.SetCursorPosCallback(onCursorPos)

	return window
}
Exemplo n.º 25
0
Arquivo: grid.go Projeto: vinzBad/grid
func Run(g *Game) error {
	if g.Scene == nil {
		return fmt.Errorf("Scene property of given Game struct is empty")
	}

	// GLFW event handling must run on the main OS thread
	runtime.LockOSThread()
	if err := glfw.Init(); err != nil {
		return fmt.Errorf("glfw.Init failed: %s", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.ContextVersionMajor, OpenGLVerMinor)
	glfw.WindowHint(glfw.ContextVersionMinor, OpenGLVerMinor)

	glfw.WindowHint(glfw.Resizable, glfw.False)
	if g.Resizable {
		glfw.WindowHint(glfw.Resizable, glfw.True)
	}

	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	window, err := glfw.CreateWindow(int(g.Width), int(g.Height), g.Title, nil, nil)
	if err != nil {
		return fmt.Errorf("glfw.CreateWindow failed: %s", err)
	}
	window.MakeContextCurrent()

	// Initialize Glow
	if err := gl.Init(); err != nil {
		return fmt.Errorf("gl.Init failed:", err)
	}

	version := gl.GoStr(gl.GetString(gl.VERSION))
	log.Println("gl.Init successful, OpenGL version:", version)

	var previousTime, deltaTime, time float32
	previousTime = float32(glfw.GetTime()) - 1.0/60.0

	g.Scene.Setup()

	for !window.ShouldClose() {
		time = float32(glfw.GetTime())
		deltaTime = time - previousTime

		glfw.PollEvents()

		gl.ClearColor(0.2, 0.3, 0.3, 0.5)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		g.Scene.Update(deltaTime)
		g.Scene.Draw(deltaTime)
		previousTime = time

		window.SwapBuffers()
	}

	return nil
}
Exemplo n.º 26
0
func headlessContext() {
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)    // Necessary for OS X
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // Necessary for OS X
	glfw.WindowHint(glfw.OpenGLDebugContext, glfw.True)
	glfw.WindowHint(glfw.Visible, glfw.False)
}
Exemplo n.º 27
0
func CreateWindow(title string, width int, height int) *Window {
	if err := glfw.Init(); err != nil {
		log.Fatalln("Failed to initialize glfw:", err)
	}

	/* GLFW Window settings */
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	window, err := glfw.CreateWindow(width, height, title, nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	glfw.SwapInterval(2)

	/* Initialize OpenGL */
	if err := gl.Init(); err != nil {
		panic(err)
	}

	window.SetInputMode(glfw.CursorMode, glfw.CursorDisabled)
	window.SetKeyCallback(KeyCallback)
	window.SetCursorPosCallback(MouseMoveCallback)
	window.SetMouseButtonCallback(MouseButtonCallback)

	w := &Window{
		Width:         width,
		Height:        height,
		Wnd:           window,
		maxFrameTime:  0.0,
		lastFrameTime: glfw.GetTime(),
	}
	w.SetMaxFps(60)
	return w
}
Exemplo n.º 28
0
// Initializing the game and set of assets.
func initialize() (*glfw.Window, *Assets, error) {
	if err := glfw.Init(); err != nil {
		return nil, nil, err
	}

	// Setting up a bunch of windowing stuff with GLFW.
	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)

	// Creating GLFW.
	window, err := glfw.CreateWindow(640, 480, "Testing", nil, nil)
	if err != nil {
		return nil, nil, err
	}

	// Creating OpenGL.
	window.MakeContextCurrent()
	if err := gl.Init(); err != nil {
		return nil, nil, err
	}
	gl.ClearColor(0.3, 0.3, 0.3, 1.0)

	if config.DebugMode {
		version := gl.GoStr(gl.GetString(gl.VERSION))
		fmt.Println("Running on OpenGL: " + version)
	}

	// Loading assets.
	assets, err := NewAssets([]string{"res/shaders/texrenderer"}, []string{"res/textures/texture.jpg"})
	if err != nil {
		return nil, nil, err
	}

	return window, assets, nil
}
Exemplo n.º 29
0
func main() {
	if err := glfw.Init(); err != nil {
		log.Fatalln("failed to inifitialize glfw:", err)
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Resizable, glfw.False)
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)
	window, err := glfw.CreateWindow(windowWidth, windowHeight, "Hello!", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	// Initialize Glow (go function bindings)
	if err := gl.Init(); err != nil {
		panic(err)
	}

	window.SetKeyCallback(keyCallback)

	// program loop
	for !window.ShouldClose() {
		// poll events and call their registered callbacks
		glfw.PollEvents()

		// perform rendering
		gl.ClearColor(0.2, 0.5, 0.5, 1.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		// swap in the rendered buffer
		window.SwapBuffers()
	}
}
Exemplo n.º 30
0
func setOpenGlVersion() {
	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenGLForwardCompatible, glfw.True)    // Necessary for OS X
	glfw.WindowHint(glfw.OpenGLProfile, glfw.OpenGLCoreProfile) // Necessary for OS X
	glfw.WindowHint(glfw.OpenGLDebugContext, glfw.True)

	glfw.WindowHint(glfw.Resizable, glfw.True)
}