func (wp *waypoint) RenderOnFloor() { if !wp.active { return } wp.drawn = true gl.Color4ub(200, 0, 0, 128) base.EnableShader("waypoint") base.SetUniformF("waypoint", "radius", float32(wp.Radius)) t := float32(time.Now().UnixNano()%1e15) / 1.0e9 base.SetUniformF("waypoint", "time", t) gl.Begin(gl.QUADS) gl.TexCoord2i(0, 1) gl.Vertex2i(gl.Int(wp.X-wp.Radius), gl.Int(wp.Y-wp.Radius)) gl.TexCoord2i(0, 0) gl.Vertex2i(gl.Int(wp.X-wp.Radius), gl.Int(wp.Y+wp.Radius)) gl.TexCoord2i(1, 0) gl.Vertex2i(gl.Int(wp.X+wp.Radius), gl.Int(wp.Y+wp.Radius)) gl.TexCoord2i(1, 1) gl.Vertex2i(gl.Int(wp.X+wp.Radius), gl.Int(wp.Y-wp.Radius)) gl.End() base.EnableShader("") // base.EnableShader("") }
func (ob *OptionBasic) DrawInfo(x, y, dx, dy int) { gl.Color4ub(255, 255, 255, 255) tx := x + (dx-ob.Large.Data().Dx())/2 ty := y + dy - ob.Large.Data().Dy() ob.Large.Data().RenderNatural(tx, ty) d := base.GetDictionary(ob.Size) d.RenderParagraph(ob.Text, float64(x), float64(y+dy-ob.Large.Data().Dy())-d.MaxHeight(), 0, float64(dx), d.MaxHeight(), gui.Left, gui.Top) }
func (co *colorOption) DrawInfo(x, y, dx, dy int) { gl.Disable(gl.TEXTURE_2D) gl.Color4ub(co.r, co.g, co.b, co.a) gl.Begin(gl.QUADS) gl.Vertex2i(gl.Int(x), gl.Int(y)) gl.Vertex2i(gl.Int(x), gl.Int(y+dy)) gl.Vertex2i(gl.Int(x+dx), gl.Int(y+dy)) gl.Vertex2i(gl.Int(x+dx), gl.Int(y)) gl.End() }
func (ep *EntityPlacer) Draw(region gui.Region) { ep.region = region gl.Color4ub(255, 255, 255, 255) ep.layout.Texture.Data().RenderNatural(region.X, region.Y) for _, button := range ep.buttons { button.RenderAt(ep.region.X, ep.region.Y) } d := base.GetDictionary(ep.layout.Roster.Points.Size) x_off := ep.layout.Roster.Points.X_off y_off := ep.layout.Roster.Points.Y_off for i, button := range ep.ent_buttons { cost := ep.roster[ep.roster_names[i]] x := float64(button.X + x_off) y := float64(button.Y + y_off) d.RenderString(fmt.Sprintf("%d", cost), x, y, 0, d.MaxHeight(), gui.Right) } gl.Color4ub(255, 255, 255, 255) var ent *Entity if !pointInsideRect(ep.mx, ep.my, region.X, region.Y, region.Dx, region.Dy) { ent = ep.game.new_ent } if ep.hovered != nil { ent = ep.hovered } if ent != nil { ent.Still.Data().RenderNatural(ep.layout.Face.X, ep.layout.Face.Y) ep.layout.Name.RenderString(ent.Name) ep.layout.Ap.RenderString(fmt.Sprintf("Ap:%d", ent.Stats.ApCur())) ep.layout.Hp.RenderString(fmt.Sprintf("Hp:%d", ent.Stats.HpCur())) ep.layout.Corpus.RenderString(fmt.Sprintf("Corpus:%d", ent.Stats.Corpus())) ep.layout.Ego.RenderString(fmt.Sprintf("Ego:%d", ent.Stats.Ego())) } if ep.show_points { d := base.GetDictionary(ep.layout.Points_remaining.Size) x := float64(ep.layout.Points_remaining.X) y := float64(ep.layout.Points_remaining.Y) d.RenderString(ep.layout.Points_remaining.String, x, y, 0, d.MaxHeight(), gui.Left) w := d.StringWidth(ep.layout.Points_remaining.String) d.RenderString(fmt.Sprintf("%d", ep.points), x+w, y, 0, d.MaxHeight(), gui.Right) } }
func (mo *MapOption) Draw(hovered, selected, selectable bool, region gui.Region) { var s gl.Ubyte switch { case selected: s = 255 case hovered && selectable: s = 205 case selectable: s = 127 default: s = 75 } gl.Color4ub(s, s, s, 255) icon := mo.house_def.Icon.Data() if icon.Dx() == 0 { icon = mo.layout.Default_icon.Data() } icon.RenderNatural(region.X, region.Y) gl.Color4ub(0, 0, 0, 255) d := base.GetDictionary(15) d.RenderString(mo.house_def.Name, float64(region.X), float64(region.Y), 0, d.MaxHeight(), gui.Left) }
func (e *Entity) drawReticle(pos mathgl.Vec2, rgba [4]float64) { if !e.hovered && !e.selected && !e.controlled { return } gl.PushAttrib(gl.CURRENT_BIT) r := gl.Ubyte(rgba[0] * 255) g := gl.Ubyte(rgba[1] * 255) b := gl.Ubyte(rgba[2] * 255) a := gl.Ubyte(rgba[3] * 255) switch { case e.controlled: gl.Color4ub(0, 0, r, a) case e.selected: gl.Color4ub(r, g, b, a) default: gl.Color4ub(r, g, b, gl.Ubyte((int(a)*200)>>8)) } glow := texture.LoadFromPath(filepath.Join(base.GetDataDir(), "ui", "glow.png")) dx := float64(e.last_render_width + 0.5) dy := float64(e.last_render_width * 150 / 100) glow.Render(float64(pos.X), float64(pos.Y), dx, dy) gl.PopAttrib() }
func (f *Furniture) Render(pos mathgl.Vec2, width float32) { var rgba [4]gl.Double gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0]) gl.PushAttrib(gl.CURRENT_BIT) if !f.Blocks_los || !f.alpha_enabled { f.alpha = 1 } var tff gl.Double = 255 gl.Color4ub(gl.Ubyte(tff*rgba[0]), gl.Ubyte(tff*rgba[1]), gl.Ubyte(tff*rgba[2]), gl.Ubyte(tff*rgba[3]*gl.Double(f.alpha))) orientation := f.Orientations[f.Rotation] dy := width * float32(orientation.Texture.Data().Dy()) / float32(orientation.Texture.Data().Dx()) // orientation.Texture.Data().Render(float64(pos.X), float64(pos.Y), float64(width), float64(dy)) orientation.Texture.Data().RenderAdvanced(float64(pos.X), float64(pos.Y), float64(width), float64(dy), 0, !f.Flip) gl.PopAttrib() }
func (o *Overlay) Draw(region gui.Region) { o.region = region switch o.game.Side { case SideHaunt: if o.game.los.denizens.mode == LosModeBlind { return } case SideExplorers: if o.game.los.intruders.mode == LosModeBlind { return } default: return } for _, wp := range o.game.Waypoints { if !wp.active || wp.drawn { continue } cx := float32(wp.X) cy := float32(wp.Y) r := float32(wp.Radius) cx1, cy1 := o.game.viewer.BoardToWindow(cx-r, cy-r) cx2, cy2 := o.game.viewer.BoardToWindow(cx-r, cy+r) cx3, cy3 := o.game.viewer.BoardToWindow(cx+r, cy+r) cx4, cy4 := o.game.viewer.BoardToWindow(cx+r, cy-r) gl.Color4ub(200, 0, 0, 128) base.EnableShader("waypoint") base.SetUniformF("waypoint", "radius", float32(wp.Radius)) t := float32(time.Now().UnixNano()%1e15) / 1.0e9 base.SetUniformF("waypoint", "time", t) gl.Begin(gl.QUADS) gl.TexCoord2i(0, 1) gl.Vertex2i(gl.Int(cx1), gl.Int(cy1)) gl.TexCoord2i(0, 0) gl.Vertex2i(gl.Int(cx2), gl.Int(cy2)) gl.TexCoord2i(1, 0) gl.Vertex2i(gl.Int(cx3), gl.Int(cy3)) gl.TexCoord2i(1, 1) gl.Vertex2i(gl.Int(cx4), gl.Int(cy4)) gl.End() base.EnableShader("") } }
func (a *Move) RenderOnFloor() { if a.ent == nil { return } if path_tex == nil { path_tex = house.MakeLosTexture() } path_tex.Remap() path_tex.Bind() gl.Color4ub(255, 255, 255, 128) base.EnableShader("path") base.SetUniformF("path", "threshold", float32(a.threshold)/255) base.SetUniformF("path", "size", house.LosTextureSize) texture.RenderAdvanced(0, 0, house.LosTextureSize, house.LosTextureSize, 3.1415926535, false) base.EnableShader("") }
func (sp *SpawnPoint) RenderOnFloor() { re := topSpawnRegexp() if re == nil || !re.MatchString(sp.Name) { return } var rgba [4]gl.Double gl.GetDoublev(gl.CURRENT_COLOR, &rgba[0]) gl.PushAttrib(gl.CURRENT_BIT) gl.Disable(gl.TEXTURE_2D) // This just creates a color that is consistent among all spawn points whose // names match SpawnName-.* prefix := sp.Name for i := range prefix { if prefix[i] == '-' { prefix = prefix[0:i] break } } h := fnv.New32() h.Write([]byte(prefix)) hs := h.Sum32() gl.Color4ub(gl.Ubyte(hs%256), gl.Ubyte((hs/256)%256), gl.Ubyte((hs/(256*256))%256), gl.Ubyte(255*rgba[3])) base.EnableShader("box") base.SetUniformF("box", "dx", float32(sp.Dx)) base.SetUniformF("box", "dy", float32(sp.Dy)) if !sp.temporary { base.SetUniformI("box", "temp_invalid", 0) } else if !sp.invalid { base.SetUniformI("box", "temp_invalid", 1) } else { base.SetUniformI("box", "temp_invalid", 2) } (&texture.Object{}).Data().Render(float64(sp.X), float64(sp.Y), float64(sp.Dx), float64(sp.Dy)) base.EnableShader("") gl.PopAttrib() }
func (c *Chooser) Draw(region gui.Region) { c.region = region gl.Color4ub(255, 255, 255, 255) c.layout.Background.Data().RenderNatural(region.X, region.Y) tex := c.layout.Scroller.Texture.Data() tex.RenderNatural(region.X+c.layout.Scroller.X, region.Y+c.layout.Scroller.Y) buttons := c.buttons if c.optionsHeight() <= c.layout.Options.Dy { buttons = c.non_scroll_buttons } for _, button := range buttons { button.RenderAt(region.X, region.Y) } c.layout.Options.Region().PushClipPlanes() hovered := -1 c.doOnOptions(func(index int, opt Option, data doOnOptionData) { if data.hovered { hovered = index } opt.Draw(data.x, data.y, data.dx) }) c.layout.Options.Region().PopClipPlanes() c.info_region.PushClipPlanes() if hovered != -1 { c.options[hovered].DrawInfo(c.layout.Info.X, c.layout.Info.Y, c.layout.Info.Dx, c.layout.Info.Dy) } else { if c.min == 1 && c.max == 1 && len(c.selected) == 1 { var index int for index = range c.selected { } c.options[index].DrawInfo(c.layout.Info.X, c.layout.Info.Y, c.layout.Info.Dx, c.layout.Info.Dy) } } c.info_region.PopClipPlanes() }
func (ob *OptionBasic) Draw(x, y, dx int) { gl.Color4ub(255, 255, 255, gl.Ubyte(ob.alpha)) ob.Small.Data().RenderNatural(x, y) }
// Need floor, right wall, and left wall matrices to draw the details func (room *Room) render(floor, left, right mathgl.Mat4, zoom float32, base_alpha byte, drawables []Drawable, los_tex *LosTexture, floor_drawers []FloorDrawer) { do_color := func(r, g, b, a byte) { R, G, B, A := room.Color() A = alphaMult(A, base_alpha) gl.Color4ub(gl.Ubyte(alphaMult(R, r)), gl.Ubyte(alphaMult(G, g)), gl.Ubyte(alphaMult(B, b)), gl.Ubyte(alphaMult(A, a))) } gl.Enable(gl.TEXTURE_2D) gl.Enable(gl.BLEND) gl.BlendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA) gl.Enable(gl.STENCIL_TEST) gl.ClearStencil(0) gl.Clear(gl.STENCIL_BUFFER_BIT) gl.EnableClientState(gl.VERTEX_ARRAY) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) defer gl.DisableClientState(gl.VERTEX_ARRAY) defer gl.DisableClientState(gl.TEXTURE_COORD_ARRAY) var vert roomVertex planes := []plane{ {room.left_buffer, room.Wall, &left}, {room.right_buffer, room.Wall, &right}, {room.floor_buffer, room.Floor, &floor}, } gl.PushMatrix() defer gl.PopMatrix() if los_tex != nil { gl.LoadMatrixf((*gl.Float)(&floor[0])) gl.ClientActiveTexture(gl.TEXTURE1) gl.ActiveTexture(gl.TEXTURE1) gl.Enable(gl.TEXTURE_2D) gl.EnableClientState(gl.TEXTURE_COORD_ARRAY) los_tex.Bind() gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(room.vbuffer)) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) gl.ActiveTexture(gl.TEXTURE0) base.EnableShader("los") base.SetUniformI("los", "tex2", 1) } var mul, run mathgl.Mat4 for _, plane := range planes { gl.LoadMatrixf((*gl.Float)(&floor[0])) run.Assign(&floor) // Render the doors and cut out the stencil buffer so we leave them empty // if they're open switch plane.mat { case &left: gl.StencilFunc(gl.ALWAYS, 1, 1) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) for _, door := range room.Doors { if door.Facing != FarLeft { continue } door.TextureData().Bind() R, G, B, A := door.Color() do_color(R, G, B, alphaMult(A, room.far_left.wall_alpha)) gl.ClientActiveTexture(gl.TEXTURE0) door.TextureData().Bind() if door.door_glids.floor_buffer != 0 { gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(door.threshold_glids.vbuffer)) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(door.door_glids.floor_buffer)) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.DrawElements(gl.TRIANGLES, door.door_glids.floor_count, gl.UNSIGNED_SHORT, nil) } } gl.StencilFunc(gl.NOTEQUAL, 1, 1) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) do_color(255, 255, 255, room.far_left.wall_alpha) case &right: gl.StencilFunc(gl.ALWAYS, 1, 1) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) for _, door := range room.Doors { if door.Facing != FarRight { continue } door.TextureData().Bind() R, G, B, A := door.Color() do_color(R, G, B, alphaMult(A, room.far_right.wall_alpha)) gl.ClientActiveTexture(gl.TEXTURE0) door.TextureData().Bind() if door.door_glids.floor_buffer != 0 { gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(door.threshold_glids.vbuffer)) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(door.door_glids.floor_buffer)) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.DrawElements(gl.TRIANGLES, door.door_glids.floor_count, gl.UNSIGNED_SHORT, nil) } } gl.StencilFunc(gl.NOTEQUAL, 1, 1) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) do_color(255, 255, 255, room.far_right.wall_alpha) case &floor: gl.StencilFunc(gl.ALWAYS, 2, 2) gl.StencilOp(gl.REPLACE, gl.REPLACE, gl.REPLACE) do_color(255, 255, 255, 255) } gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(room.vbuffer)) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) if los_tex != nil { los_tex.Bind() } gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(room.vbuffer)) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) // Now draw the walls gl.LoadMatrixf((*gl.Float)(&floor[0])) plane.texture.Data().Bind() gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(plane.index_buffer)) if (plane.mat == &left || plane.mat == &right) && strings.Contains(string(room.Wall.Path), "gradient.png") { base.EnableShader("gorey") base.SetUniformI("gorey", "tex", 0) base.SetUniformI("gorey", "foo", Foo) base.SetUniformF("gorey", "num_rows", Num_rows) base.SetUniformF("gorey", "noise_rate", Noise_rate) base.SetUniformF("gorey", "num_steps", Num_steps) } if plane.mat == &floor && strings.Contains(string(room.Floor.Path), "gradient.png") { base.EnableShader("gorey") base.SetUniformI("gorey", "tex", 0) base.SetUniformI("gorey", "foo", Foo) base.SetUniformF("gorey", "num_rows", Num_rows) base.SetUniformF("gorey", "noise_rate", Noise_rate) base.SetUniformF("gorey", "num_steps", Num_steps) zexp := math.Log(float64(zoom)) frac := 1 - 1/zexp frac = (frac - 0.6) * 5.0 switch { case frac > 0.7: base.SetUniformI("gorey", "range", 1) case frac > 0.3: base.SetUniformI("gorey", "range", 2) default: base.SetUniformI("gorey", "range", 3) } } if plane.mat == &floor { R, G, B, _ := room.Color() gl.Color4ub(gl.Ubyte(R), gl.Ubyte(G), gl.Ubyte(B), 255) } gl.DrawElements(gl.TRIANGLES, gl.Sizei(room.floor_count), gl.UNSIGNED_SHORT, nil) if los_tex != nil { base.EnableShader("los") } else { base.EnableShader("") } } for _, wt := range room.WallTextures { if room.wall_texture_gl_map == nil { room.wall_texture_gl_map = make(map[*WallTexture]wallTextureGlIds) room.wall_texture_state_map = make(map[*WallTexture]wallTextureState) } ids := room.wall_texture_gl_map[wt] state := room.wall_texture_state_map[wt] var new_state wallTextureState new_state.flip = wt.Flip new_state.rot = wt.Rot new_state.x = wt.X new_state.y = wt.Y new_state.room.x = room.X new_state.room.y = room.Y new_state.room.dx = room.Size.Dx new_state.room.dy = room.Size.Dy if new_state != state { wt.setupGlStuff(room.X, room.Y, room.Size.Dx, room.Size.Dy, &ids) room.wall_texture_gl_map[wt] = ids room.wall_texture_state_map[wt] = new_state } gl.LoadMatrixf((*gl.Float)(&floor[0])) if ids.vbuffer != 0 { wt.Texture.Data().Bind() R, G, B, A := wt.Color() gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(ids.vbuffer)) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) if ids.floor_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 2, 2) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(ids.floor_buffer)) gl.Color4ub(gl.Ubyte(R), gl.Ubyte(G), gl.Ubyte(B), gl.Ubyte(A)) gl.DrawElements(gl.TRIANGLES, ids.floor_count, gl.UNSIGNED_SHORT, nil) } if ids.left_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 1, 1) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(ids.left_buffer)) do_color(R, G, B, alphaMult(A, room.far_left.wall_alpha)) gl.DrawElements(gl.TRIANGLES, ids.left_count, gl.UNSIGNED_SHORT, nil) } if ids.right_buffer != 0 { gl.StencilFunc(gl.ALWAYS, 1, 1) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(ids.right_buffer)) do_color(R, G, B, alphaMult(A, room.far_right.wall_alpha)) gl.DrawElements(gl.TRIANGLES, ids.right_count, gl.UNSIGNED_SHORT, nil) } } } base.EnableShader("marble") base.SetUniformI("marble", "tex2", 1) base.SetUniformF("marble", "room_x", float32(room.X)) base.SetUniformF("marble", "room_y", float32(room.Y)) for _, door := range room.Doors { door.setupGlStuff(room) if door.threshold_glids.vbuffer == 0 { continue } if door.AlwaysOpen() { continue } if door.highlight_threshold { gl.Color4ub(255, 255, 255, 255) } else { gl.Color4ub(128, 128, 128, 255) } gl.BindBuffer(gl.ARRAY_BUFFER, gl.Uint(door.threshold_glids.vbuffer)) gl.VertexPointer(3, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.x))) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.u))) gl.ClientActiveTexture(gl.TEXTURE1) gl.TexCoordPointer(2, gl.FLOAT, gl.Sizei(unsafe.Sizeof(vert)), gl.Pointer(unsafe.Offsetof(vert.los_u))) gl.ClientActiveTexture(gl.TEXTURE0) gl.BindBuffer(gl.ELEMENT_ARRAY_BUFFER, gl.Uint(door.threshold_glids.floor_buffer)) gl.DrawElements(gl.TRIANGLES, door.threshold_glids.floor_count, gl.UNSIGNED_SHORT, nil) } base.EnableShader("") if los_tex != nil { base.EnableShader("") gl.ActiveTexture(gl.TEXTURE1) gl.Disable(gl.TEXTURE_2D) gl.ActiveTexture(gl.TEXTURE0) gl.ClientActiveTexture(gl.TEXTURE1) gl.DisableClientState(gl.TEXTURE_COORD_ARRAY) gl.ClientActiveTexture(gl.TEXTURE0) } run.Assign(&floor) mul.Translation(float32(-room.X), float32(-room.Y), 0) run.Multiply(&mul) gl.LoadMatrixf((*gl.Float)(&run[0])) gl.StencilFunc(gl.EQUAL, 2, 3) gl.StencilOp(gl.KEEP, gl.KEEP, gl.KEEP) room_rect := image.Rect(room.X, room.Y, room.X+room.Size.Dx, room.Y+room.Size.Dy) for _, fd := range floor_drawers { x, y := fd.Pos() dx, dy := fd.Dims() if room_rect.Overlaps(image.Rect(x, y, x+dx, y+dy)) { fd.RenderOnFloor() } } do_color(255, 255, 255, 255) gl.LoadIdentity() gl.Disable(gl.STENCIL_TEST) room.renderFurniture(floor, 255, drawables, los_tex) gl.ClientActiveTexture(gl.TEXTURE1) gl.Disable(gl.TEXTURE_2D) gl.ClientActiveTexture(gl.TEXTURE0) base.EnableShader("") }
func (room *Room) renderFurniture(floor mathgl.Mat4, base_alpha byte, drawables []Drawable, los_tex *LosTexture) { board_to_window := func(mx, my float32) (x, y float32) { v := mathgl.Vec4{X: mx, Y: my, W: 1} v.Transform(&floor) x, y = v.X, v.Y return } var all []RectObject for _, d := range drawables { x, y := d.Pos() if x < room.X { continue } if y < room.Y { continue } if x >= room.X+room.Size.Dx { continue } if y >= room.Y+room.Size.Dy { continue } all = append(all, offsetDrawable{d, -room.X, -room.Y}) } // Do not include temporary objects in the ordering, since they will likely // overlap with other objects and make it difficult to determine the proper // ordering. Just draw the temporary ones last. var temps []RectObject for _, f := range room.Furniture { if f.temporary { temps = append(temps, f) } else { all = append(all, f) } } all = OrderRectObjects(all) for i := range all { temps = append(temps, all[i]) } for i := len(temps) - 1; i >= 0; i-- { d := temps[i].(Drawable) fx, fy := d.FPos() near_x, near_y := float32(fx), float32(fy) idx, idy := d.Dims() dx, dy := float32(idx), float32(idy) leftx, _ := board_to_window(near_x, near_y+dy) rightx, _ := board_to_window(near_x+dx, near_y) _, boty := board_to_window(near_x, near_y) vis := visibilityOfObject(room.X, room.Y, d, los_tex) r, g, b, a := d.Color() r = alphaMult(r, vis) g = alphaMult(g, vis) b = alphaMult(b, vis) a = alphaMult(a, vis) a = alphaMult(a, base_alpha) gl.Color4ub(gl.Ubyte(r), gl.Ubyte(g), gl.Ubyte(b), gl.Ubyte(a)) d.Render(mathgl.Vec2{leftx, boty}, rightx-leftx) } }