Exemple #1
0
func render() {
	modelMatrix = trig.MatrixMult(trig.RotateY(math.Pi/360), modelMatrix)

	gl.Viewport(0, 0, 768, 768)
	gl.ClearColor(0.0, 0.0, 0, 0)
	gl.Enable(gl.DEPTH_TEST)

	raytraceProgram.Use()
	mInput.UniformMatrix4f(false, (*[16]float32)(modelMatrix))
	vInput.UniformMatrix4f(false, (*[16]float32)(viewMatrix))
	pInput.UniformMatrix4f(false, (*[16]float32)(projMatrix))
	glh.With(framebuffer, func() {
		framebuffer.UpdateTextures()

		gl.DrawBuffer(gl.COLOR_ATTACHMENT0)

		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.GREATER)
		gl.CullFace(gl.BACK)
		cube.Render(gl.TRIANGLES, raytraceProgram)

		gl.DrawBuffer(gl.COLOR_ATTACHMENT1)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		gl.DepthFunc(gl.LESS)
		gl.CullFace(gl.FRONT)
		cube.Render(gl.TRIANGLES, raytraceProgram)
	})
}
Exemple #2
0
func main() {
	window, err := initGL()
	if err != nil || window == nil {
		log.Printf("InitGL: %v", err)
		return
	}
	defer glfw.Terminate()

	shaderLoad()

	cube, square = createBuffers()

	defer cube.Release()
	defer square.Release()

	timeframe = 0.0

	stack := trig.NewMatrixStack()
	stack.Push(trig.TranslateXYZ(-0.5, -0.5, 0), trig.RotateY(math.Pi/4))

	modelMatrix = stack.Get()
	viewMatrix = trig.TranslateXYZ(0, 0, -2)
	projMatrix = trig.Frustum(-0.5, 0.5, -0.5, 0.5, 1, 10)

	textureBank = helper.InitTextureBank(4, 1)
	textureBank.InitSamplerWithDefaults(0)
	textureBank.InstantiateSamplers()

	textureBank.InstantiateGeometry(0, 768, 768, 0, 0)
	textureBank.InstantiateGeometry(1, 768, 768, 0, 0)
	textureBank.InstantiateGeometry(2, 256, 256, 256, 0)
	textureBank.InstantiateGeometry(3, 256, 0, 0, 0)

	textureBank.InstantiateFormat(0, gl.FLOAT, gl.RGB, gl.RGB32F)
	textureBank.InstantiateFormat(1, gl.FLOAT, gl.RGB, gl.RGB32F)
	textureBank.InstantiateFormat(2, gl.UNSIGNED_BYTE, gl.RED, gl.R8)
	textureBank.InstantiateFormat(3, gl.UNSIGNED_BYTE, gl.RGBA, gl.RGBA)

	textureBank.ConfigUnit(0, gl.TEXTURE_2D, 0)
	textureBank.ConfigUnit(1, gl.TEXTURE_2D, 0)
	textureBank.ConfigUnit(2, gl.TEXTURE_3D, 0)
	textureBank.ConfigUnit(3, gl.TEXTURE_1D, 0)

	loadTexture()
	textureBank.InstantiateTextures()
	glh.OpenGLSentinel()()

	glh.With(textureBank, func() {

		framebuffer = &helper.Framebuffer{}
		framebuffer.Outputs = []gl.Texture{
			textureBank.Units[0].Texture,
			textureBank.Units[1].Texture,
		}
		framebuffer.Sizes = []*helper.TextureGeometry{
			textureBank.PixelData[0].Geometry[0],
			textureBank.PixelData[1].Geometry[0],
		}
		for !window.ShouldClose() {
			render()
			compose()
			window.SwapBuffers()
			glfw.PollEvents()
		}
	})
	os.Exit(0)
}