// Start starts the renderer func Start() { if os.Getenv("STEVEN_DEBUG") == "true" { gl.DebugLog() } gl.Enable(gl.DepthTest) gl.Enable(gl.CullFaceFlag) gl.CullFace(gl.Back) gl.FrontFace(gl.ClockWise) chunkProgram = CreateProgram( glsl.Get("chunk_vertex"), glsl.Get("chunk_frag"), ) shaderChunk = &chunkShader{} InitStruct(shaderChunk, chunkProgram) chunkProgramT = CreateProgram( glsl.Get("chunk_vertex"), glsl.Get("chunk_frag", "alpha"), ) shaderChunkT = &chunkShader{} InitStruct(shaderChunkT, chunkProgramT) initUI() initLineDraw() initModels() clouds.init() gl.BlendFunc(gl.SrcAlpha, gl.OneMinusSrcAlpha) elementBuffer = gl.CreateBuffer() }
func initUI() { uiState.program = CreateProgram(glsl.Get("ui_vertex"), glsl.Get("ui_frag")) uiState.shader = &uiShader{} InitStruct(uiState.shader, uiState.program) uiState.array = gl.CreateVertexArray() uiState.array.Bind() uiState.buffer = gl.CreateBuffer() uiState.buffer.Bind(gl.ArrayBuffer) uiState.shader.Position.Enable() uiState.shader.TextureInfo.Enable() uiState.shader.TextureOffset.Enable() uiState.shader.Color.Enable() uiState.shader.Position.PointerInt(3, gl.Short, 28, 0) uiState.shader.TextureInfo.Pointer(4, gl.UnsignedShort, false, 28, 8) uiState.shader.TextureOffset.PointerInt(3, gl.Short, 28, 16) uiState.shader.Color.Pointer(4, gl.UnsignedByte, true, 28, 24) uiState.indexBuffer = gl.CreateBuffer() uiState.indexBuffer.Bind(gl.ElementArrayBuffer) }
func initModels() { c := &ModelCollection{ blendS: gl.SrcAlpha, blendD: gl.OneMinusSrcAlpha, } c.program = CreateProgram(glsl.Get("model_vertex"), glsl.Get("model_frag")) c.shader = &modelShader{} InitStruct(c.shader, c.program) modelState.baseCollection = c modelState.models = append(modelState.models, c) SunModels = &ModelCollection{ blendS: gl.SrcAlpha, blendD: gl.OneFactor, } SunModels.program = CreateProgram(glsl.Get("sun_vertex"), glsl.Get("sun_frag")) SunModels.shader = &modelShader{} InitStruct(SunModels.shader, SunModels.program) modelState.models = append(modelState.models, SunModels) modelState.indexBuffer = gl.CreateBuffer() }
func (c *cloudState) init() { program := gl.CreateProgram() v := gl.CreateShader(gl.VertexShader) v.Source(glsl.Get("cloud_vertex")) v.Compile() if v.Parameter(gl.CompileStatus) == 0 { panic(v.InfoLog()) } else { log := v.InfoLog() if len(log) > 0 { fmt.Println(log) } } g := gl.CreateShader(gl.GeometryShader) g.Source(glsl.Get("cloud_geo")) g.Compile() if g.Parameter(gl.CompileStatus) == 0 { panic(g.InfoLog()) } else { log := g.InfoLog() if len(log) > 0 { fmt.Println(log) } } f := gl.CreateShader(gl.FragmentShader) f.Source(glsl.Get("cloud_fragment")) f.Compile() if f.Parameter(gl.CompileStatus) == 0 { panic(f.InfoLog()) } else { log := f.InfoLog() if len(log) > 0 { fmt.Println(log) } } program.AttachShader(v) program.AttachShader(g) program.AttachShader(f) program.Link() program.Use() c.program = program InitStruct(&c.shader, c.program) c.array = gl.CreateVertexArray() c.array.Bind() c.buffer = gl.CreateBuffer() c.buffer.Bind(gl.ArrayBuffer) c.shader.Position.Enable() c.shader.Position.Pointer(3, gl.Float, false, 12, 0) data := builder.New(builder.Float, builder.Float, builder.Float) for x := -160; x < 160; x++ { for y := -160; y < 160; y++ { data.Float(float32(x)) data.Float(128) data.Float(float32(y)) c.numPoints++ } } c.buffer.Data(data.Data(), gl.StaticDraw) c.texture = gl.CreateTexture() c.texture.Bind(gl.Texture2D) c.texture.Image2D(0, 512, 512, gl.Red, gl.UnsignedByte, c.data) c.texture.Parameter(gl.TextureMinFilter, gl.Nearest) c.texture.Parameter(gl.TextureMagFilter, gl.Nearest) }