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) }) }
// Creates a new Framebuffer. func NewFramebuffer(w int, h int) (fb *Framebuffer, err error) { var ( buffer gl.Framebuffer texture gl.Texture ) buffer = gl.GenFramebuffer() buffer.Bind() texture = gl.GenTexture() texture.Bind(gl.TEXTURE_2D) gl.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w, h, 0, gl.RGBA, gl.UNSIGNED_BYTE, nil) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.NEAREST) gl.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.NEAREST) gl.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0) gl.DrawBuffer(gl.COLOR_ATTACHMENT0) if gl.CheckFramebufferStatus(gl.FRAMEBUFFER) != gl.FRAMEBUFFER_COMPLETE { err = fmt.Errorf("Framebuffer could not be set up") return } fb = &Framebuffer{ Buffer: buffer, Texture: texture, Width: w, Height: h, } return }
func copiedReshape(window *glfw.Window, w int, h int) { gl.DrawBuffer(gl.FRONT_AND_BACK) //gl.Viewport(int(w/2), int(h/2), w, h) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Frustum(-1, 1, -1, 1, 1.5, 20) gl.MatrixMode(gl.MODELVIEW) }
func reshape(w, h int) { // Write to both buffers, prevent flickering gl.DrawBuffer(gl.FRONT_AND_BACK) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Viewport(0, 0, w, h) gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() }
func onResize(w, h int) { // Write to both buffers, prevent flickering gl.DrawBuffer(gl.FRONT_AND_BACK) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Viewport(0, 0, w, h) gl.Ortho(0, float64(w), float64(h), 0, -1.0, 1.0) gl.ClearColor(1, 1, 1, 0) gl.Clear(gl.COLOR_BUFFER_BIT) gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() }
func Reshape(width, height int) { if DoneThisFrame(ReshapeWindow) { return } gl.Viewport(0, 0, width, height) gl.MatrixMode(gl.PROJECTION) gl.LoadIdentity() gl.Ortho(-2.1, 6.1, -2.25, 2.1, -1, 1) //gl.Ortho(-2.1, 6.1, -2.25*2, 2.1*2, -1, 1) // Y debug gl.MatrixMode(gl.MODELVIEW) gl.LoadIdentity() gl.Clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) if Draw != nil { gl.DrawBuffer(gl.FRONT_AND_BACK) Draw() gl.DrawBuffer(gl.BACK) } }