示例#1
0
文件: main.go 项目: krux02/mathgl
func main() {
	runtime.LockOSThread()

	if !glfw.Init() {
		fmt.Fprintf(os.Stderr, "Can't open GLFW")
		return
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.Samples, 4)
	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
	glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True) // needed for macs

	window, err := glfw.CreateWindow(1024, 768, "Tutorial 1", nil, nil)
	if err != nil {
		fmt.Fprintf(os.Stderr, "%v\n", err)
		return
	}

	window.MakeContextCurrent()

	gl.Init()
	gl.GetError() // Ignore error
	window.SetInputMode(glfw.StickyKeys, 1)

	gl.ClearColor(0., 0., 0.4, 0.)
	// Equivalent to a do... while
	for ok := true; ok; ok = (window.GetKey(glfw.KeyEscape) != glfw.Press && !window.ShouldClose()) {
		window.SwapBuffers()
		glfw.PollEvents()
	}

}
示例#2
0
文件: glfw.go 项目: kunos/tutorials
func main() {
	fmt.Println("Init GLFW3")
	if glfw3.Init() {
		fmt.Println("Init ok")
		defer closeGLFW()
	}

	// Create the window
	fmt.Println("Opening window")
	win, err := glfw3.CreateWindow(1024, 768, "Kunos Rulez", nil, nil)
	gl.Init()
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("ok", win)
	}

	win.MakeContextCurrent()

	for win.ShouldClose() == false {
		glfw3.PollEvents()
		gl.ClearColor(1.0, 0.0, 0.0, 1.0)
		gl.Clear(gl.COLOR_BUFFER_BIT)

		win.SwapBuffers()
	}

	fmt.Println("Destroying win")
	win.Destroy()
}
示例#3
0
文件: main.go 项目: andrebq/exp
func main() {
	glfw.SetErrorCallback(glfwError)

	if !glfw.Init() {
		log.Printf("Unable to initializer glfw")
		return
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()
	window.SetSizeCallback(fixProjection)

	err = initGL()
	if err != nil {
		log.Printf("Error initializing OpenGL. %v", err)
		panic(err)
	}

	glfw.SwapInterval(1)
	fixProjection(window, Width, Height)

	meshBuff := createMeshBuffer()

	for !window.ShouldClose() {
		timeDelta.Tick()
		log.Printf("Time: %v", timeDelta.Delta)
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
示例#4
0
文件: main.go 项目: srm88/blocks
func main() {
	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw")
	}
	defer glfw.Terminate()

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

	window.MakeContextCurrent()
	window.SetSizeCallback(copiedReshape)
	window.SetKeyCallback(keyHandler)

	copiedInit()
	running := true
	for running && !window.ShouldClose() {
		//copiedDrawCube(angle)
		redraw()
		window.SwapBuffers()
		glfw.PollEvents()
		running = window.GetKey(glfw.KeyEscape) == glfw.Release
	}
}
示例#5
0
文件: gopher.go 项目: nzlov/examples
func main() {
	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()

	glfw.SwapInterval(1)

	gl.Init()

	if err := initScene(); err != nil {
		fmt.Fprintf(os.Stderr, "init: %s\n", err)
		return
	}
	defer destroyScene()

	for !window.ShouldClose() {
		drawScene()
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
示例#6
0
文件: window.go 项目: joonazan/sprite
func OpenWindow(width, height int, caption string) *glfw.Window {
	// OpenGL haluaa että sitä käytetään aina samasta threadista
	// muuten tulee satunnaisia segfaultteja
	runtime.LockOSThread()

	glfw.Init()

	// luodaan ikkuna
	w, err := glfw.CreateWindow(width, height, caption, nil, nil)
	if err != nil {
		log.Fatal(err)
	}
	w.MakeContextCurrent()

	gl.Init()

	// Jotta painalluksista kerrottaisiin vaikka ne olisivat jo päättyneet
	w.SetInputMode(glfw.StickyKeys, glfw.True)
	w.SetInputMode(glfw.StickyMouseButtons, glfw.True)

	// läpinäkyvyys päälle (non-premultiplied alpha)
	gl.Enable(gl.BLEND)
	gl.BlendEquationSeparate(gl.FUNC_ADD, gl.FUNC_ADD)
	gl.BlendFuncSeparate(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA, gl.ONE, gl.ZERO)

	return w
}
示例#7
0
func main() {
	glfw.SetErrorCallback(glfwErrorCallback)
	if !glfw.Init() {
		panic("failed to initialize glfw")
	}
	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()
	}
}
示例#8
0
文件: ctx.go 项目: go3d/go-ngine
func (me *context) Window(winf *ngctx.WinProfile, bufSize *ngctx.BufferBits, ctxProf *ngctx.CtxProfile) (window ngctx.Window, err error) {
	glfw.WindowHint(glfw.Samples, winf.MultiSampling)
	glfw.WindowHint(glfw.RedBits, bufSize.Color.R)
	glfw.WindowHint(glfw.GreenBits, bufSize.Color.G)
	glfw.WindowHint(glfw.BlueBits, bufSize.Color.B)
	glfw.WindowHint(glfw.AlphaBits, bufSize.Color.A)
	glfw.WindowHint(glfw.DepthBits, bufSize.Depth)
	glfw.WindowHint(glfw.StencilBits, bufSize.Stencil)
	glfw.WindowHint(glfw.ContextVersionMajor, ctxProf.Version.Major)
	glfw.WindowHint(glfw.ContextVersionMinor, ctxProf.Version.Minor)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
	if ctxProf.ForwardCompat {
		glfw.WindowHint(glfw.OpenglForwardCompatible, 1)
	}
	var mon *glfw.Monitor
	if winf.FullScreen {
		mon, err = glfw.GetPrimaryMonitor()
	}
	if err == nil {
		var win *glfw.Window
		if win, err = glfw.CreateWindow(winf.Width, winf.Height, winf.Title, mon, nil); win != nil {
			window = newWindow(win)
			if winf.FullScreen {
				win.SetInputMode(glfw.Cursor, glfw.CursorHidden)
			}
		}
	}
	return
}
示例#9
0
func RunIn3DContext(example func()) {
	if !glfw.Init() {
		log.Panic("glfw Error")
	}
	defer glfw.Terminate()

	glfw.WindowHint(glfw.ContextVersionMajor, 3)
	glfw.WindowHint(glfw.ContextVersionMinor, 3)
	glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)

	w, h := 100, 100
	window, err := glfw.CreateWindow(w, h, "Test", nil, nil)
	if err != nil {
		log.Panic(err)
	}
	window.MakeContextCurrent()

	if gl.Init() != 0 {
		log.Panic("gl error")
	}
	gl.GetError()

	vertexArray := gl.GenVertexArray()
	vertexArray.Bind()

	example()
}
示例#10
0
文件: runner.go 项目: kebo/gorgasm
func main() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	defer glfw.Terminate()

	gorgasm.Verbose = true

	if !glfw.Init() {
		panic("Can't init glfw!")
	}

	// Enable OpenGL ES 2.0.
	glfw.WindowHint(glfw.ClientApi, glfw.OpenglEsApi)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	window, err := glfw.CreateWindow(testlib.Width, testlib.Height, "Gorgasm Test", nil, nil)
	if err != nil {
		panic(err)
	}

	gorgasm.Init(window)

	go prettytest.Run(new(testing.T), testlib.NewTestSuite())

	for !window.ShouldClose() {
		glfw.WaitEvents()
	}
}
示例#11
0
func main() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()
	defer glfw.Terminate()

	mandala.Verbose = true

	if !glfw.Init() {
		panic("Can't init glfw!")
	}

	// Enable OpenGL ES 2.0.
	glfw.WindowHint(glfw.ClientApi, glfw.OpenglEsApi)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	window, err := glfw.CreateWindow(Width, Height, "gltext black-box testing", nil, nil)
	if err != nil {
		panic(err)
	}

	glfw.SwapInterval(0)
	mandala.Init(window)

	go prettytest.Run(new(testing.T), testlib.NewTestSuite(outputPath))

	for !window.ShouldClose() {
		glfw.WaitEvents()
	}
}
示例#12
0
// Initialize creates new window
func (e *E) Initialize(title string, params Params, state State) error {
	if !glfw3.Init() {
		return fmt.Errorf("unable to initialize glfw")
	}
	if e.window != nil {
		return fmt.Errorf("Initialize error: window is not nil")
	}

	glfw3.SetErrorCallback(OnError)

	glfw3.WindowHint(glfw3.Resizable, glfw3.True)
	glfw3.WindowHint(glfw3.ContextVersionMajor, params.Version[0])
	glfw3.WindowHint(glfw3.ContextVersionMinor, params.Version[1])
	glfw3.WindowHint(glfw3.OpenglProfile, glfw3.OpenglCoreProfile)
	glfw3.WindowHint(glfw3.OpenglDebugContext, glfw3.True)

	size := params.Size
	window, err := glfw3.CreateWindow(size[0], size[1], title, nil, nil)
	if err != nil {
		return err
	}

	window.MakeContextCurrent()
	window.SetKeyCallback(e.OnKey)
	window.SetFramebufferSizeCallback(e.OnFramebufferResize)

	e.window = window
	e.state = state

	return nil
}
示例#13
0
func main() {

	if !glfw.Init() {
		log.Fatal("glfw failed to initialize")
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(640, 480, "Deformable", nil, nil)
	if err != nil {
		log.Fatal(err.Error())
	}

	window.MakeContextCurrent()
	glfw.SwapInterval(1)
	window.SetMouseButtonCallback(handleMouseButton)
	window.SetKeyCallback(handleKeyDown)
	window.SetInputMode(glfw.Cursor, glfw.CursorHidden)

	gl.Init()
	initGL()

	i := 16
	m = GenerateMap(1600/i, 1200/i, i)
	for running && !window.ShouldClose() {

		x, y := window.GetCursorPosition()

		if drawing != 0 {
			m.Add(int(x)+int(camera[0]), int(y)+int(camera[1]), drawing, brushSizes[currentBrushSize])
		}

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.LoadIdentity()

		gl.PushMatrix()
		gl.PushAttrib(gl.CURRENT_BIT | gl.ENABLE_BIT | gl.LIGHTING_BIT | gl.POLYGON_BIT | gl.LINE_BIT)
		gl.Translatef(-camera[0], -camera[1], 0)
		m.Draw()
		gl.PopAttrib()
		gl.PopMatrix()

		gl.PushAttrib(gl.COLOR_BUFFER_BIT)
		gl.LineWidth(2)
		gl.Enable(gl.BLEND)
		gl.BlendFunc(gl.ONE_MINUS_DST_COLOR, gl.ZERO)
		// gl.Enable(gl.LINE_SMOOTH)
		// gl.Hint(gl.LINE_SMOOTH_HINT, gl.NICEST)

		gl.Translatef(float32(x), float32(y), 0)

		gl.EnableClientState(gl.VERTEX_ARRAY)
		gl.VertexPointer(2, gl.DOUBLE, 0, cursorVerts)
		gl.DrawArrays(gl.LINE_LOOP, 0, 24)
		gl.PopAttrib()

		window.SwapBuffers()
		glfw.PollEvents()
	}

}
示例#14
0
文件: main.go 项目: andrebq/exp
func main() {
	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

	window, err := glfw.CreateWindow(800, 640, "MyGui", nil, nil)
	if err != nil {
		panic(err)
	}
	window.MakeContextCurrent()

	glfw.SwapInterval(1)
	gl.Init()

	mvp := prepareModelViewProjection(800, 640)

	prepareScene()
	dt := float64(0)
	glfw.SetTime(dt)

	for !window.ShouldClose() {
		dt = glfw.GetTime()
		glfw.SetTime(0)
		updateScene(dt)
		drawScene(mvp, dt)
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
示例#15
0
func main() {
	_ = fmt.Sprint()

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

	// antialiasing
	//glfw.WindowHint(glfw.Samples, 4)

	window, err = glfw.CreateWindow(WindowWidth, WindowHeight, "Mozaik", nil, nil)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()

	// Ensure thread context
	window.MakeContextCurrent()
	//glfw.SwapInterval(1)

	window.SetKeyCallback(keyCb)
	window.SetMouseButtonCallback(mouseCb)

	gl.Init()
	gl.ClearColor(0.9, 0.85, 0.46, 0.0)
	// useless in 2D
	gl.Disable(gl.DEPTH_TEST)
	// antialiasing
	gl.Enable(gl.BLEND)
	gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA)
	gl.Enable(gl.LINE_SMOOTH)

	for i := int32(32); i < 72; i++ {
		font := loadFonts(i)
		defer font.Release()
		fonts = append(fonts, font)
	}

	// Compute window radius
	windowRadius = math.Sqrt(math.Pow(WindowHeight, 2) + math.Pow(WindowWidth, 2))

	// Use window coordinates
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, WindowWidth, WindowHeight, 0, 0, 1)
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	g = NewGame()

	g.Start()
	go eventLoop(g)
	go renderLoop(g)
	Main()
	g.Stop()
}
示例#16
0
func initWindow() (window *glfw.Window, err error) {
	monitor, err := glfw.GetPrimaryMonitor()
	if err != nil {
		return nil, err
	}
	videomode, err := monitor.GetVideoMode()
	if err != nil {
		return nil, err
	}
	if videomode.Height < 480 || videomode.Width < 640 {
		return nil, errors.New("unsupported resolution!")
	}

	ratio := float64(videomode.Width) / float64(videomode.Height)

	if fullscreen {
		glfw.WindowHint(glfw.Decorated, 0)
		window, err = glfw.CreateWindow(videomode.Width, videomode.Height, "Golang Asteroids!", nil, nil)
		if err != nil {
			return nil, err
		}
		window.SetPosition(0, 0)
	} else {
		glfw.WindowHint(glfw.Decorated, 1)
		window, err = glfw.CreateWindow(int(ratio*480), 480, "Golang Asteroids!", nil, nil)
		if err != nil {
			return nil, err
		}
		window.SetPosition(videomode.Width/2-320, videomode.Height/2-240)
	}

	window.SetKeyCallback(keyCallback)
	window.SetFramebufferSizeCallback(reshapeWindow)
	window.MakeContextCurrent()

	gl.Init()
	gl.ClearColor(gl.GLclampf(Colorize(0)), gl.GLclampf(Colorize(0)), gl.GLclampf(Colorize(0)), 0.0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	width, height := window.GetFramebufferSize()
	reshapeWindow(window, width, height)

	return window, nil
}
func (self *OpenGLWindow) Open() {
	var err error
	if !glfw.Init() {
		panic(errors.New("Unable to initialize GLFW"))
	}

	glfw.SetErrorCallback(func(code glfw.ErrorCode, desc string) {
		log.Printf("[GLFW Error] (%d) %s", code, desc)
	})

	var monitor *glfw.Monitor
	if self.config.Fullscreen {
		monitor, err = glfw.GetPrimaryMonitor()

		if err != nil {
			panic(err)
		}
	}

	glfw.WindowHint(glfw.ContextVersionMajor, 4)
	glfw.WindowHint(glfw.ContextVersionMinor, 1)
	glfw.WindowHint(glfw.OpenglProfile, glfw.OpenglCoreProfile)
	glfw.WindowHint(glfw.OpenglForwardCompatible, glfw.True)

	// Default buffer sizes
	glfw.WindowHint(glfw.DepthBits, 32)
	glfw.WindowHint(glfw.StencilBits, 0)

	// Toggle VSync. Turning VSync off aparently doesn't work via glfw through
	// some ATI cards and drivers
	if self.config.VSync {
		glfw.SwapInterval(1)
	} else {
		glfw.SwapInterval(0)
	}

	self.window, err = glfw.CreateWindow(
		int(self.config.Width), int(self.config.Height),
		"Project Slartibartfast",
		monitor,
		nil)

	if err != nil {
		panic(err)
	}

	self.window.MakeContextCurrent()

	if glewError := gl.Init(); glewError != 0 {
		panic(errors.New("Unable to initialize OpenGL"))
	}
}
示例#18
0
文件: window.go 项目: phaikawl/gosui
//NewWindow creates and return a new Window
func NewWindow(b RenderBackend, w, h int, title string) *Window {
	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw!")
	}

	window, err := glfw.CreateWindow(w, h, title, nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()
	b.Init(w, h)
	setupGL(w, h)

	return &Window{window, b, gs.NewRootElement()}
}
示例#19
0
文件: glfw.go 项目: james4k/exp
// Open opens a new OS window via GLFW.
func Open(width, height int, title string) (*Window, error) {
	var wnd *glfw3.Window
	errc := make(chan error)
	mainc <- func() {
		var err error
		wnd, err = glfw3.CreateWindow(width, height, title, nil, nil)
		errc <- err
		if err == nil {
			wnd.SetInputMode(glfw3.Cursor, glfw3.CursorNormal)
			wnd.Restore()
		}
	}
	err := <-errc
	if err != nil {
		return nil, err
	}
	return openFromWindow(wnd)
}
示例#20
0
文件: main.go 项目: james4k/gfx
func main() {
	runtime.LockOSThread()

	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

	// must be done in main thread or we get a nasty stderr message from glfw,
	// although it does seem to 'work'
	window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
	if err != nil {
		panic(err)
	}

	// separate thread for drawing so that we don't block on the event thread.
	// most obvious benefit is that we continue to render during window
	// resizes.
	go func() {
		runtime.LockOSThread()

		window.MakeContextCurrent()
		glfw.SwapInterval(1)
		gl.Init()
		if err := initScene(); err != nil {
			fmt.Fprintf(os.Stderr, "init: %s\n", err)
			return
		}

		for !window.ShouldClose() {
			drawScene()
			window.SwapBuffers()
		}
		os.Exit(0)
	}()

	for {
		glfw.WaitEvents()
	}
}
示例#21
0
func (a *Application) init() {
	glfw.SetErrorCallback(a.glfwError)
	if !glfw.Init() {
		os.Exit(1)
	}

	a.Width = 1280
	a.Height = 720
	a.Title = filepath.Base(os.Args[0])

	// For now, force a fixed size window. bgfx currently breaks glfw
	// events on OS X because it overrides the NSWindow's content view.
	glfw.WindowHint(glfw.Resizable, 0)
	var err error
	a.window, err = glfw.CreateWindow(a.Width, a.Height, a.Title, nil, nil)
	if err != nil {
		log.Fatalln(err)
	}
	bgfx_glfw.SetWindow(a.window)
}
示例#22
0
func main() {
	if !glfw.Init() {
		f.Println("Failed to init glfw")
		panic("Cannot initialize glfw library")
	}
	defer glfw.Terminate()

	//glfw.WindowHint(glfw.DepthBits, 16)
	window, err := glfw.CreateWindow(300, 300, "Wander", nil, nil)
	if err != nil {
		panic(err)
	}

	window.SetFramebufferSizeCallback(reshape)
	window.SetKeyCallback(key)
	window.MakeContextCurrent()
	glfw.SwapInterval(1)
	width, height := window.GetFramebufferSize()
	reshape(window, width, height)

	if gl.Init() != 0 {
		panic("Failed to init GL")
	}

	prog := setupProgram()
	defer prog.Delete()
	prog.Use()

	attr = prog.GetAttribLocation("offset")

	setup()
	for !window.ShouldClose() {
		if shouldRender() {
			draw()
		}
		animate()
		window.SwapBuffers()
		glfw.PollEvents()
	}

}
示例#23
0
文件: glfw.go 项目: james4k/exp
// New creates a new OS window via GLFW as a ui.Environment.
func New(width, height int, title string) (ui.Environment, error) {
	var wnd *glfw.Window
	errc := make(chan error)
	mainc <- func() {
		var err error
		wnd, err = glfw.CreateWindow(width, height, title, nil, nil)
		errc <- err
		if err == nil {
			wnd.SetInputMode(glfw.Cursor, glfw.CursorNormal)
		}
	}
	err := <-errc
	if err != nil {
		return nil, err
	}
	w := &env{
		Window: wnd,
	}
	w.init()
	return w, nil
}
示例#24
0
func main() {
	glfw.SetErrorCallback(errorCallback)

	if !glfw.Init() {
		panic("Can't init glfw!")
	}
	defer glfw.Terminate()

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

	window.MakeContextCurrent()

	for !window.ShouldClose() {
		//Do OpenGL stuff
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
示例#25
0
// initGL initializes GLFW and OpenGL.
func initGL() (*glfw.Window, error) {
	if !glfw.Init() {
		log.Panic("glfw Error:")
	}

	var err error
	window, err = glfw.CreateWindow(768, 768, "My Own Shadertoy", nil, nil)
	if err != nil {
		glfw.Terminate()
		return nil, err
	}

	window.MakeContextCurrent()

	window.SetSizeCallback(onResize)

	window.SetKeyCallback(onKey)
	window.SetMouseButtonCallback(onMouse)
	window.SetCursorPositionCallback(onCursor)

	errno := gl.Init()
	if errno != gl.NO_ERROR {
		str, err := glu.ErrorString(errno)
		if err != nil {
			return nil, fmt.Errorf("Unknown openGL error: %d", errno)
		}
		return nil, fmt.Errorf(str)
	}

	gl.Enable(gl.TEXTURE_1D)
	gl.Enable(gl.TEXTURE_2D)
	gl.Enable(gl.TEXTURE_3D)

	fmt.Printf("gl.RENDERER   = %s\n", gl.GetString(gl.RENDERER))
	fmt.Printf("gl.VERSION    = %s\n", gl.GetString(gl.VERSION))
	fmt.Printf("gl.VENDOR     = %s\n", gl.GetString(gl.VENDOR))
	fmt.Printf("gl.EXTENSIONS = %s\n", gl.GetString(gl.EXTENSIONS))

	return window, nil
}
示例#26
0
func RunGamehost() {
	if !glfw.Init() {
		panic("Cannot init GLFW")
	}

	defer glfw.Terminate()

	window, err := glfw.CreateWindow(800, 600, "Apollo", nil, nil)
	if err != nil {
		panic(err)
	}

	window.MakeContextCurrent()
	gamehost_Window = window

	gl.ClearColor(1, 1, 1, 1)
	glu.LookAt(0, 1.5, 5, 0, 0, 0, 0, 1, 0)
	frame := 0

	EvaluateString("(trigger GAMEHOST Init!)", MainContext)

	gamehost_world.Create(CreateCube(0, 0, 0))

	for !gamehost_Window.ShouldClose() {
		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.LoadIdentity()
		gamehost_Window.SetTitle(fmt.Sprintf("Frame #%v", frame))
		frame++

		EvaluateString("(gameloop 0.016)", MainContext)

		gamehost_world.Render()
		graphicsQueue.Process()

		gamehost_Window.SwapBuffers()
		glfw.PollEvents()
	}

	EvaluateString("(trigger GAMEHOST Shutdown!)", MainContext)
}
示例#27
0
文件: gears.go 项目: nzlov/examples
func main() {
	if !glfw.Init() {
		panic("Failed to initialize GLFW")
	}

	defer glfw.Terminate()

	glfw.WindowHint(glfw.DepthBits, 16)

	window, err := glfw.CreateWindow(300, 300, "Gears", nil, nil)
	if err != nil {
		panic(err)
	}

	// Set callback functions
	window.SetFramebufferSizeCallback(reshape)
	window.SetKeyCallback(key)

	window.MakeContextCurrent()
	glfw.SwapInterval(1)

	width, height := window.GetFramebufferSize()
	reshape(window, width, height)

	// Parse command-line options
	Init()

	// Main loop
	for !window.ShouldClose() {
		// Draw gears
		draw()

		// Update animation
		animate()

		// Swap buffers
		window.SwapBuffers()
		glfw.PollEvents()
	}
}
示例#28
0
func main() {
	// initialize glfw
	if !glfw.Init() {
		panic("Failed to initialize GLFW")
	}
	defer glfw.Terminate()

	// create window
	window, err := glfw.CreateWindow(600, 600, os.Args[0], nil, nil)
	if err != nil {
		panic(err)
	}
	window.SetFramebufferSizeCallback(onResize)

	window.MakeContextCurrent()
	// set up opengl context
	onResize(window, 600, 600)

	// set up physics
	createBodies()

	runtime.LockOSThread()
	glfw.SwapInterval(1)

	ticksToNextBall := 10
	ticker := time.NewTicker(time.Second / 60)
	for !window.ShouldClose() {
		ticksToNextBall--
		if ticksToNextBall == 0 {
			ticksToNextBall = rand.Intn(100) + 1
			addBall()
		}
		draw()
		step(1.0 / 60.0)
		window.SwapBuffers()
		glfw.PollEvents()

		<-ticker.C // wait up to 1/60th of a second
	}
}
示例#29
0
func main() {
	flag.Parse()
	glfw.SetErrorCallback(errorCallback)
	if !glfw.Init() {
		println("glfw init failure")
	}
	defer glfw.Terminate()
	glfw.WindowHint(glfw.ClientApi, glfw.OpenglEsApi)
	glfw.WindowHint(glfw.ContextVersionMajor, 2)
	glfw.WindowHint(glfw.ContextVersionMinor, 0)
	window, err := glfw.CreateWindow(Width, Height, Title, nil, nil)
	if err != nil {
		panic(err)
	}
	defer window.Destroy()
	window.MakeContextCurrent()
	glfw.SwapInterval(1)
	window.SetSizeCallback(reshape)
	window.SetKeyCallback(keyEvent)
	gl.Viewport(0, 0, Width, Height)
	initScene()

	if *debug {
		go func() {
			tick := time.Tick(1 * time.Second)
			for {
				<-tick
				fmt.Printf("FPS:%v\tGOROUTINE:%v\r", atomic.LoadUint64(fps), runtime.NumGoroutine())
				atomic.StoreUint64(fps, 0)
			}
		}()
	}
	for !window.ShouldClose() {
		drawScene()
		window.SwapBuffers()
		glfw.PollEvents()
		atomic.AddUint64(fps, 1)
	}
}
示例#30
0
文件: main.go 项目: rdterner/gosgl
func main() {
	go m.Do(func() {
		defer m.Exit()
		runtime.LockOSThread()
		glfw.SetErrorCallback(errorCallback)

		if !glfw.Init() {
			panic("Can't init glfw!")
		}
		defer glfw.Terminate()

		w, h := 800, 600
		window, err := glfw.CreateWindow(w, h, "Testing", nil, nil)
		if err != nil {
			panic(err)
		}

		window.MakeContextCurrent()
		gl.Init()
		sgl.Init()
		canv := sgl.NewCanvas(w, h)
		pa := sgl.NewPath().StartAt(sgl.Pt(50, 50))
		pa.QuadraticTo(sgl.Pt(80, 50), sgl.Pt(150, 0))
		pa.QuadraticTo(sgl.Pt(300, 300), sgl.Pt(800, 100))
		pa.QuadraticTo(sgl.Pt(100, 600), sgl.Pt(0, 300))
		pa.BezierTo(sgl.Pt(50, 50), sgl.Pt(-100, 200), sgl.Pt(100, 100))
		for !window.ShouldClose() {
			gl.ClearColor(1, 1, 1, 1)
			gl.Clear(gl.COLOR_BUFFER_BIT)
			pa.DrawFill(canv, sgl.NewPaint().SetFill(color.RGBA{89, 184, 239, 100}))
			//Do OpenGL stuff
			window.SwapBuffers()
			glfw.PollEvents()
			time.Sleep(100 * time.Millisecond)
		}
	})
	m.Main()
}