Ejemplo n.º 1
0
func CreateFrameBuffer(width, height int32) *FrameBuffer {
    f := &FrameBuffer {
        Width: width,
        Height: height,
        Buffers: []DrawBuffer { },
        ClearColor: Color4(0,0,0,1),
    }
    gl.GenFramebuffers(1, &f.id)
    gl.BindFramebuffer(gl.FRAMEBUFFER, f.id)
    return f
}
Ejemplo n.º 2
0
func (glRenderer *OpenglRenderer) CreatePostEffect(shader *renderer.Shader) {

	//Create program
	glRenderer.CreateShader(shader)
	gl.UseProgram(shader.Program)

	//Create Texture
	var fbo_texture uint32
	gl.ActiveTexture(gl.TEXTURE0)
	gl.GenTextures(1, &fbo_texture)
	gl.BindTexture(gl.TEXTURE_2D, fbo_texture)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE)
	gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE)
	gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, int32(glRenderer.WindowWidth), int32(glRenderer.WindowHeight), 0, gl.RGBA, gl.UNSIGNED_BYTE, nil)

	//Create depth buffer
	var dbo uint32
	gl.GenRenderbuffers(1, &dbo)
	gl.BindRenderbuffer(gl.RENDERBUFFER, dbo)
	gl.RenderbufferStorage(gl.RENDERBUFFER, gl.DEPTH_COMPONENT16, int32(glRenderer.WindowWidth), int32(glRenderer.WindowHeight))
	gl.BindRenderbuffer(gl.RENDERBUFFER, 0)

	//Create frame buffer
	var fbo uint32
	gl.GenFramebuffers(1, &fbo)
	gl.BindFramebuffer(gl.FRAMEBUFFER, fbo)
	gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, fbo_texture, 0)
	gl.FramebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, dbo)

	//add new postEffect to the queue
	newPe := postEffect{
		program:   shader.Program,
		textureId: fbo_texture,
		dboId:     dbo,
		fboId:     fbo,
		shader:    shader,
	}
	glRenderer.postEffects = append(glRenderer.postEffects, newPe)
}