Esempio n. 1
0
File: dg.go Progetto: toophy/vu
// 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 [+]:available or [ ]:missing will
// be written the the console.
func dg() {
	app := device.New("Dump", 400, 100, 600, 600)
	gl.Dump() // gets graphic context to properly bind.
	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()
}
Esempio n. 2
0
File: tr.go Progetto: skyview059/vu
// initScene is one time initialization that creates a single VAO
func (tag *trtag) initScene() {
	tag.mvp64 = lin.NewM4()
	tag.persp = lin.NewM4().Persp(60, float64(600)/float64(600), 0.1, 50)
	tag.mvp = render.NewMvp()
	tag.initData()

	// Bind the OpenGL calls and dump some version info.
	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))

	// Gather the one scene into this one vertex array object.
	gl.GenVertexArrays(1, &tag.vao)
	gl.BindVertexArray(tag.vao)

	// create shaders
	tag.initShader()
	gl.UseProgram(tag.shaders)

	// vertex data.
	var vbuff uint32
	gl.GenBuffers(1, &vbuff)
	gl.BindBuffer(gl.ARRAY_BUFFER, vbuff)
	gl.BufferData(gl.ARRAY_BUFFER, int64(len(tag.verticies)*4), gl.Pointer(&(tag.verticies[0])), gl.STATIC_DRAW)
	vattr := uint32(gl.GetAttribLocation(tag.shaders, "in_v"))
	gl.EnableVertexAttribArray(vattr)
	gl.VertexAttribPointer(vattr, 3, gl.FLOAT, false, 0, 0)

	// colour data.
	var cbuff uint32
	gl.GenBuffers(1, &cbuff)
	gl.BindBuffer(gl.ARRAY_BUFFER, cbuff)
	gl.BufferData(gl.ARRAY_BUFFER, int64(len(tag.colour)*4), gl.Pointer(&(tag.colour[0])), gl.STATIC_DRAW)
	cattr := uint32(gl.GetAttribLocation(tag.shaders, "in_c"))
	gl.EnableVertexAttribArray(cattr)
	gl.VertexAttribPointer(cattr, 4, gl.FLOAT, false, 0, 0)

	// faces data.
	var ebuff uint32
	gl.GenBuffers(1, &ebuff)
	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebuff)
	gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, int64(len(tag.faces)), gl.Pointer(&(tag.faces[0])), gl.STATIC_DRAW)

	// set some state that doesn't need to change during drawing.
	gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	gl.Enable(gl.CULL_FACE)
	gl.CullFace(gl.BACK)
}
Esempio n. 3
0
File: sf.go Progetto: toophy/vu
// initScene is one time initialization that creates a single VAO
func (sf *sftag) initScene() {
	sf.sTime = time.Now()
	sf.initData()

	// Bind the OpenGL calls and dump some version info.
	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))
	gl.GenVertexArrays(1, &sf.vao)
	gl.BindVertexArray(sf.vao)

	// vertex data.
	var vbuff uint32
	gl.GenBuffers(1, &vbuff)
	gl.BindBuffer(gl.ARRAY_BUFFER, vbuff)
	gl.BufferData(gl.ARRAY_BUFFER, int64(len(sf.verticies)*4), gl.Pointer(&(sf.verticies[0])), gl.STATIC_DRAW)
	gl.VertexAttribPointer(0, 3, gl.FLOAT, false, 0, 0)
	gl.EnableVertexAttribArray(0)

	// faces data.
	var ebuff uint32
	gl.GenBuffers(1, &ebuff)
	gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, ebuff)
	gl.BufferData(gl.ELEMENT_ARRAY_BUFFER, int64(len(sf.faces)), gl.Pointer(&(sf.faces[0])), gl.STATIC_DRAW)

	// create texture and shaders after all the data has been set up.
	// renderer := render.New()
	shader := "fire"
	loader := load.NewLoader()
	vsrc, verr := loader.Vsh(shader)
	fsrc, ferr := loader.Fsh(shader)
	if verr == nil && ferr == nil {
		sf.shaders = gl.CreateProgram()
		if err := gl.BindProgram(sf.shaders, vsrc, fsrc); err != nil {
			fmt.Printf("Failed to create program: %s\n", err)
		}
		sf.mvpref = gl.GetUniformLocation(sf.shaders, "mvpm")
		sf.gTime = gl.GetUniformLocation(sf.shaders, "time")
		sf.sizes = gl.GetUniformLocation(sf.shaders, "screen")
		sf.mvp = render.NewMvp().Set(lin.NewM4().Ortho(0, 4, 0, 4, 0, 10))

		// set some state that doesn't need to change during drawing.
		gl.ClearColor(0.0, 0.0, 0.0, 1.0)
	}
}
Esempio n. 4
0
File: sh.go Progetto: skyview059/vu
// 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()

		// slow things down so that the loop is closer
		// to the engine update loop timing.
		time.Sleep(10 * time.Millisecond)
	}
	dev.ShowCursor(true)
	dev.Dispose()
}