Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cel Shader Example #83

Open
shehackedyou opened this issue Jan 7, 2024 · 2 comments
Open

Cel Shader Example #83

shehackedyou opened this issue Jan 7, 2024 · 2 comments

Comments

@shehackedyou
Copy link

I like how simple this project is go-gl isn't trying to be a full engine just control over gl, which is nice because I want to build a 3D scene to be streamed.

Any recommendations on how to implement custom shaders? Itd be nice to be able to switch between them, it would create a mechanic.

@shehackedyou
Copy link
Author

shehackedyou commented Jan 7, 2024

	vertexShader, err := compileShader(vertexShaderSource, gl.VERTEX_SHADER)
	if err != nil {
		return 0, err
	}

gl.AttachShader(program, vertexShader)

# Then you can delete and presumably re-add to make the switch
gl.DeleteShader(program, vertexShader)

@shehackedyou
Copy link
Author

func compileShader(source string, shaderType uint32) (uint32, error) {
	shader := gl.CreateShader(shaderType)

	csources, free := gl.Strs(source)
	gl.ShaderSource(shader, 1, csources, nil)
	free()
	gl.CompileShader(shader)

	var status int32
	gl.GetShaderiv(shader, gl.COMPILE_STATUS, &status)
	if status == gl.FALSE {
		var logLength int32
		gl.GetShaderiv(shader, gl.INFO_LOG_LENGTH, &logLength)

		log := strings.Repeat("\x00", int(logLength+1))
		gl.GetShaderInfoLog(shader, logLength, nil, gl.Str(log))

		return 0, fmt.Errorf("failed to compile %v: %v", source, log)
	}

	return shader, nil
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant