Add functionality for isometric block drawing for gui, simplify and arrange graphics api info, add warning for intel graphics cards users that they should use Direct3D build because of the lousy OpenGL implementation.

This commit is contained in:
UnknownShadow200 2015-10-06 20:15:48 +11:00
parent bab9b11b49
commit b000dcd543
8 changed files with 140 additions and 13 deletions

View file

@ -0,0 +1,96 @@
using System;
using ClassicalSharp.GraphicsAPI;
using OpenTK;
using ClassicalSharp.Model;
namespace ClassicalSharp {
public static class IsometricBlockDrawer {
static BlockInfo info;
static ModelCache cache;
static TerrainAtlas2D atlas;
static float blockHeight;
static int index;
static float scale;
public static void Draw( Game game, byte block, float size, float x, float y ) {
info = game.BlockInfo;
cache = game.ModelCache;
atlas = game.TerrainAtlas;
blockHeight = info.Height[block];
index = 0;
scale = size;
// screen to isometric coords
pos.X = x; pos.Y = -y; pos.Z = 0;
pos = Utils.RotateX( pos, (float)Utils.DegreesToRadians( -35.264f ) );
pos = Utils.RotateY( pos, (float)Utils.DegreesToRadians( 45f ) );
Console.WriteLine( pos );
if( info.IsSprite[block] ) {
DrawXFace( block, 0f, TileSide.Right );
DrawZFace( block, 0f, TileSide.Back );
} else {
DrawXFace( block, scale, TileSide.Left );
DrawZFace( block, -scale, TileSide.Back );
DrawYFace( block, scale * blockHeight, TileSide.Top );
}
game.Graphics.DrawDynamicIndexedVb( DrawMode.Triangles, cache.vb,
cache.vertices, index, index * 6 / 4 );
}
public static void SetupState( IGraphicsApi graphics, bool setFog ) {
graphics.PushMatrix();
Matrix4 m = Matrix4.RotateY( (float)Utils.DegreesToRadians( 45f ) ) *
Matrix4.RotateX( (float)Utils.RadiansToDegrees( -35.264f ) );
graphics.LoadMatrix( ref m );
if( setFog )
graphics.Fog = false;
}
public static void RestoreState( IGraphicsApi graphics, bool setFog ) {
graphics.PopMatrix();
if( setFog )
graphics.Fog = true;
}
static Vector3 pos = Vector3.Zero;
static FastColour col = FastColour.White;
static void DrawYFace( byte block, float y, int side ) {
int texId = info.GetTextureLoc( block, side );
TextureRectangle rec = atlas.GetTexRec( texId );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + y, pos.Z - scale, rec.U2, rec.V2, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + y, pos.Z + scale, rec.U1, rec.V2, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + y, pos.Z + scale, rec.U1, rec.V1, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + y, pos.Z - scale, rec.U2, rec.V1, col );
}
static void DrawZFace( byte block, float z, int side ) {
int texId = info.GetTextureLoc( block, side );
TextureRectangle rec = atlas.GetTexRec( texId );
if( blockHeight != 1 )
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y - scale * blockHeight, pos.Z + z, rec.U1, rec.V2, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X - scale, pos.Y + scale * blockHeight, pos.Z + z, rec.U1, rec.V1, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y + scale * blockHeight, pos.Z + z, rec.U2, rec.V1, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + scale, pos.Y - scale * blockHeight, pos.Z + z, rec.U2, rec.V2, col );
}
static void DrawXFace( byte block, float x, int side ) {
int texId = info.GetTextureLoc( block, side );
TextureRectangle rec = atlas.GetTexRec( texId );
if( blockHeight != 1 )
rec.V2 = rec.V1 + blockHeight * TerrainAtlas2D.invElementSize;
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y - scale * blockHeight, pos.Z - scale, rec.U1, rec.V2, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + scale * blockHeight, pos.Z - scale, rec.U1, rec.V1, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y + scale * blockHeight, pos.Z + scale, rec.U2, rec.V1, col );
cache.vertices[index++] = new VertexPos3fTex2fCol4b( pos.X + x, pos.Y - scale * blockHeight, pos.Z + scale, rec.U2, rec.V2, col );
}
}
}

View file

@ -1,6 +1,9 @@
using System;
using System.Drawing;
using OpenTK;
using OpenTK.Input;
using ClassicalSharp.GraphicsAPI;
using ClassicalSharp.Renderers;
namespace ClassicalSharp {
@ -27,7 +30,7 @@ namespace ClassicalSharp {
public override void Init() {
int y = game.Height - blockSize;
Size size = new Size( 32, 32 );
Size size = new Size( blockSize, blockSize );
using( Bitmap bmp = IDrawer2D.CreatePow2Bitmap( size ) ) {
using( IDrawer2D drawer = game.Drawer2D ) {
drawer.SetBitmap( bmp );
@ -59,6 +62,12 @@ namespace ClassicalSharp {
selectedX = barTextures[i].X1;
}
}
//bool setFog = game.EnvRenderer is StandardEnvRenderer;
//IsometricBlockDrawer.SetupState( graphicsApi, setFog );
//IsometricBlockDrawer.Draw( game, (byte)Block.Brick, 200, 100 + 100 * (float)Math.Sin( game.accumulator ), 100 );
//IsometricBlockDrawer.RestoreState( graphicsApi, setFog );
selectedBlock.X1 = selectedX;
selectedBlock.Render( graphicsApi );
graphicsApi.Texturing = false;

View file

@ -65,6 +65,7 @@
<Reference Include="System.Windows.Forms" />
</ItemGroup>
<ItemGroup>
<Compile Include="2D\IsometricBlockDrawer.cs" />
<Compile Include="2D\Drawing\DrawTextArgs.cs" />
<Compile Include="2D\Drawing\GdiPlusDrawer2D.cs" />
<Compile Include="2D\Drawing\IDrawer2D.cs" />

View file

@ -549,11 +549,15 @@ namespace ClassicalSharp.GraphicsAPI {
public override void PrintApiSpecificInfo() {
Utils.Log( "--Using Direct3D 9--" );
Utils.Log( "Tex memory available: " + (uint)device.AvailableTextureMemory );
Utils.Log( "Vertex processing mode: " + createFlags );
Utils.Log( "Adapter: " + d3d.Adapters[0].Details.Description );
Utils.Log( "Mode: " + createFlags );
float texMem = (uint)device.AvailableTextureMemory / 1024f / 1024f;
Utils.Log( "Texture mem: " + texMem + " MB" );
Utils.Log( "Max 2D texture dimensions: " + MaxTextureDimensions );
Utils.Log( "Depth buffer format: " + depthFormat );
Utils.Log( "Back buffer format: " + viewFormat );
Utils.Log( "Adapter description: " + d3d.Adapters[0].Details.Description );
Utils.Log( "" );
Utils.Log( "Device caps: " + caps.DeviceCaps );
}

View file

@ -167,8 +167,6 @@ namespace ClassicalSharp.GraphicsAPI {
public void PrintGraphicsInfo() {
Console.ForegroundColor = ConsoleColor.Green;
PrintApiSpecificInfo();
Utils.Log( "Max 2D texture dimensions: " + MaxTextureDimensions );
Utils.Log( "== End of graphics info ==" );
Console.ResetColor();
}

View file

@ -376,16 +376,23 @@ namespace ClassicalSharp.GraphicsAPI {
public unsafe override void PrintApiSpecificInfo() {
Utils.Log( "--Using OpenGL--" );
Utils.Log( "Vendor: " + new String( (sbyte*)GL.GetString( StringName.Vendor ) ) );
Utils.Log( "Renderer: " + new String( (sbyte*)GL.GetString( StringName.Renderer ) ) );
Utils.Log( "Version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
string renderer = new String( (sbyte*)GL.GetString( StringName.Renderer ) );
Utils.Log( "Renderer: " + renderer );
Utils.Log( "GL version: " + new String( (sbyte*)GL.GetString( StringName.Version ) ) );
Utils.Log( "Max 2D texture dimensions: " + MaxTextureDimensions );
int depthBits = 0;
GL.GetIntegerv( GetPName.DepthBits, &depthBits );
Utils.Log( "Depth buffer bits: " + depthBits );
if( depthBits < 24 ) {
Utils.LogWarning( "Depth buffer is less than 24 bits, you may see some issues " +
"with disappearing and/or 'white' graphics." );
Utils.LogWarning( "If this bothers you, type \"/client rendertype legacy\" (without quotes) " +
"after you have loaded the first map." );
if( renderer.Contains( "Intel" ) ) {
Utils.LogWarning( "Intel graphics cards are known to have issues with the OpenGL build." );
Utils.LogWarning( "VSync may not work, and you may see disappearing clouds and map edges." );
Utils.LogWarning( "" );
Utils.LogWarning( "If you use Windows, try downloading and using the " +
"Direct3D9 build as it doesn't have these problems." );
Utils.LogWarning( "Alternatively, the disappearing graphics can be partially " +
"fixed by typing \"/client rendertype legacy\" into chat." );
}
}

View file

@ -129,6 +129,12 @@ namespace ClassicalSharp {
return new Vector3( cosA * x - sinA * z, y, sinA * x + cosA * z );
}
public static Vector3 RotateX( Vector3 v, float angle ) {
float cosA = (float)Math.Cos( angle );
float sinA = (float)Math.Sin( angle );
return new Vector3( v.X, cosA * v.Y + sinA * v.Z, -sinA * v.Y + cosA * v.Z );
}
public static Vector3 RotateX( float x, float y, float z, float cosA, float sinA ) {
return new Vector3( x, cosA * y + sinA * z, -sinA * y + cosA * z );
}

View file

@ -225,6 +225,12 @@ namespace Launcher {
}
internal static void UpdateResumeInfo( GameStartData data, bool classiCubeSkins ) {
// If the client has changed some settings in the meantime, make sure we keep the changes
try {
Options.Load();
} catch( IOException ) {
}
Options.Set( "launcher-username", data.Username );
Options.Set( "launcher-ip", data.Ip );
Options.Set( "launcher-port", data.Port );