Combine player rendering functions into Player class, remove D3DX reference since we longer need it.

This commit is contained in:
UnknownShadow200 2015-07-21 18:48:51 +10:00
parent 0417790d6a
commit 25d7cbda9e
22 changed files with 157 additions and 138 deletions

View File

@ -81,7 +81,6 @@
<ItemGroup> <ItemGroup>
<Reference Include="Microsoft.DirectX" Condition=" '$(Configuration)' == 'Debug_DX32' " /> <Reference Include="Microsoft.DirectX" Condition=" '$(Configuration)' == 'Debug_DX32' " />
<Reference Include="Microsoft.DirectX.Direct3D" Condition=" '$(Configuration)' == 'Debug_DX32' " /> <Reference Include="Microsoft.DirectX.Direct3D" Condition=" '$(Configuration)' == 'Debug_DX32' " />
<Reference Include="Microsoft.DirectX.Direct3DX" Condition=" '$(Configuration)' == 'Debug_DX32' " />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Drawing" /> <Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
@ -119,6 +118,7 @@
<Compile Include="Entities\Particles\ParticleManager.cs" /> <Compile Include="Entities\Particles\ParticleManager.cs" />
<Compile Include="Entities\Particles\TerrainParticle.cs" /> <Compile Include="Entities\Particles\TerrainParticle.cs" />
<Compile Include="Entities\Player.cs" /> <Compile Include="Entities\Player.cs" />
<Compile Include="Entities\Player.Rendering.cs" />
<Compile Include="Game\Game.Chat.cs" /> <Compile Include="Game\Game.Chat.cs" />
<Compile Include="Game\Game.cs" /> <Compile Include="Game\Game.cs" />
<Compile Include="Game\Game.Events.cs" /> <Compile Include="Game\Game.Events.cs" />
@ -169,7 +169,6 @@
<Compile Include="Rendering\MapEnvRenderer.cs" /> <Compile Include="Rendering\MapEnvRenderer.cs" />
<Compile Include="Rendering\MapRenderer.cs" /> <Compile Include="Rendering\MapRenderer.cs" />
<Compile Include="Rendering\PickingRenderer.cs" /> <Compile Include="Rendering\PickingRenderer.cs" />
<Compile Include="Rendering\PlayerRenderer.cs" />
<Compile Include="Rendering\StandardEnvRenderer.cs" /> <Compile Include="Rendering\StandardEnvRenderer.cs" />
<Compile Include="Rendering\WeatherRenderer.cs" /> <Compile Include="Rendering\WeatherRenderer.cs" />
<Compile Include="Selections\SelectionBox.cs" /> <Compile Include="Selections\SelectionBox.cs" />

View File

@ -62,12 +62,6 @@ namespace ClassicalSharp {
} }
} }
public override void Despawn() {
if( renderer != null ) {
renderer.Dispose();
}
}
public override void Tick( double delta ) { public override void Tick( double delta ) {
if( Window.Map.IsNotLoaded ) return; if( Window.Map.IsNotLoaded ) return;
//Window.Title = ( GC.GetTotalMemory( false ) / 1024.0 / 1024.0 ).ToString(); // TODO: temp debug statement //Window.Title = ( GC.GetTotalMemory( false ) / 1024.0 / 1024.0 ).ToString(); // TODO: temp debug statement
@ -82,19 +76,19 @@ namespace ClassicalSharp {
nextPos = Position; nextPos = Position;
Position = lastPos; Position = lastPos;
UpdateAnimState( lastPos, nextPos, delta ); UpdateAnimState( lastPos, nextPos, delta );
if( renderer != null ) { if( api != null ) {
CheckSkin(); CheckSkin();
} }
} }
public override void Render( double deltaTime, float t ) { public override void Render( double deltaTime, float t ) {
if( !Window.Camera.IsThirdPerson ) return; if( !Window.Camera.IsThirdPerson ) return;
if( renderer == null ) { if( api == null ) {
renderer = new PlayerRenderer( this, Window ); InitRenderingData();
Window.AsyncDownloader.DownloadSkin( SkinName ); Window.AsyncDownloader.DownloadSkin( SkinName );
} }
SetCurrentAnimState( t ); SetCurrentAnimState( t );
renderer.Render( deltaTime ); RenderModel( deltaTime );
} }
void HandleInput( ref float xMoving, ref float zMoving ) { void HandleInput( ref float xMoving, ref float zMoving ) {

View File

@ -11,7 +11,7 @@ namespace ClassicalSharp {
public NetPlayer( string displayName, string skinName, Game window ) : base( window ) { public NetPlayer( string displayName, string skinName, Game window ) : base( window ) {
DisplayName = displayName; DisplayName = displayName;
SkinName = Utils.StripColours( skinName ); SkinName = Utils.StripColours( skinName );
renderer = new PlayerRenderer( this, window ); InitRenderingData();
} }
// Last known position and orientation sent by the server. // Last known position and orientation sent by the server.
@ -42,10 +42,6 @@ namespace ClassicalSharp {
} }
} }
public override void Despawn() {
renderer.Dispose();
}
struct State { struct State {
public int tick; public int tick;
public Vector3 pos; public Vector3 pos;
@ -97,7 +93,7 @@ namespace ClassicalSharp {
PitchDegrees = Utils.InterpAngle( oldState.pitch, newState.pitch, t ); PitchDegrees = Utils.InterpAngle( oldState.pitch, newState.pitch, t );
SetCurrentAnimState( t ); SetCurrentAnimState( t );
renderer.Render( deltaTime ); RenderModel( deltaTime );
} }
} }
} }

View File

@ -0,0 +1,56 @@
using System;
using System.Drawing;
using ClassicalSharp.GraphicsAPI;
using OpenTK;
namespace ClassicalSharp {
partial class Player {
protected IGraphicsApi api;
protected Texture nameTex;
protected internal int PlayerTextureId = -1, MobTextureId = -1;
public override void Despawn() {
api.DeleteTexture( ref PlayerTextureId );
api.DeleteTexture( ref nameTex.ID );
}
protected void InitRenderingData() {
api = Window.Graphics;
using( Font font = new Font( "Arial", 14 ) ) {
DrawTextArgs args = new DrawTextArgs( api, DisplayName, true );
nameTex = Utils2D.MakeTextTexture( font, 0, 0, ref args );
}
}
protected void RenderModel( double deltaTime ) {
Model.RenderModel( this );
DrawName();
}
void DrawName() {
api.Texturing = true;
api.Bind2DTexture( nameTex.ID );
float x1 = -nameTex.Width * 0.5f / 50f, y1 = nameTex.Height / 50f;
float x2 = nameTex.Width * 0.5f / 50f, y2 = 0;
// NOTE: Do this instead with network player's yaw to have names rotate with them instead.
//yaw = Math.Pi - Player.YawRadians;
float angle = Window.LocalPlayer.YawRadians;
float cosA = (float)Math.Cos( angle ), sinA = (float)Math.Sin( angle );
Vector3 pos = Position;
pos.Y += Model.NameYOffset;
// Inlined translation + rotation Y axis
api.texVerts[0] = new VertexPos3fTex2f( cosA * x2 + pos.X, y1 + pos.Y, sinA * x2 + pos.Z, nameTex.U2, nameTex.V1 );
api.texVerts[1] = new VertexPos3fTex2f( cosA * x2 + pos.X, y2 + pos.Y, sinA * x2 + pos.Z, nameTex.U2, nameTex.V2 );
api.texVerts[2] = new VertexPos3fTex2f( cosA * x1 + pos.X, y1 + pos.Y, sinA * x1 + pos.Z, nameTex.U1, nameTex.V1 );
api.texVerts[3] = new VertexPos3fTex2f( cosA * x1 + pos.X, y2 + pos.Y, sinA * x1 + pos.Z, nameTex.U1, nameTex.V2 );
api.DrawDynamicVb( DrawMode.TriangleStrip, api.texVb, api.texVerts, VertexFormat.Pos3fTex2f, 4 );
api.Texturing = false;
api.AlphaTest = false;
}
}
}

View File

@ -7,7 +7,7 @@ using ClassicalSharp.Renderers;
namespace ClassicalSharp { namespace ClassicalSharp {
public abstract class Player : Entity { public abstract partial class Player : Entity {
public const float EyeHeight = 1.625f; public const float EyeHeight = 1.625f;
@ -19,7 +19,6 @@ namespace ClassicalSharp {
public Game Window; public Game Window;
public string DisplayName, SkinName; public string DisplayName, SkinName;
public SkinType SkinType; public SkinType SkinType;
protected PlayerRenderer renderer;
public Player( Game window ) : base( window ) { public Player( Game window ) : base( window ) {
Window = window; Window = window;
@ -93,22 +92,22 @@ namespace ClassicalSharp {
Window.AsyncDownloader.TryGetItem( "skin_" + SkinName, out item ); Window.AsyncDownloader.TryGetItem( "skin_" + SkinName, out item );
if( item != null && item.Bmp != null ) { if( item != null && item.Bmp != null ) {
Bitmap bmp = item.Bmp; Bitmap bmp = item.Bmp;
Window.Graphics.DeleteTexture( ref renderer.PlayerTextureId ); Window.Graphics.DeleteTexture( ref PlayerTextureId );
try { try {
SkinType = Utils.GetSkinType( bmp ); SkinType = Utils.GetSkinType( bmp );
renderer.PlayerTextureId = Window.Graphics.LoadTexture( bmp ); PlayerTextureId = Window.Graphics.LoadTexture( bmp );
renderer.MobTextureId = -1; MobTextureId = -1;
// Custom mob textures. // Custom mob textures.
if( Utils.IsUrl( item.Url ) && item.TimeAdded > lastModelChange ) { if( Utils.IsUrl( item.Url ) && item.TimeAdded > lastModelChange ) {
renderer.MobTextureId = renderer.PlayerTextureId; MobTextureId = PlayerTextureId;
} }
} catch( NotSupportedException ) { } catch( NotSupportedException ) {
string formatString = "Skin {0} has unsupported dimensions({1}, {2}), reverting to default."; string formatString = "Skin {0} has unsupported dimensions({1}, {2}), reverting to default.";
Utils.LogWarning( formatString, SkinName, bmp.Width, bmp.Height ); Utils.LogWarning( formatString, SkinName, bmp.Width, bmp.Height );
renderer.MobTextureId = -1; MobTextureId = -1;
renderer.PlayerTextureId = -1; PlayerTextureId = -1;
SkinType = Window.DefaultPlayerSkinType; SkinType = Window.DefaultPlayerSkinType;
} }
bmp.Dispose(); bmp.Dispose();
@ -121,9 +120,7 @@ namespace ClassicalSharp {
ModelName = modelName; ModelName = modelName;
Model = Window.ModelCache.GetModel( ModelName ); Model = Window.ModelCache.GetModel( ModelName );
lastModelChange = DateTime.UtcNow; lastModelChange = DateTime.UtcNow;
if( renderer != null ) { MobTextureId = -1;
renderer.MobTextureId = -1;
}
} }
} }
} }

View File

@ -184,8 +184,8 @@ namespace ClassicalSharp.GraphicsAPI {
DrawDynamicVb( DrawMode.TriangleStrip, quadVb, quadVertices, VertexFormat.Pos3fCol4b, 4 ); DrawDynamicVb( DrawMode.TriangleStrip, quadVb, quadVertices, VertexFormat.Pos3fCol4b, 4 );
} }
VertexPos3fTex2f[] texVertices = new VertexPos3fTex2f[4]; internal VertexPos3fTex2f[] texVerts = new VertexPos3fTex2f[4];
int texVb; internal int texVb;
public virtual void Draw2DTexture( ref Texture tex ) { public virtual void Draw2DTexture( ref Texture tex ) {
float x1 = tex.X1, y1 = tex.Y1, x2 = tex.X2, y2 = tex.Y2; float x1 = tex.X1, y1 = tex.Y1, x2 = tex.X2, y2 = tex.Y2;
#if USE_DX #if USE_DX
@ -197,11 +197,11 @@ namespace ClassicalSharp.GraphicsAPI {
y2 -= 0.5f; y2 -= 0.5f;
#endif #endif
// Have to order them this way because it's a triangle strip. // Have to order them this way because it's a triangle strip.
texVertices[0] = new VertexPos3fTex2f( x2, y1, 0, tex.U2, tex.V1 ); texVerts[0] = new VertexPos3fTex2f( x2, y1, 0, tex.U2, tex.V1 );
texVertices[1] = new VertexPos3fTex2f( x2, y2, 0, tex.U2, tex.V2 ); texVerts[1] = new VertexPos3fTex2f( x2, y2, 0, tex.U2, tex.V2 );
texVertices[2] = new VertexPos3fTex2f( x1, y1, 0, tex.U1, tex.V1 ); texVerts[2] = new VertexPos3fTex2f( x1, y1, 0, tex.U1, tex.V1 );
texVertices[3] = new VertexPos3fTex2f( x1, y2, 0, tex.U1, tex.V2 ); texVerts[3] = new VertexPos3fTex2f( x1, y2, 0, tex.U1, tex.V2 );
DrawDynamicVb( DrawMode.TriangleStrip, texVb, texVertices, VertexFormat.Pos3fTex2f, 4 ); DrawDynamicVb( DrawMode.TriangleStrip, texVb, texVerts, VertexFormat.Pos3fTex2f, 4 );
} }
public void Mode2D( float width, float height ) { public void Mode2D( float width, float height ) {

View File

@ -1,4 +1,5 @@
using System; #if !USE_DX
using System;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
@ -422,3 +423,4 @@ namespace ClassicalSharp.GraphicsAPI {
} }
} }
} }
#endif

View File

@ -26,7 +26,7 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -0.5f, 0f, -0.5f, 0.5f, blockHeight, 0.5f ); } get { return new BoundingBox( -0.5f, 0f, -0.5f, 0.5f, blockHeight, 0.5f ); }
} }
protected override void DrawPlayerModel( Player player, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player player ) {
graphics.Texturing = true; graphics.Texturing = true;
graphics.AlphaTest = true; graphics.AlphaTest = true;
block = Byte.Parse( player.ModelName ); block = Byte.Parse( player.ModelName );

View File

@ -62,9 +62,9 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -4 / 16f, 0, -8 / 16f, 4 / 16f, 15 / 16f, 4 / 16f ); } get { return new BoundingBox( -4 / 16f, 0, -8 / 16f, 4 / 16f, 15 / 16f, 4 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
graphics.AlphaTest = true; graphics.AlphaTest = true;

View File

@ -45,9 +45,9 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -4 / 16f, 0, -6 / 16f, 4 / 16f, 26 / 16f, 6 / 16f ); } get { return new BoundingBox( -4 / 16f, 0, -6 / 16f, 4 / 16f, 26 / 16f, 6 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
DrawRotate( 0, 1.125f, 0, -p.PitchRadians, 0, 0, Head ); DrawRotate( 0, 1.125f, 0, -p.PitchRadians, 0, 0, Head );

View File

@ -23,15 +23,15 @@ namespace ClassicalSharp.Model {
public abstract BoundingBox PickingBounds { get; } public abstract BoundingBox PickingBounds { get; }
public void RenderModel( Player p, PlayerRenderer renderer ) { public void RenderModel( Player p ) {
graphics.PushMatrix(); graphics.PushMatrix();
Matrix4 mat = Matrix4.RotateY( -p.YawRadians ) * Matrix4.Translate( p.Position ); Matrix4 mat = Matrix4.RotateY( -p.YawRadians ) * Matrix4.Translate( p.Position );
graphics.MultiplyMatrix( ref mat ); graphics.MultiplyMatrix( ref mat );
DrawPlayerModel( p, renderer ); DrawPlayerModel( p );
graphics.PopMatrix(); graphics.PopMatrix();
} }
protected abstract void DrawPlayerModel( Player p, PlayerRenderer renderer ); protected abstract void DrawPlayerModel( Player p );
public abstract void Dispose(); public abstract void Dispose();

View File

@ -45,9 +45,9 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -5 / 16f, 0, -14 / 16f, 5 / 16f, 16 / 16f, 9 / 16f ); } get { return new BoundingBox( -5 / 16f, 0, -14 / 16f, 5 / 16f, 16 / 16f, 9 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
DrawRotate( 0, 0.75f, -0.375f, -p.PitchRadians, 0, 0, Head ); DrawRotate( 0, 0.75f, -0.375f, -p.PitchRadians, 0, 0, Head );

View File

@ -88,9 +88,9 @@ namespace ClassicalSharp.Model {
} }
ModelSet model; ModelSet model;
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.PlayerTextureId <= 0 ? DefaultTexId : renderer.PlayerTextureId; int texId = p.PlayerTextureId <= 0 ? DefaultTexId : p.PlayerTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
SkinType skinType = p.SkinType; SkinType skinType = p.SkinType;
model = Set64x32; model = Set64x32;

View File

@ -69,9 +69,9 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -6 / 16f, 0, -13 / 16f, 6 / 16f, 23 / 16f, 10 / 16f ); } get { return new BoundingBox( -6 / 16f, 0, -13 / 16f, 6 / 16f, 23 / 16f, 10 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
DrawRotate( 0, 1.125f, -0.5f, -p.PitchRadians, 0, 0, Head ); DrawRotate( 0, 1.125f, -0.5f, -p.PitchRadians, 0, 0, Head );

View File

@ -57,10 +57,10 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -4 / 16f, 0, -4 / 16f, 4 / 16f, 32 / 16f, 4 / 16f ); } get { return new BoundingBox( -4 / 16f, 0, -4 / 16f, 4 / 16f, 32 / 16f, 4 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
graphics.AlphaTest = true; graphics.AlphaTest = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head ); DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head );

View File

@ -50,9 +50,9 @@ namespace ClassicalSharp.Model {
const float quarterPi = (float)( Math.PI / 4 ); const float quarterPi = (float)( Math.PI / 4 );
const float eighthPi = (float)( Math.PI / 8 ); const float eighthPi = (float)( Math.PI / 8 );
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
graphics.AlphaTest = true; graphics.AlphaTest = true;

View File

@ -57,9 +57,9 @@ namespace ClassicalSharp.Model {
get { return new BoundingBox( -4 / 16f, 0, -4 / 16f, 4 / 16f, 32 / 16f, 4 / 16f ); } get { return new BoundingBox( -4 / 16f, 0, -4 / 16f, 4 / 16f, 32 / 16f, 4 / 16f ); }
} }
protected override void DrawPlayerModel( Player p, PlayerRenderer renderer ) { protected override void DrawPlayerModel( Player p ) {
graphics.Texturing = true; graphics.Texturing = true;
int texId = renderer.MobTextureId <= 0 ? DefaultTexId : renderer.MobTextureId; int texId = p.MobTextureId <= 0 ? DefaultTexId : p.MobTextureId;
graphics.Bind2DTexture( texId ); graphics.Bind2DTexture( texId );
DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head ); DrawRotate( 0, 1.5f, 0, -p.PitchRadians, 0, 0, Head );

View File

@ -215,10 +215,6 @@ namespace OpenTK.Graphics.OpenGL {
public delegate void TexImage2D(TextureTarget target, Int32 level, PixelInternalFormat publicformat, Int32 width, Int32 height, Int32 border, PixelFormat format, PixelType type, IntPtr pixels); public delegate void TexImage2D(TextureTarget target, Int32 level, PixelInternalFormat publicformat, Int32 width, Int32 height, Int32 border, PixelFormat format, PixelType type, IntPtr pixels);
public static TexImage2D glTexImage2D; public static TexImage2D glTexImage2D;
[SuppressUnmanagedCodeSecurity()]
public delegate void TexParameterf(TextureTarget target, TextureParameterName pname, Single param);
public static TexParameterf glTexParameterf;
[SuppressUnmanagedCodeSecurity()] [SuppressUnmanagedCodeSecurity()]
public delegate void TexParameteri(TextureTarget target, TextureParameterName pname, Int32 param); public delegate void TexParameteri(TextureTarget target, TextureParameterName pname, Int32 param);
public static TexParameteri glTexParameteri; public static TexParameteri glTexParameteri;

View File

@ -84,7 +84,6 @@ namespace OpenTK.Graphics.OpenGL
//LoadDelegate( "glShadeModel", out Delegates.glShadeModel ); //LoadDelegate( "glShadeModel", out Delegates.glShadeModel );
LoadDelegate( "glTexCoordPointer", out Delegates.glTexCoordPointer ); LoadDelegate( "glTexCoordPointer", out Delegates.glTexCoordPointer );
LoadDelegate( "glTexImage2D", out Delegates.glTexImage2D ); LoadDelegate( "glTexImage2D", out Delegates.glTexImage2D );
//LoadDelegate( "glTexParameterf", out Delegates.glTexParameterf );
LoadDelegate( "glTexParameteri", out Delegates.glTexParameteri ); LoadDelegate( "glTexParameteri", out Delegates.glTexParameteri );
LoadDelegate( "glTexSubImage2D", out Delegates.glTexSubImage2D ); LoadDelegate( "glTexSubImage2D", out Delegates.glTexSubImage2D );
LoadDelegate( "glVertexPointer", out Delegates.glVertexPointer ); LoadDelegate( "glVertexPointer", out Delegates.glVertexPointer );

View File

@ -4,8 +4,6 @@ using System.Security;
namespace OpenTK.Platform.Windows { namespace OpenTK.Platform.Windows {
#pragma warning disable 0649
internal partial class Wgl : BindingsBase { internal partial class Wgl : BindingsBase {
const string Library = "OPENGL32.DLL"; const string Library = "OPENGL32.DLL";
@ -25,29 +23,35 @@ namespace OpenTK.Platform.Windows {
} }
} }
[SuppressUnmanagedCodeSecurity()] [SuppressUnmanagedCodeSecurity]
internal delegate Boolean SwapIntervalEXT(int interval); internal delegate Boolean SwapIntervalEXT(int interval);
internal static SwapIntervalEXT wglSwapIntervalEXT; internal static SwapIntervalEXT wglSwapIntervalEXT;
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
internal delegate int GetSwapIntervalEXT(); internal delegate int GetSwapIntervalEXT();
internal static GetSwapIntervalEXT wglGetSwapIntervalEXT; internal static GetSwapIntervalEXT wglGetSwapIntervalEXT;
[SuppressUnmanagedCodeSecurity()] [SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static IntPtr wglCreateContext(IntPtr hDc); internal extern static IntPtr wglCreateContext(IntPtr hDc);
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static Boolean wglDeleteContext(IntPtr oldContext); internal extern static Boolean wglDeleteContext(IntPtr oldContext);
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static IntPtr wglGetCurrentContext(); internal extern static IntPtr wglGetCurrentContext();
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static Boolean wglMakeCurrent(IntPtr hDc, IntPtr newContext); internal extern static Boolean wglMakeCurrent(IntPtr hDc, IntPtr newContext);
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static IntPtr wglGetCurrentDC(); internal extern static IntPtr wglGetCurrentDC();
[SuppressUnmanagedCodeSecurity()]
[SuppressUnmanagedCodeSecurity]
[DllImport(Library, SetLastError = true)] [DllImport(Library, SetLastError = true)]
internal extern static IntPtr wglGetProcAddress(String lpszProc); internal extern static IntPtr wglGetProcAddress(String lpszProc);
} }

View File

@ -1,64 +0,0 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using ClassicalSharp.GraphicsAPI;
using OpenTK;
namespace ClassicalSharp.Renderers {
public class PlayerRenderer {
public Game Window;
public IGraphicsApi Graphics;
public Player Player;
Texture nameTexture;
float nameWidth, nameHeight;
public int PlayerTextureId = -1, MobTextureId = -1;
int nameTextureId = -1;
public PlayerRenderer( Player player, Game window ) {
Player = player;
Window = window;
Graphics = window.Graphics;
using( Font font = new Font( "Arial", 14 ) ) {
DrawTextArgs args = new DrawTextArgs( Graphics, player.DisplayName, true );
nameTexture = Utils2D.MakeTextTexture( font, 0, 0, ref args );
nameWidth = nameTexture.Width;
nameHeight = nameTexture.Height;
nameTextureId = nameTexture.ID;
}
}
public void Dispose() {
Graphics.DeleteTexture( ref PlayerTextureId );
Graphics.DeleteTexture( ref nameTextureId );
}
public void Render( double deltaTime ) {
Player.Model.RenderModel( Player, this );
DrawName();
}
const float nameScale = 1 / 50f;
private void DrawName() {
Vector3 pos = Player.Position;
Graphics.PushMatrix();
Matrix4 mat = Matrix4.Translate( pos.X, pos.Y + Player.Model.NameYOffset, pos.Z );
// Do this to always have names facing the player
float yaw = Window.LocalPlayer.YawRadians;
mat = Matrix4.RotateY( 0f - yaw ) * mat;
// NOTE: Do this instead with network player's yaw to have names rotate with them instead.
//Graphics.RotateY( 180f - yaw );
mat = Matrix4.Scale( nameScale, -nameScale, nameScale ) * mat; // -y to flip text
mat = Matrix4.Translate( -nameWidth / 2f, -nameHeight, 0f ) * mat;
Graphics.MultiplyMatrix( ref mat );
Graphics.Texturing = true;
nameTexture.Render( Graphics );
Graphics.PopMatrix();
Graphics.Texturing = false;
Graphics.AlphaTest = false;
}
}
}

View File

@ -0,0 +1,40 @@
using System;
namespace ClassicalSharp.Renderers {
/// <summary> Minimialistic environment renderer - only sets the clear colour to be sky colour.
/// (no fog, clouds, or proper overhead sky) </summary>
public class MinimalEnvRenderer : EnvRenderer {
public MinimalEnvRenderer( Game window ) {
Window = window;
Map = Window.Map;
}
public override void Render( double deltaTime ) {
Graphics.ClearColour( Map.SkyCol );
}
public override void Init() {
base.Init();
Graphics.Fog = false;
Graphics.ClearColour( Map.SkyCol );
}
public override void OnNewMap( object sender, EventArgs e ) {
}
public override void OnNewMapLoaded( object sender, EventArgs e ) {
Graphics.ClearColour( Map.SkyCol );
}
protected override void CloudsColourChanged() {
}
protected override void FogColourChanged() {
}
protected override void SkyColourChanged() {
}
}
}