Ejemplo n.º 1
0
//NewVUNModel process and uploads the data to the GPU.
func NewVUNModel(indices []uint16, indexedVertices []glm.Vec3, indexedUvs []glm.Vec2, indexedNormals []glm.Vec3) Mesh {

	m := VUNMesh{}
	m.VAO = gl2.GenVertexArray()
	m.VAO.Bind()
	defer m.VAO.Unbind()

	m.Msize = int32(len(indices))
	//create a bunch of buffers and fill them
	//Positions
	m.Positions = gl2.GenBuffer()
	m.Positions.Bind(gl.ARRAY_BUFFER)
	m.Positions.Data(gl.ARRAY_BUFFER, len(indexedVertices)*3*4, ptr(indexedVertices), gl.STATIC_DRAW)

	//Uvs
	m.Uvs = gl2.GenBuffer()
	m.Uvs.Bind(gl.ARRAY_BUFFER)
	m.Uvs.Data(gl.ARRAY_BUFFER, len(indexedUvs)*2*4, ptr(indexedUvs), gl.STATIC_DRAW)

	//Normals
	m.Normals = gl2.GenBuffer()
	m.Normals.Bind(gl.ARRAY_BUFFER)
	m.Normals.Data(gl.ARRAY_BUFFER, len(indexedNormals)*3*4, ptr(indexedNormals), gl.STATIC_DRAW)

	//indices
	m.Indices = gl2.GenBuffer()
	m.Indices.Bind(gl.ELEMENT_ARRAY_BUFFER)
	m.Indices.Data(gl.ELEMENT_ARRAY_BUFFER, len(indices)*2, ptr(indices), gl.STATIC_DRAW)

	return &m
}
Ejemplo n.º 2
0
//InitPostProcessSystem will allocate all the resources required to make the Image Post Processing system work.
func InitPostProcessSystem() {
	//init model
	quadvao := gl2.GenVertexArray()
	quadvao.Bind()
	defer quadvao.Unbind()

	vertpos := gl2.GenBuffer()
	vertpos.Bind(gl.ARRAY_BUFFER)
	gl.BufferData(gl.ARRAY_BUFFER, len(_quadvertpos)*2*4, ptr(_quadvertpos), gl.STATIC_DRAW)

	vertuv := gl2.GenBuffer()
	vertuv.Bind(gl.ARRAY_BUFFER)
	gl.BufferData(gl.ARRAY_BUFFER, len(_quadvertuv)*2*4, ptr(_quadvertuv), gl.STATIC_DRAW)

	fstri.vao = quadvao
	fstri.pos = vertpos
	fstri.uv = vertuv
}