public ChunkModel(BaseChunk chunk, ITextureStorage storage) { this.chunk = chunk; this.storage = storage; UpdateModel(); }
private static int RegisterImage(ITextureStorage storage, Image <Rgba32> img) { var id = storage.CreateTexture(img.Width, img.Height, TextureFormat.Rgba32); ReadOnlySpan <Rgba32> pixelSpan = img.GetPixelSpan(); storage.SetData(id, pixelSpan); return(id); }
public Game(IWorld world, IPlayer player, ITextureStorage textures, IRenderer renderer) { World = world; Player = player; this.textures = textures; this.renderer = renderer; Load += OnLoad; VSync = VSyncMode.On; }
/// <summary> /// Load a system font and register it in the texture storage. /// </summary> /// <param name="name">Name of the system font.</param> /// <param name="size">Size to render the font at.</param> /// <param name="ranges">The character ranges to render to the font atlas.</param> /// <param name="fallbackCharacter">Optional fallback character for the font. Defaults to <c>0</c> (no fallback).</param> public static TextureFont LoadSystemFont(this ITextureStorage storage, string name, float size, IEnumerable <Range <int> > ranges, int fallbackCharacter = 0) { FontAtlasHelpers.CreateSystemFont(name, size, ranges, out var glyphMap, out var image); var width = image.Width; var height = image.Height; var texId = RegisterImage(storage, image); image.Dispose(); return(new TextureFont(glyphMap.ToUvGlyphMap(width, height), texId, fallbackCharacter)); }
/// <summary> /// Load a font and register it in the texture storage. /// </summary> /// <param name="storage">The texture storage to register the font atlas.</param> /// <param name="path">Path to the font file.</param> /// <param name="size">Size to render the font at.</param> /// <param name="fallbackCharacter">Optional fallback character for the font. Defaults to <c>0</c> (no fallback).</param> public static TextureFont LoadFont(this ITextureStorage storage, string path, float size, int fallbackCharacter = 0) { FontAtlasHelpers.CreateFont(path, size, out var glyphMap, out var image); var width = image.Width; var height = image.Height; var texId = RegisterImage(storage, image); image.Dispose(); return(new TextureFont(glyphMap.ToUvGlyphMap(width, height), texId, fallbackCharacter)); }
public virtual IModel GetModel(ITextureStorage storage, ICamera camera) { if (Model == null) { if (!isPendingModel) { isPendingModel = true; Task.Run(() => GenerateModel(storage)); } } return(Model); }
public void Render(ICamera camera, ITextureStorage storage, IEnumerable <IEntity> entities) { using (shader.Start()) { foreach (var entity in entities) { var model = entity.GetModel(storage, camera); if (model == null) { continue; } using (model.Start()) { shader.SetIsTextured(model.IsTextured); shader.SetTransformationMatrix(entity.TransformMatrix); shader.SetViewMatrix(camera.ViewMatrix); GL.DrawElements(model.DrawingMode, model.VerticesCount, DrawElementsType.UnsignedInt, 0); } } } }
/// <summary> /// Load an image from a path and register it in the texture storage. /// </summary> /// <param name="storage">The texture storage to register the texture in.</param> /// <param name="path">Path to the image.</param> public static int LoadTexture(this ITextureStorage storage, string path) { using (var img = Image.Load <Rgba32>(path)) return(RegisterImage(storage, img)); }
/// <summary> /// Load an image from a stream and register it in the texture storage. /// </summary> /// <param name="storage">The texture storage to register the texture in.</param> /// <param name="imageStream">Stream of the image data.</param> public static int LoadTexture(this ITextureStorage storage, Stream imageStream) { using (var img = Image.Load <Rgba32>(imageStream)) return(RegisterImage(storage, img)); }
public IModel GetModel(ITextureStorage storage, ICamera camera) { return(model); }
IModel IEntity.GetModel(ITextureStorage storage, ICamera camera) { return(GetModel(storage, camera)); }
private void GenerateModel(ITextureStorage textureStorage) { Model = new ChunkModel(this, textureStorage); isPendingModel = false; }