public Graphics(Audio audio) { // Save a pointer to the audio class, for convenience this.Audio = audio; // Load Shader Programs. ShaderProgram uvShader = new ShaderProgram(VertexShader.FromFile("data/shaders/uvcolor_vs.glsl"), FragmentShader.FromFile("data/shaders/uvcolor_fs.glsl")); ShaderProgram objShader = new ShaderProgram(VertexShader.FromFile("data/shaders/obj_vs.glsl"), FragmentShader.FromFile("data/shaders/obj_fs.glsl")); ShaderProgram objShaderHax = new ShaderProgram(VertexShader.FromFile("data/shaders/obj_vs_hax.glsl"), FragmentShader.FromFile("data/shaders/obj_fs.glsl")); this.wallShader = objShader; // Create matrix uniforms used for rendering. this.view2D = new Matrix4Uniform("viewMatrix"); this.projection2D = new Matrix4Uniform("projectionMatrix"); this.view3D = new Matrix4Uniform("viewMatrix"); this.projection3D = new Matrix4Uniform("projectionMatrix"); this.createColorMatrices(); this.WallColorUniform = new Matrix4Uniform("mixColor", this.Blue); this.lightDirection = new Vector3(-1f, -0.5f, -0.4f); this.lightDirection.Normalize(); // Create the surfaces #region Font Surface Texture t = new Texture("data/fonts/freshman.png"); this.FontSurface = new IndexedSurface <UVColorVertexData>(); this.FontSurface.AddSettings( this.view2D, this.projection2D, new TextureUniform("diffuseTexture", t), SurfaceBlendSetting.Alpha, SurfaceDepthMaskSetting.DontMask ); this.FontSurface.SetShaderProgram(uvShader); // the following line loads the json file this.FontGeometry = new FontGeometry(this.FontSurface, amulware.Graphics.Font.FromJsonFile("data/fonts/freshman_monospaced_numbers.json")); // this.FontGeometry.SizeCoefficient = new Vector2(1, -1); // FLIP IT this.MenuFontGeometry = this.FontGeometry; #endregion #region 3D font Surface t = new Texture("data/fonts/freshman.png"); this.FontSurface3D = new IndexedSurface <UVColorVertexData>(); this.FontSurface3D.AddSettings( this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), SurfaceBlendSetting.Alpha, SurfaceDepthMaskSetting.DontMask ); this.FontSurface3D.SetShaderProgram(uvShader); // the following line loads the json file this.FontGeometry3D = new FontGeometry(this.FontSurface3D, amulware.Graphics.Font.FromJsonFile("data/fonts/freshman_monospaced_numbers.json")); this.FontGeometry3D.SizeCoefficient = new Vector2(1, -1); // FLIP IT #endregion #region PacmanSurface MeshData m = new MeshData("data/models/Pacman.obj"); t = new Texture("data/sprites/PacmanTexture.png"); this.pacManModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.PacmanSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.PacmanSurface.AddSettings( this.pacManModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), new Matrix4Uniform("mixColor", Matrix4.Identity) ); this.PacmanSurface.SetShaderProgram(objShader); #endregion #region PacmanMouthSurface (must be placed directly after the 'PacmanSurface') m = new MeshData("data/models/Pacman_mouth.obj"); this.PacManMouthTopTexture = new Texture("data/sprites/OrbTexture.png"); // 't' is the same texture as pacman, 't-top' is a plain white pixel (as used for the orbs). this.PacManMouthBottomTexture = t; this.PacManMouthTextureUniform = new TextureUniform("diffuseTexture", t); this.PacManMouthColorUniform = new Matrix4Uniform("mixColor", Matrix4.Identity); this.PacmanMouthSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.PacmanMouthSurface.AddSettings( this.pacManModel, this.view3D, this.projection3D, this.PacManMouthTextureUniform, new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), this.PacManMouthColorUniform ); this.PacmanMouthSurface.SetShaderProgram(objShaderHax); #endregion #region GhostSurface m = new MeshData("data/models/Ghost.obj"); t = new Texture("data/sprites/GhostTexture.png"); this.GhostColorUniform = new Matrix4Uniform("mixColor", this.Red); this.ghostModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.GhostSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.GhostSurface.AddSettings( this.ghostModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), this.GhostColorUniform ); this.GhostSurface.SetShaderProgram(objShader); #endregion #region OrbSurface m = new MeshData("data/models/Orb.obj"); t = new Texture("data/sprites/OrbTexture.png"); this.orbModel = new Matrix4Uniform("modelMatrix", Matrix4.Identity); this.OrbSurface = m.ToIndexedSurface <NormalUVColorVertexData>(NormalUVColorVertexData.FromMesh); this.OrbSurface.AddSettings( this.orbModel, this.view3D, this.projection3D, new TextureUniform("diffuseTexture", t), new Vector3Uniform("lightDirection", this.lightDirection), new FloatUniform("ambientIntensity", 0.3f), new FloatUniform("diffuseIntensity", 0.8f), new Matrix4Uniform("mixColor", Matrix4.Identity) ); this.OrbSurface.SetShaderProgram(objShader); #endregion }
public GraphicsManager() { // Load Shader Programs. ShaderProgram simpleShader = new ShaderProgram(VertexShader.FromFile("data/shaders/simple_vs.glsl"), FragmentShader.FromFile("data/shaders/simple_fs.glsl")); ShaderProgram uvShader = new ShaderProgram(VertexShader.FromFile("data/shaders/uvcolor_vs.glsl"), FragmentShader.FromFile("data/shaders/uvcolor_fs.glsl")); // Create matrix uniforms used for rendering. this.modelview = new Matrix4Uniform("modelviewMatrix"); this.projection = new Matrix4Uniform("projectionMatrix"); this.hudMatrix = new Matrix4Uniform("modelviewMatrix"); // Font Font quartz = Font.FromJsonFile("data/fonts/Quartz.json"); // Create the surfaces #region Background surface Texture t = new Texture("data/graphics/omega-nebula.jpg"); this.BackgroundSurface = new IndexedSurface <UVColorVertexData>(); this.BackgroundSurface.AddSettings( this.hudMatrix, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.BackgroundSurface.SetShaderProgram(uvShader); this.BackgroundGeometry = new Sprite2DGeometry(this.BackgroundSurface); this.BackgroundGeometry.Size = new Vector2(1280, -720); this.BackgroundGeometry.Color.A = (byte)100; #endregion #region Planet Surface t = new Texture("data/graphics/planet.png"); this.PlanetSurface = new IndexedSurface <UVColorVertexData>(); this.PlanetSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.PlanetSurface.SetShaderProgram(uvShader); this.PlanetGeometry = new Sprite2DGeometry(this.PlanetSurface); this.PlanetGeometry.Size = new Vector2(2, 2); #endregion #region Asteroid Surface t = new Texture("data/graphics/asteroid.png"); this.AsteroidSurface = new IndexedSurface <UVColorVertexData>(); this.AsteroidSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.AsteroidSurface.SetShaderProgram(uvShader); this.AsteroidGeometry = new Sprite2DGeometry(this.AsteroidSurface); this.AsteroidGeometry.Size = new Vector2(2, 2); #endregion #region Space Core Surface t = new Texture("data/graphics/spacecore.png"); this.SpaceCoreSurface = new IndexedSurface <UVColorVertexData>(); this.SpaceCoreSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.SpaceCoreSurface.SetShaderProgram(uvShader); this.SpaceCoreGeometry = new Sprite2DGeometry(this.SpaceCoreSurface); this.SpaceCoreGeometry.Size = new Vector2(30, 30); #endregion #region Jumper Surface t = new Texture("data/graphics/jumper.png"); this.JumperSurface = new IndexedSurface <UVColorVertexData>(); this.JumperSurface.AddSettings( this.modelview, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.JumperSurface.SetShaderProgram(uvShader); this.JumperGeometry = new Sprite2DGeometry(this.JumperSurface); this.JumperGeometry.Size = Jumper.Size; #endregion #region Trail Surface this.TrailSurface = new IndexedSurface <PrimitiveVertexData>(); this.TrailSurface.AddSettings( this.modelview, this.projection, SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.TrailSurface.SetShaderProgram(simpleShader); this.TrailGeometry = new PrimitiveGeometry(this.TrailSurface); this.TrailGeometry.Color = Color.Cyan; #endregion #region Score Surface t = new Texture("data/fonts/Quartz.png"); this.ScoreSurface = new IndexedSurface <UVColorVertexData>(); this.ScoreSurface.AddSettings( this.hudMatrix, this.projection, new TextureUniform("diffusetexture", t), SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.ScoreSurface.SetShaderProgram(uvShader); this.ScoreGeometry = new FontGeometry(this.ScoreSurface, quartz); this.ScoreGeometry.Height = 32; this.ScoreGeometry.SizeCoefficient = new Vector2(1, -1); #endregion #region Overlay surface this.OverlaySurface = new IndexedSurface <PrimitiveVertexData>(); this.OverlaySurface.AddSettings( this.hudMatrix, this.projection, SurfaceDepthMaskSetting.DontMask, SurfaceBlendSetting.Alpha ); this.OverlaySurface.SetShaderProgram(simpleShader); this.OverlayGeometry = new PrimitiveGeometry(this.OverlaySurface); this.OverlayGeometry.Color = Color.Cyan; this.OverlayGeometry.Color.A = (byte)150; #endregion }