public void Init( Game game ) { this.game = game; api = game.Graphics; game.Events.TexturePackChanged += TexturePackChanged; game.Events.TextureChanged += TextureChanged; }
public virtual void Init( Game game ) { this.game = game; map = game.World; graphics = game.Graphics; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; }
public ChunkMeshBuilder( Game game ) { this.game = game; graphics = game.Graphics; info = game.BlockInfo; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; }
public SelectionBox( Vector3I start, Vector3I end, FastColour col, IGraphicsApi graphics ) { Graphics = graphics; Min = Vector3I.Min( start, end ); Max = Vector3I.Max( start, end ); int index = 0; Vector3 p1 = (Vector3)Min + new Vector3( 1/16f, 1/16f, 1/16f ); Vector3 p2 = (Vector3)Max - new Vector3( 1/16f, 1/16f, 1/16f ); YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p1.Y, col ); // bottom YQuad( ref index, p1.X, p1.Z, p2.X, p2.Z, p2.Y, col ); // top XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p1.Z, col ); // sides XQuad( ref index, p1.X, p2.X, p1.Y, p2.Y, p2.Z, col ); ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p1.X, col ); ZQuad( ref index, p1.Z, p2.Z, p1.Y, p2.Y, p2.X, col ); col = new FastColour( (byte)~col.R, (byte)~col.G, (byte)~col.B ); // bottom face Line( ref index, p1.X, p1.Y, p1.Z, p2.X, p1.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p1.Y, p2.Z, col ); Line( ref index, p2.X, p1.Y, p2.Z, p1.X, p1.Y, p2.Z, col ); Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p1.Y, p1.Z, col ); // top face Line( ref index, p1.X, p2.Y, p1.Z, p2.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p2.Y, p1.Z, p2.X, p2.Y, p2.Z, col ); Line( ref index, p2.X, p2.Y, p2.Z, p1.X, p2.Y, p2.Z, col ); Line( ref index, p1.X, p2.Y, p2.Z, p1.X, p2.Y, p1.Z, col ); // side faces Line( ref index, p1.X, p1.Y, p1.Z, p1.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p1.Z, p2.X, p2.Y, p1.Z, col ); Line( ref index, p2.X, p1.Y, p2.Z, p2.X, p2.Y, p2.Z, col ); Line( ref index, p1.X, p1.Y, p2.Z, p1.X, p2.Y, p2.Z, col ); Vb = Graphics.CreateVb( vertices, VertexFormat.Pos3fCol4b, VerticesCount + LineVerticesCount ); }
public virtual void Init() { graphics = game.Graphics; game.Events.OnNewMap += OnNewMap; game.Events.OnNewMapLoaded += OnNewMapLoaded; game.Events.EnvVariableChanged += EnvVariableChanged; }
public void Init( Game game ) { this.game = game; map = game.World; graphics = game.Graphics; info = game.BlockInfo; weatherVb = graphics.CreateDynamicVb( VertexFormat.P3fT2fC4b, vertices.Length ); }
public WeatherRenderer( Game game ) { this.game = game; map = game.Map; graphics = game.Graphics; info = game.BlockInfo; weatherVb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 12 * 9 * 9 ); }
protected void InitRenderingData() { api = game.Graphics; using( Font font = new Font( "Arial", 14 ) ) { DrawTextArgs args = new DrawTextArgs( DisplayName, font, true ); nameTex = game.Drawer2D.MakeBitmappedTextTexture( ref args, 0, 0 ); } }
public void Init( Game game ) { this.game = game; map = game.World; graphics = game.Graphics; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.ViewDistanceChanged += ResetSidesAndEdges; game.Events.TerrainAtlasChanged += ResetTextures; }
public GdiPlusDrawer2D( IGraphicsApi graphics ) { this.graphics = graphics; format = StringFormat.GenericTypographic; format.FormatFlags |= StringFormatFlags.MeasureTrailingSpaces; format.Trimming = StringTrimming.None; //format.FormatFlags |= StringFormatFlags.NoWrap; //format.FormatFlags |= StringFormatFlags.NoClip; measuringBmp = new Bitmap( 1, 1 ); measuringGraphics = Graphics.FromImage( measuringBmp ); measuringGraphics.TextRenderingHint = TextRenderingHint.AntiAlias; }
public MapRenderer( Game game ) { this.game = game; _1Dcount = game.TerrainAtlas1D.TexIds.Length; builder = new ChunkMeshBuilder( game ); api = game.Graphics; elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap; info = game.BlockInfo; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.Events.OnNewMap += OnNewMap; game.Events.OnNewMapLoaded += OnNewMapLoaded; game.Events.EnvVariableChanged += EnvVariableChanged; }
public void Init( Game game ) { this.game = game; map = game.World; graphics = game.Graphics; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.ViewDistanceChanged += ResetSidesAndEdges; game.Events.TerrainAtlasChanged += ResetTextures; MakeTexture( ref edgeTexId, ref lastEdgeTexLoc, map.EdgeBlock ); MakeTexture( ref sideTexId, ref lastSideTexLoc, map.SidesBlock ); ResetSidesAndEdges( null, null ); }
public void RenderHoveredNames( IGraphicsApi api, double delta, float t ) { if( !ShowHoveredNames ) return; api.Texturing = true; api.AlphaTest = true; api.DepthTest = false; for( int i = 0; i < Players.Length; i++ ) { if( Players[i] != null && i == closestId ) Players[i].RenderName(); } api.Texturing = false; api.AlphaTest = false; api.DepthTest = true; }
public ChunkUpdater( Game game, MapRenderer renderer ) { this.game = game; this.renderer = renderer; info = game.BlockInfo; builder = new ChunkMeshBuilder( game ); api = game.Graphics; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.WorldEvents.OnNewMap += OnNewMap; game.WorldEvents.OnNewMapLoaded += OnNewMapLoaded; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.BlockDefinitionChanged += BlockDefinitionChanged; game.Events.ViewDistanceChanged += ViewDistanceChanged; game.Events.ProjectionChanged += ProjectionChanged; }
public static void Draw( Game game, byte block, float size, float x, float y ) { info = game.BlockInfo; cache = game.ModelCache; atlas = game.TerrainAtlas1D; minBB = info.MinBB[block]; maxBB = info.MaxBB[block]; fullBright = info.FullBright[block]; if( info.IsSprite[block] ) { minBB = Vector3.Zero; maxBB = Vector3.One; } if( info.IsAir[block] ) return; index = 0; api = game.Graphics; // isometric coords size: cosY * -scale - sinY * scale // we need to divide by (2 * cosY), as the calling function expects size to be in pixels. scale = size / (2 * cosY); // screen to isometric coords (cos(-x) = cos(x), sin(-x) = -sin(x)) pos.X = x; pos.Y = y; pos.Z = 0; Utils.RotateX( ref pos.Y, ref pos.Z, cosX, -sinX ); Utils.RotateY( ref pos.X, ref pos.Z, cosY, -sinY ); if( info.IsSprite[block] ) { SpriteXQuad( block, Side.Right, false ); SpriteZQuad( block, Side.Back, false ); SpriteZQuad( block, Side.Back, true ); SpriteXQuad( block, Side.Right, true ); } else { XQuad( block, Make( maxBB.X ), Side.Left ); ZQuad( block, Make( minBB.Z ), Side.Back ); YQuad( block, Make( maxBB.Y ), Side.Top ); } if( index == 0 ) return; if( atlas.TexIds[texIndex] != lastTexId ) { lastTexId = atlas.TexIds[texIndex]; api.BindTexture( lastTexId ); } for( int i = 0; i < index; i++ ) TransformVertex( ref cache.vertices[i] ); api.UpdateDynamicIndexedVb( DrawMode.Triangles, cache.vb, cache.vertices, index, index * 6 / 4 ); }
public ChunkUpdater( Game game, MapRenderer renderer ) { this.game = game; this.renderer = renderer; info = game.BlockInfo; renderer._1DUsed = game.TerrainAtlas1D.CalcMaxUsedRow( game.TerrainAtlas, info ); renderer.totalUsed = new int[game.TerrainAtlas1D.TexIds.Length]; RecalcBooleans( true ); builder = new ChunkMeshBuilder( game ); api = game.Graphics; elementsPerBitmap = game.TerrainAtlas1D.elementsPerBitmap; game.Events.TerrainAtlasChanged += TerrainAtlasChanged; game.WorldEvents.OnNewMap += OnNewMap; game.WorldEvents.OnNewMapLoaded += OnNewMapLoaded; game.WorldEvents.EnvVariableChanged += EnvVariableChanged; game.Events.BlockDefinitionChanged += BlockDefinitionChanged; game.Events.ViewDistanceChanged += ViewDistanceChanged; game.Events.ProjectionChanged += ProjectionChanged; }
static void CheckShadowTexture( IGraphicsApi graphics ) { if( shadowTex != -1 ) return; const int size = 128, half = size / 2; using( Bitmap bmp = new Bitmap( size, size ) ) using( FastBitmap fastBmp = new FastBitmap( bmp, true, false ) ) { int inPix = new FastColour( 0, 0, 0, 200 ).ToArgb(); int outPix = new FastColour( 0, 0, 0, 0 ).ToArgb(); for( int y = 0; y < fastBmp.Height; y++ ) { int* row = fastBmp.GetRowPtr( y ); for( int x = 0; x < fastBmp.Width; x++ ) { double dist = (half - (x + 0.5)) * (half - (x + 0.5)) + (half - (y + 0.5)) * (half - (y + 0.5)); row[x] = dist < half * half ? inPix : outPix; } } shadowTex = graphics.CreateTexture( fastBmp ); } }
protected override void OnLoad( EventArgs e ) { #if !USE_DX Graphics = new OpenGLApi(); #else Graphics = new Direct3D9Api( this ); #endif try { Options.Load(); } catch( IOException ) { Utils.LogWarning( "Unable to load options.txt" ); } ViewDistance = Options.GetInt( "viewdist", 16, 8192, 512 ); Keys = new KeyMap(); InputHandler = new InputHandler( this ); Chat = new ChatLog( this ); Drawer2D = new GdiPlusDrawer2D( Graphics ); defaultIb = Graphics.MakeDefaultIb(); ModelCache = new ModelCache( this ); ModelCache.InitCache(); AsyncDownloader = new AsyncDownloader( skinServer ); Graphics.PrintGraphicsInfo(); TerrainAtlas1D = new TerrainAtlas1D( Graphics ); TerrainAtlas = new TerrainAtlas2D( Graphics, Drawer2D ); Animations = new Animations( this ); TexturePackExtractor extractor = new TexturePackExtractor(); extractor.Extract( defaultTexPack, this ); Inventory = new Inventory( this ); BlockInfo = new BlockInfo(); BlockInfo.Init(); BlockInfo.SetDefaultBlockPermissions( Inventory.CanPlace, Inventory.CanDelete ); Map = new Map( this ); LocalPlayer = new LocalPlayer( this ); Players[255] = LocalPlayer; width = Width; height = Height; MapRenderer = new MapRenderer( this ); MapEnvRenderer = new MapEnvRenderer( this ); EnvRenderer = new StandardEnvRenderer( this ); if( IPAddress == null ) { Network = new Singleplayer.SinglePlayerServer( this ); } else { Network = new NetworkProcessor( this ); } Graphics.LostContextFunction = Network.Tick; firstPersonCam = new FirstPersonCamera( this ); thirdPersonCam = new ThirdPersonCamera( this ); Camera = firstPersonCam; CommandManager = new CommandManager(); CommandManager.Init( this ); SelectionManager = new SelectionManager( this ); ParticleManager = new ParticleManager( this ); WeatherRenderer = new WeatherRenderer( this ); WeatherRenderer.Init(); Graphics.SetVSync( this, true ); Graphics.DepthTest = true; Graphics.DepthTestFunc( CompareFunc.LessEqual ); //Graphics.DepthWrite = true; Graphics.AlphaBlendFunc( BlendFunc.SourceAlpha, BlendFunc.InvSourceAlpha ); Graphics.AlphaTestFunc( CompareFunc.Greater, 0.5f ); Title = Utils.AppName; fpsScreen = new FpsScreen( this ); fpsScreen.Init(); Culling = new FrustumCulling(); EnvRenderer.Init(); MapEnvRenderer.Init(); Picking = new PickingRenderer( this ); string connectString = "Connecting to " + IPAddress + ":" + Port + ".."; SetNewScreen( new LoadingMapScreen( this, connectString, "Reticulating splines" ) ); Network.Connect( IPAddress, Port ); }
public TerrainAtlas1D( IGraphicsApi graphics ) { this.graphics = graphics; }
public IModel( Game game ) { this.game = game; graphics = game.Graphics; cache = game.ModelCache; }
public void Init( Game game ) { this.game = game; Graphics = game.Graphics; }
/// <summary> Renders the names of all player entities contained in this list.<br/> /// If ShowHoveredNames is false, this method only renders names of entities that are /// not currently being looked at by the user. </summary> public void RenderNames( IGraphicsApi api, double delta, float t ) { if( NamesMode == NameMode.NoNames ) return; api.Texturing = true; api.AlphaTest = true; LocalPlayer localP = game.LocalPlayer; Vector3 eyePos = localP.EyePosition; closestId = 255; if( NamesMode != NameMode.All ) closestId = GetClosetPlayer( game.LocalPlayer ); if( NamesMode == NameMode.HoveredOnly || !game.LocalPlayer.Hacks.CanSeeAllNames ) { api.Texturing = false; api.AlphaTest = false; return; } for( int i = 0; i < Players.Length; i++ ) { if( Players[i] == null ) continue; if( i != closestId || i == 255 ) Players[i].RenderName(); } api.Texturing = false; api.AlphaTest = false; }
public SelectionManager( Game window ) { game = window; Graphics = window.Graphics; window.Events.OnNewMap += OnNewMap; }
public CanvasDrawer2D(IGraphicsApi graphics) { this.graphics = graphics; measuringBmp = Bitmap.CreateBitmap(1, 1, Bitmap.Config.Argb8888); measuringC = new Canvas(measuringBmp); }
public ParticleManager( Game game ) { this.game = game; graphics = game.Graphics; vb = graphics.CreateDynamicVb( VertexFormat.Pos3fTex2fCol4b, 1000 ); }
public TerrainAtlas2D( IGraphicsApi graphics, IDrawer2D drawer ) { this.graphics = graphics; this.drawer = drawer; }
public void Render( IGraphicsApi graphics, FastColour colour ) { graphics.BindTexture( ID ); graphics.Draw2DTexture( ref this, colour ); }
/// <summary> Renders the models of all player entities contained in this list. </summary> public void RenderModels( IGraphicsApi api, double delta, float t ) { api.Texturing = true; api.AlphaTest = true; for( int i = 0; i < Players.Length; i++ ) { if( Players[i] == null ) continue; Players[i].RenderModel( delta, t ); } api.Texturing = false; api.AlphaTest = false; }
public Animations( Game game ) { this.game = game; api = game.Graphics; }
public ModelCache( Game window ) { this.game = window; api = game.Graphics; }
public PickingRenderer( Game window ) { graphics = window.Graphics; vb = graphics.CreateDynamicVb( VertexFormat.Pos3fCol4b, verticesCount ); info = window.BlockInfo; }
public MapBordersRenderer(Game game) { this.game = game; map = game.Map; graphics = game.Graphics; }