Beispiel #1
0
func CreateVOB() {
    Verticies := [...]gl.Float{-0.8f, -0.8f, 0.0f, 1.0f,
                               0.0f,  0.8f, 0.0f, 1.0f,
                               0.8f, -0.8f, 0.0f, 1.0f}

    Colours := [...]gl.Float{1.0f, 0.0f, 0.0f, 1.0f,
                         0.0f, 1.0f, 0.0f, 1.0f,
                         0.0f, 0.0f, 1.0f, 1.0f}

    BufferSize = unsafe.Sizeof(Verticies)
    VertexSize = unsafe.Sizeof(Verticies[0])
    RgbOffset  = unsafe.Sizeof(Verticies[0].XYZW)

    gl.GenVertexArrays(1, &VaoId)
    gl.BindVertexArray(VaoId)

    gl.GenBuffers(1, &VboId)
    gl.BindBuffer(gl.ARRAY_BUFFER, VboId)
    gl.BufferData(gl.ARRAY_BUFFER, unsafe.Sizeof(Verticies), Verticies, gl.STATIC_DRAW)
    gl.VertexAttribPointer(1, 4, gl.Float, gl.FALSE, 0, 0)
    gl.EnableVertexAttribArray(1)

    if err := gl.GetError(); err != gl.NO_ERROR {
    	fmt.Println(err, "ERROR: Could not create a VBO")
    }
}
Beispiel #2
0
func renderToScreen() {
	gl.BindFramebuffer(gl.FRAMEBUFFER, 0)
	gl.Viewport(0, 0, winWidth, winHeight)
	gl.UseProgram(shaderTextureDisplay.glProg)
	gl.BindTexture(gl.TEXTURE_2D, rttFrameTex)
	gl.Uniform1i(shaderTextureDisplay.unifTex, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, dispVertBuf)
	gl.EnableVertexAttribArray(shaderTextureDisplay.attrPos)
	gl.VertexAttribPointer(shaderTextureDisplay.attrPos, 3, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))
	gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)
	gl.DisableVertexAttribArray(shaderTextureDisplay.attrPos)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
}
Beispiel #3
0
func renderToTexture() {
	gl.BindFramebuffer(gl.FRAMEBUFFER, rttFrameBuf)
	gl.Viewport(0, 0, texSize, texSize)
	gl.ClearColor(0.9, 0.6, 0.3, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(shaderTextureCreator.glProg)
	gl.BindBuffer(gl.ARRAY_BUFFER, rttVertBuf)
	gl.EnableVertexAttribArray(shaderTextureCreator.attrPos)
	gl.VertexAttribPointer(shaderTextureCreator.attrPos, 2, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))
	gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)
	gl.DisableVertexAttribArray(shaderTextureCreator.attrPos)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
}
Beispiel #4
0
func renderToTexture() {
	gl.BindFramebuffer(gl.FRAMEBUFFER, rttFrameBuf)
	gl.Viewport(0, 0, texWidth, texHeight)
	gl.ClearColor(0.1, 0.2, 0.3, 1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)
	gl.UseProgram(shaderTextureCreator.glProg)
	gl.BindTexture(gl.TEXTURE_3D, volTex)
	gl.Uniform1i(shaderTextureCreator.unifTex, 0)
	gl.BindBuffer(gl.ARRAY_BUFFER, rttVertBuf)
	gl.EnableVertexAttribArray(shaderTextureCreator.attrPos)
	gl.VertexAttribPointer(shaderTextureCreator.attrPos, 2, gl.FLOAT, gl.FALSE, 0, gl.Pointer(nil))
	gl.DrawArrays(gl.TRIANGLE_FAN, 0, 4)
	gl.DisableVertexAttribArray(shaderTextureCreator.attrPos)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)
}
Beispiel #5
0
Datei: main.go Projekt: vron/fm
func display() {
	gl.ClearColor(0.19, 0.19, 0.21, 0)
	gl.ClearDepth(1)
	gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT)

	gl.UseProgram(theProgram)

	// Temporarily set the cam t clip
	id := gls.Identity()

	trans := getLookAtMatrix()
	//	log.Println(trans)
	gls.UniformMatrix4fv(wtcm_unif, 1, false, trans)

	gls.UniformMatrix4fv(mtwm_unif, 1, false, id)

	// And here we do the actual rendering

	// Generate a name for vufferobj and store it
	gl.GenBuffers(1, &positionBufferObject)
	// Bind it to a target
	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)

	// Conver all nodes to a long array of vertexes!
	i := 0
	// TODO: Fix this, based on 4 per eleemnts
	vpos := make([]float32, len(elements)*4*4)
	elms := make(map[uint32]mS, len(elements))
	// Note that the order here is undefined!
	ii := 0
	for k, v := range elements {
		elms[k] = mS{ii, len(v.Nodes())}
		for _, vv := range v.Nodes() {
			ii++
			vpos[i] = float32(nodes[vv][0])
			i++
			vpos[i] = float32(nodes[vv][1])
			i++
			vpos[i] = float32(nodes[vv][2])
			i++
			vpos[i] = 1.0
			i++
		}
	}
	/*
		for _, v := range nodes {
			vpos[i] = float32(v[0])
			i++
			vpos[i] = float32(v[1])
			i++
			vpos[i] = float32(v[2])
			i++
		}
	*/
	gl.BufferData(gl.ARRAY_BUFFER, gl.Sizeiptr(32/8*len(vpos)), (gl.Pointer)(&vpos[0]), gl.STATIC_DRAW)
	gl.BindBuffer(gl.ARRAY_BUFFER, 0)

	gl.BindBuffer(gl.ARRAY_BUFFER, positionBufferObject)
	gl.EnableVertexAttribArray(0)
	gl.VertexAttribPointer(0, 4, gl.FLOAT, gl.FALSE, 0, (gl.Pointer)(nil))

	/*	for _,v := range elms {

		}
	*/
	for _, v := range elms {
		gl.DrawArrays(gl.LINE_LOOP, gl.Int(v.Start), gl.Sizei(v.Length))
	}

	// Draw Coordinate acis
	/*for i := 9; i < 9+2*5; i += 2 {
		gl.DrawArrays(gl.LINE_STRIP, gl.Int(i), 2)
	}*/
}