コード例 #1
0
ファイル: dg.go プロジェクト: krattai/monoflow
// Initialize enough of the opengl context that some OpenGL information
// can be dumped to screen along with the bindings.  This is a basic graphics
// package test that checks if the underlying OpenGL functions are available.
// Columns of function names marked as [+] (available) or [ ] (missing) will
// be written the the console if everything is ok.
func dg() {
	gl.Dump() // doesn't need context.

	// Also print the opengl version which does need a context.
	app := device.New("Dump", 400, 100, 600, 600)
	fmt.Printf("%s %s", gl.GetString(gl.RENDERER), gl.GetString(gl.VERSION))
	fmt.Printf(" GLSL %s\n", gl.GetString(gl.SHADING_LANGUAGE_VERSION))
	app.Dispose()
}
コード例 #2
0
ファイル: ld.go プロジェクト: krattai/monoflow
// ld loads a mesh model that has been exported from another tool -
// a .obj file from Blender in this case. It is really testing the
// "data" package with the key line being:
//        loader.Load("monkey", &mesh)
//
// This also demonstrates basic rendering by using OpenGL calls from
// package "vu/render/gl" to render the imported mesh.
func ld() {
	ld := &ldtag{}
	dev := device.New("Load Model", 400, 100, 800, 600)
	ld.initScene()
	dev.Open()
	for dev.IsAlive() {
		ld.update(dev)
		ld.render()
		dev.SwapBuffers()
	}
	dev.Dispose()
}
コード例 #3
0
ファイル: tb.go プロジェクト: krattai/monoflow
// tb shows how a basic texture is used in OpenGL.  One texture is loaded and
// rendered on a single mesh. This example is useful in understanding texture
// basics.
//
// This also demonstrates basic rendering by using OpenGL calls from
// package "vu/render/gl" for rendering.
func tb() {
	tb := new(tbtag)
	dev := device.New("Texture:Basic", 400, 100, 500, 500)
	tb.initScene()
	dev.Open()
	for dev.IsAlive() {
		tb.update(dev)
		tb.drawScene()
		dev.SwapBuffers()
	}
	dev.Dispose()
}
コード例 #4
0
ファイル: sf.go プロジェクト: krattai/monoflow
// sf demonstrates one example of shader only rendering. This shows the power of shaders using
// an example from shadertoy.com. Specifically:
//       https://www.shadertoy.com/view/Xsl3zN
// For more shader examples also check out:
//       http://glsl.heroku.com
// The real star of this demo though is found in ./shaders/fire.fsh.  Kudos to @301z and
// the other contributors to shadertoy and heroku.
//
// This also demonstrates basic rendering by using OpenGL calls from
// package "vu/render/gl" for rendering.
func sf() {
	sf := new(sftag)
	dev := device.New("Shader Fire", 400, 100, 500, 500)
	sf.initScene()
	dev.Open()
	for dev.IsAlive() {
		sf.update(dev)
		sf.drawScene()
		dev.SwapBuffers()
	}
	dev.Dispose()
}
コード例 #5
0
ファイル: tr.go プロジェクト: krattai/monoflow
// tr demonstrates basic OpenGL by drawing a triangle. If anything this example
// shows that basic OpenGL is not all that basic. Check out the following methods:
//     - initData()   creates a triangle mesh that includes vertex points, faces, and colours.
//     - initScene()  makes the data available to the graphics card.
//     - initShader() uses render.BindProgram to load and prepare the shader programs.
//     - drawScene()  is called to render and spin the triangle.
func tr() {
	tag := &trtag{}
	dev := device.New("Triangle", 400, 100, 600, 600)
	tag.initScene()
	dev.Open()
	tag.resize(600, 600)
	for dev.IsAlive() {
		dev.Update()
		tag.drawScene()
		dev.SwapBuffers()
	}
	dev.Dispose()
}
コード例 #6
0
ファイル: sh.go プロジェクト: krattai/monoflow
// sh is used to test and showcase the vu/device package.  Just getting a window
// to appear demonstrates that the majority of the functionality is working.
// The remainder of the example dumps keyboard and mouse events showing that
// user input is being processed.
func sh() {
	sh := &shtag{}
	dev := device.New("Shell", 400, 100, 800, 600)
	gl.Init()
	fmt.Printf("%s %s", gl.GetString(gl.RENDERER), gl.GetString(gl.VERSION))
	fmt.Printf(" GLSL %s\n", gl.GetString(gl.SHADING_LANGUAGE_VERSION))
	dev.Open()
	gl.ClearColor(0.3, 0.6, 0.4, 1.0)
	for dev.IsAlive() {
		sh.update(dev)
		gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
		dev.SwapBuffers()
	}
	dev.ShowCursor(true)
	dev.Dispose()
}
コード例 #7
0
ファイル: eng.go プロジェクト: krattai/monoflow
// New creates a 3D engine. The expected usage is:
//      if eng, err = vu.New("Title", 100, 100, 800, 600); err != nil {
//          log.Printf("Failed to initialize engine %s", err)
//          return
//      }
//      defer eng.Shutdown() // Close down nicely.
//      eng.SetDirector(app) // Enable application callbacks.
//                           // Application 3D setup and initialization.
//      eng.Action()         // Run application loop (does not return).
func New(name string, x, y, width, height int) (e Engine, err error) {
	if name == "" {
		name = "Title"
	}
	if width < 100 {
		width = 100
	}
	if height < 100 {
		height = 100
	}
	eng := &engine{}

	// initialize the os specific shell, graphics context, and
	// user input monitor.
	eng.dev = device.New(name, x, y, width, height)

	// initialize the audio layer.
	eng.aud = audio.NewSoundListener()
	eng.ac = audio.New()
	if err = eng.ac.Init(); err != nil {
		eng.Shutdown()
		return // failed to initialize audio layer
	}

	// initialize the graphics layer.
	eng.gc = render.New()
	if err = eng.gc.Init(); err != nil {
		eng.Shutdown()
		return // failed to initialize graphics layer.
	}
	eng.res = newRoadie(eng.ac, eng.gc)
	eng.gc.Viewport(width, height)
	eng.dev.Open()
	e = eng
	return
}