func (batch VaoBatch) Enter() { batch.vao.Bind() if err := glw.CheckGlError(); err != nil { err.Description = "VaoBatch.vao.Bind()" panic(err) } }
func (batch UniformBatch) Enter() { batch.modelMatrixUniform.UniformMatrix4f(false, &batch.modelMatrix) batch.context.Program.Validate() if err := glw.CheckGlError(); err != nil { err.Description = "Program.Validate failed." panic(err) } status := batch.context.Program.Get(gl.VALIDATE_STATUS) if err := glw.CheckGlError(); err != nil { err.Description = "Program.Get(VALIDATE_STATUS) failed." panic(err) } if status == gl.FALSE { infolog := batch.context.Program.GetInfoLog() gl.GetError() // Clear error flag if infolog derped. panic(fmt.Errorf("Program validation failed. Log: %v", infolog)) } }
func (batch ProgramBatch) Enter() { program, err := batch.context.Programs.Serve(batch.shaderRefs) if err != nil { panic(err) } program.Use() if err := glw.CheckGlError(); err != nil { err.Description = fmt.Sprintf("program.Use() for ProgramBatch %v", program) } batch.context.Program = program }
func (batch ClearBatch) Enter() { if batch.clearMask&gl.COLOR_BUFFER_BIT != 0 { gl.ClearColor( batch.clearColor[0], batch.clearColor[1], batch.clearColor[2], batch.clearColor[3], ) } if batch.clearMask&gl.DEPTH_BUFFER_BIT != 0 { gl.ClearDepth(batch.clearDepth) } gl.Clear(batch.clearMask) if err := glw.CheckGlError(); err != nil { err.Description = "gl.Clear" panic(err) } }
func main() { var programState programState var err error glfw.SetErrorCallback(errorCallback) if !glfw.Init() { panic("GLFW initialization failed.") } defer glfw.Terminate() glfw.WindowHint(glfw.ContextVersionMajor, 3) glfw.WindowHint(glfw.ContextVersionMinor, 3) glfw.WindowHint(glfw.SrgbCapable, glfw.True) glfw.WindowHint(glfw.Resizable, glfw.False) programState.Gl.Window, err = glfw.CreateWindow(640, 480, "Daggor", nil, nil) if err != nil { panic(err) } defer programState.Gl.Window.Destroy() programState.Gl.glfwKeyEventList = makeGlfwKeyEventList() programState.Gl.Window.SetKeyCallback(programState.Gl.glfwKeyEventList.Callback) programState.Gl.Window.MakeContextCurrent() if ec := gl.Init(); ec != 0 { panic(fmt.Sprintf("OpenGL initialization failed with code %v.", ec)) } // For some reason, here, the OpenGL error flag for me contains "Invalid enum". // This is weird since I have not done anything yet. I imagine that something // goes wrong in gl.Init. Reading the error flag clears it, so I do it. // Here's the reason: // https://github.com/go-gl/glfw3/issues/50 // Maybe I should not even ask for a core profile anyway. // What are the advantages are asking for a core profile? if err := glw.CheckGlError(); err != nil { err.Description = "OpenGL has this error right after init for some reason." //fmt.Println(err) } { // Assert OpenGL >= 3.3. major := programState.Gl.Window.GetAttribute(glfw.ContextVersionMajor) minor := programState.Gl.Window.GetAttribute(glfw.ContextVersionMinor) fmt.Printf("OpenGL version %v.%v.\n", major, minor) if (major < 3) || (major == 3 && minor < 3) { panic("OpenGL version 3.3 required, your video card/driver does not seem to support it.") } } programState.Gl.context = glw.NewGlContext() programState.Gl.Shapes[floorID] = sculpt.FloorInstNorm(programState.Gl.context.Programs) programState.Gl.Shapes[ceilingID] = sculpt.CeilingInstNorm(programState.Gl.context.Programs) programState.Gl.Shapes[wallID] = sculpt.WallInstNorm(programState.Gl.context.Programs) { // I do not like the default reference frame of OpenGl. // By default, we look in the direction -z, and y points up. // I want z to point up, and I want to look in the direction +x // by default. That way, I move on an xy plane where z is the // altitude, instead of having the altitude stuffed between // the two things I use the most. And my reason for pointing // toward +x is that I use the convention for trigonometry: // an angle of 0 points to the right (east) of the trigonometric // circle. Bonus point: this matches Blender's reference frame. myFrame := glm.ZUP.Mult(glm.RotZ(90)) eye_to_clip := glm.PerspectiveProj(110, 640./480., .1, 100).Mult(myFrame) programState.Gl.context.SetEyeToClp(eye_to_clip) } gl.Enable(gl.FRAMEBUFFER_SRGB) gl.Enable(gl.DEPTH_TEST) gl.Enable(gl.CULL_FACE) gl.CullFace(gl.BACK) gl.FrontFace(gl.CCW) gl.Enable(gl.TEXTURE_CUBE_MAP_SEAMLESS) // This needs a texture server attached to the context, like for programs. glw.LoadSkybox() programState.World = world.MakeWorld() mainLoop(programState) }