void CreateVBO(bool origCenter) { if (Vbo != null) { Vbo.Dispose(); } ushort[] ind = new ushort[] { 0, 1, 3, 1, 2, 3 }; int w, h, nw = 0, nh = 0; if (origCenter) { w = RealWidth / 2; h = RealHeight / 2; nw = -w; nh = -h; } else { w = RealWidth; h = RealHeight; } Vertex[] vert = { new Vertex(new Vector3(nw, nh, 0), new Vector3(0, 0, 1), new Vector2(0, 0)), new Vertex(new Vector3(nw, h, 0), new Vector3(0, 0, 1), new Vector2(0, 1)), new Vertex(new Vector3(w, h, 0), new Vector3(0, 0, 1), new Vector2(1, 1)), new Vertex(new Vector3(w, nh, 0), new Vector3(0, 0, 1), new Vector2(1, 0)) }; Vbo = new VBO(); Vbo.DataToVBO(vert, ind, VBO.VertexMode.UV1); Vbo.Shader = GLSLShader.Load("default2d.shader"); }
public override void Init() { depthFBO = new FBO(0, 0, 1, true); ShadowMapping.Create(depthFBO, "lightmask.png"); font = BitmapFont.Load("fonts/comic12.png"); skybox = Sky.Load("sky/sky_", "jpg"); world.Add(skybox); GLSLShader.SetShader("shadowmapping.shader", "SHADOWS"); DotScene ds = DotScene.Load("scene1/scene1.scene", scene); world.Add(scene); actors[0] = AnimatedModel.Load("ugly/ukko.mesh"); actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim"); actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim"); actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim"); actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim"); actors[0].SetAnimation("act2"); // idle anim actors[0].Scale = new Vector3(5, 5, 5); world.Add(actors[0]); lightImg = Billboard.Load("lightimg.png"); Camera.Set3D(); base.Init(); }
public static PostEffect Load(string shaderFileName, string flags) { PostEffect eff = new PostEffect(); eff.effect = GLSLShader.Load(shaderFileName + (flags == "" ? "" : ":" + flags)); return(eff); }
public static void Create(FBO fbo, string lightMaskFileName) { if (Settings.DisableShadowMapping) { UseShadowMapping = false; return; } if (FBO.IsSupported == false) { Log.WriteLine("FBOs not supported so no shadow mapping."); UseShadowMapping = false; return; } ShadowMapping.fbo = fbo; UseShadowMapping = true; TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge; TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge; try { lightMask = Texture.Load(lightMaskFileName); } catch (Exception) { } // skipataan valitukset jos tiedostoa ei löydy TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat; TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat; depthShader = GLSLShader.Load("depth.shader"); depthShaderAlphaTest = GLSLShader.Load("depth.shader:ALPHATEST"); }
public virtual void Dispose() { if (font != null) { font.Dispose(); } if (colorFBO != null) { colorFBO.Dispose(); } if (depthFBO != null) { depthFBO.Dispose(); } if (skybox != null) { skybox.Dispose(); } skybox = null; colorFBO = null; depthFBO = null; font = null; world = null; Node.ObjectCount = 0; GLSLShader.UnBindShader(); GLSLShader.SetShader("default.shader", ""); }
public void Dispose() { if (vertexID != -1) { GL.DeleteBuffers(1, ref vertexID); } if (indexID != -1) { GL.DeleteBuffers(1, ref indexID); } if (vaoID != -1) { GL.DeleteVertexArrays(1, ref vaoID); } if (Shader != null) { Shader.Dispose(); } vertexID = indexID = vaoID = -1; Shader = null; if (numOfIndices > 0) { Log.WriteLine("Disposed: VBO", false); } numOfIndices = 0; }
void LoadMesh(string name, string fileName) { Name = name; XmlDocument XMLDoc = null; XmlElement XMLRoot; try { using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName)) { // tiedosto muistiin string data = file.ReadToEnd(); XMLDoc = new XmlDocument(); XMLDoc.LoadXml(data); } } catch (Exception e) { Log.Error(e.ToString()); } // Validate the File XMLRoot = XMLDoc.DocumentElement; if (XMLRoot.Name != "mesh") { Log.Error("Error [" + fileName + "] Invalid .mesh.xml File. Missing <mesh>"); } bool isPath = false; // jos meshi on pathi if (name.StartsWith("Path_")) { isPath = true; } // Process the mesh processMesh(XMLRoot, isPath); if (isPath == false) { Vbo = new VBO(); Vbo.DataToVBO(VertexBuffer, IndexBuffer, VBO.VertexMode.UV1); Boundings = new BoundingSphere(); Boundings.CreateBoundingVolume(this); // lataa shader string shader = Material.ShaderName; if (shader != "") { Vbo.Shader = GLSLShader.Load(shader); } } else { Path path = new Path(); path.AddPath(name, VertexBuffer); } }
public void UseProgram() { if (CurrentShader != this) { CurrentShader = this; GL.UseProgram(ProgramID); } }
public void SetSkyShader(string shaderFileName) { GetList(true); for (int q = 0; q < ObjList.Count; q++) { OgreMesh m = ObjList[q] as OgreMesh; m.Vbo.Shader = GLSLShader.Load(shaderFileName); } }
/// <summary> /// lataa glsl shader (vertex ja fragment shader samassa tiedostossa). /// asettaaa ladatun shaderin käyttöön. /// </summary> public static GLSLShader Load(string fileName) { if (fileName == "" || fileName == ":") return null; GLSLShader shader = new GLSLShader(); shader.LoadShader(fileName); return shader; }
public void Dispose() { if (vertexID != -1) GL.DeleteBuffers(1, ref vertexID); if (indexID != -1) GL.DeleteBuffers(1, ref indexID); if (vaoID != -1) GL.DeleteVertexArrays(1, ref vaoID); if (Shader != null) Shader.Dispose(); vertexID = indexID = vaoID = -1; Shader = null; if (numOfIndices > 0) Log.WriteLine("Disposed: VBO", false); numOfIndices = 0; }
/// <summary> /// lataa glsl shader (vertex ja fragment shader samassa tiedostossa). /// asettaaa ladatun shaderin käyttöön. /// </summary> public static GLSLShader Load(string fileName) { if (fileName == "" || fileName == ":") { return(null); } GLSLShader shader = new GLSLShader(); shader.LoadShader(fileName); return(shader); }
public static Billboard Load(string fileName, bool softParticle) { if (Particles.SoftParticles == false) { softParticle = false; } Billboard bb = new Billboard(); bb.billBoard = Texture2D.Load(fileName, true); bb.billBoard.Vbo.Shader = GLSLShader.Load("particles.shader" + (softParticle ? ":SOFT" : "")); return(bb); }
public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode) { if (numOfIndices > 0) { Dispose(); } int size; vertexFlags = mode; numOfIndices = indices.Length; Vertex.Size = BlittableValueType.StrideOf(vertices); GL.GenBuffers(1, out vertexID); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage); GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size); if (vertices.Length * BlittableValueType.StrideOf(vertices) != size) { Log.Error("DataToVBO: Vertex data not uploaded correctly"); } GL.GenBuffers(1, out indexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage); GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size); if (indices.Length * sizeof(short) != size) { throw new ApplicationException("DataToVBO: Element data not uploaded correctly"); } Shader = GLSLShader.Load(); if (Shader != null) { if (Settings.UseGL3) { GL.GenVertexArrays(1, out vaoID); GL.BindVertexArray(vaoID); } GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); Shader.SetAttributes(); if (Settings.UseGL3) { GL.BindVertexArray(0); } } GLExt.CheckGLError("DataToVBO"); }
/// <summary> /// renderoi worldin valosta päin (pelkän depthin) /// </summary> public static void SetupShadows(Renderable world, int lightNo, bool withParticles) { if (UseShadowMapping == false) { return; } if (Light.Lights.Count == 0) { Log.WriteLine("SetupShadows requires at least one light source!", false); return; } GL.Disable(EnableCap.Blend); GL.ColorMask(false, false, false, false); GL.Disable(EnableCap.CullFace); GL.PolygonOffset(1, 1); GL.Enable(EnableCap.PolygonOffsetFill); fbo.BindDepth(); fbo.BindFBO(); fbo.Clear(); // kuvakulma valosta päin GLExt.LoadMatrix(ref Light.Lights[lightNo].OrigOrientationMatrix); GLExt.Translate(-Light.Lights[lightNo].Position.X, -Light.Lights[lightNo].Position.Y, -Light.Lights[lightNo].Position.Z); SetTextureMatrix(); Frustum.CalculateFrustum(); VBO.FastRenderPass = true; depthShader.UseProgram(); world.Render(); if (withParticles) { depthShaderAlphaTest.UseProgram(); Particles.Render(); GLSLShader.UnBindShader(); } VBO.FastRenderPass = false; fbo.UnBindFBO(); GL.Disable(EnableCap.PolygonOffsetFill); GL.Enable(EnableCap.CullFace); GL.ColorMask(true, true, true, true); GLExt.LoadIdentity(); GameClass.NumOfObjects = 0; ShadowMapping.UnBindLightMask(); }
public override void Dispose() { if (particleTex != null) { particleTex.Dispose(); } if (depthShader != null) { depthShader.Dispose(); } particleTex = null; depthShader = null; particles.Clear(); Log.WriteLine("Disposed: Particles", false); }
public static void EnableSoftParticles() { if (Settings.DisableSoftParticles) { softParticles = false; return; } if (Texture.IsFloatTextureSupported == false) { Log.WriteLine("Float textures not supported so no soft particles."); softParticles = false; return; } depthShader = GLSLShader.Load("depth.shader:DEPTH_W"); softParticles = true; }
/// <summary> /// renderoi vbo /// </summary> public void Render() { GL.ActiveTexture(TextureUnit.Texture0); if (VBO.FastRenderPass == false) { if (Shader != null) { Shader.UseProgram(); } } if (Settings.UseGL3 == true) { GL.BindVertexArray(vaoID); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); if (GLSLShader.CurrentShader != null) { GLSLShader.CurrentShader.SetUniforms(); GLSLShader.CurrentShader.SetAttributes(); } GL.DrawElements(BeginMode.Triangles, numOfIndices, DrawElementsType.UnsignedShort, IntPtr.Zero); GL.BindVertexArray(0); return; } else { // gl2 GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); if (GLSLShader.CurrentShader != null) { GLSLShader.CurrentShader.SetUniforms(); GLSLShader.CurrentShader.SetAttributes(); } else { GLSLShader.UnBindShader(); } GL.DrawElements(BeginMode.Triangles, numOfIndices, DrawElementsType.UnsignedShort, IntPtr.Zero); } }
// debug public void RenderSkeleton() { if (Settings.UseGL3 == false) { GLSLShader.UnBindShader(); GL.Disable(EnableCap.Texture2D); GL.Disable(EnableCap.DepthTest); GLExt.PushMatrix(); { GL.Translate(Position.X, Position.Y, Position.Z); GL.Rotate(Rotation.X, 1, 0, 0); GL.Rotate(Rotation.Y, 0, 1, 0); GL.Rotate(Rotation.Z, 0, 0, 1); GL.Rotate(-90, 1, 0, 0); GL.Scale(Scale.X, Scale.Y, Scale.Z); GL.PointSize(5); GLExt.Color4(1, 0, 0, 1); GL.Begin(BeginMode.Points); for (int q = 0; q < numJoints; q++) { GL.Vertex3(skeleton[q].pos); } GL.End(); GL.PointSize(1); GLExt.Color4(0, 1, 0, 1); GL.Begin(BeginMode.Lines); for (int q = 0; q < numJoints; q++) { if (skeleton[q].parent != -1) { GL.Vertex3(skeleton[skeleton[q].parent].pos); GL.Vertex3(skeleton[q].pos); } } GL.End(); } GLExt.PopMatrix(); GL.Enable(EnableCap.DepthTest); GL.Enable(EnableCap.Texture2D); GLExt.Color4(1, 1, 1, 1); } }
public override void Init() { colorFBO = new FBO(0, 0, 2, true); // 2 colorbufferia depthFBO = new FBO(0, 0, 0, true); blurH = PostEffect.Load("blur.shader", "HORIZ"); blurH.SetParameter("size", 1f / (float)colorFBO.Width); blurV = PostEffect.Load("blur.shader", "VERT"); blurV.SetParameter("size", 1f / (float)colorFBO.Width); bloom = PostEffect.Load("bloom.shader", ""); bloom.SetParameter("size", 0.001f); Particles.EnableSoftParticles(); ShadowMapping.Create(depthFBO, "lightmask.png"); font = BitmapFont.Load("fonts/comic12.png"); skybox = Sky.Load("sky/sky2_", "jpg"); world.Add(skybox); lightImg = Billboard.Load("lightimg.png"); GLSLShader.SetShader("shadowmapping.shader", "SHADOWS"); DotScene ds = DotScene.Load("scene1/scene1.scene", scene); world.Add(scene); actors[0] = AnimatedModel.Load("ugly/ukko.mesh"); actors[0].LoadMD5Animation("act1", "ugly/ukko_action1.anim"); actors[0].LoadMD5Animation("act2", "ugly/ukko_action2.anim"); actors[0].LoadMD5Animation("act3", "ugly/ukko_action3.anim"); actors[0].LoadMD5Animation("walk", "ugly/ukko_walk.anim"); actors[0].SetAnimation("act2"); // idle anim actors[0].Position.Y = -0.5f; actors[0].Scale = new Vector3(5, 5, 5); world.Add(actors[0]); explosion = Particles.Load("explosion.particles.xml", new ParticleCallback(RenderParticleCallback)); smoke = Particles.Load("smoke.particles.xml", null); actors[0].Add(smoke); Camera.Set3D(); base.Init(); }
public static BitmapFont Load(string fileName) { BitmapFont font = new BitmapFont(); try { // lataa fonttitexture font.texture = Texture.Load(fileName); Bitmap CurrentBitmap = new Bitmap(Settings.TextureDir + fileName); if (CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb || CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb) { BitmapData Data = CurrentBitmap.LockBits(new Rectangle(0, 0, CurrentBitmap.Width, CurrentBitmap.Height), ImageLockMode.ReadOnly, CurrentBitmap.PixelFormat); font.SearchUV(ref Data, (CurrentBitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb) ? 3 : 4); CurrentBitmap.UnlockBits(Data); } else { Log.Error("Font: wrong pixel format."); } } catch (Exception e) { Log.Error("Font: error loading file " + fileName + "\n" + e.ToString()); } if (vbo == null) { ushort[] ind = new ushort[] { 0, 1, 3, 1, 2, 3 }; vbo = new VBO(BufferUsageHint.StreamDraw); vbo.DataToVBO(letter, ind, VBO.VertexMode.UV1); vbo.Shader = GLSLShader.Load("default2d.shader"); } return(font); }
/// <summary> /// putsaa listat ja poista gl-datat /// </summary> public void ClearArrays() { Texture.DisposeAll(); GLSLShader.DisposeAll(); Material.DisposeAll(); Particles.DisposeAll(); Light.Lights.Clear(); Path.Paths.Clear(); world = null; world = new Renderable("World"); Node.ObjectCount = 0; for (int q = 0; q < Texture.MaxTextures; q++) { Texture.UnBind(q); } GLSLShader.UnBindShader(); GLSLShader.SetShader("default.shader", ""); GC.Collect(); GC.WaitForPendingFinalizers(); }
public override void Init() { depthFBO = new FBO(0, 0, 1, true); ShadowMapping.Create(depthFBO, "lightmask.png"); Fog.CreateFog(0.005f, Fog.Color); GLSLShader.SetShader("default.shader", "FOG"); skybox = Sky.Load("sky/sky2_", "jpg"); world.Add(skybox); GLSLShader.SetShader("default.shader", "LIGHTING:PERPIXEL:FOG"); Model scene = new Model(); DotScene ds = DotScene.Load("scene1/scene1.scene", scene); world.Add(scene); camPath = Path.GetPath("Path_camera"); camPath.Attach(camera, true, true); font = BitmapFont.Load("fonts/comic12.png"); Camera.Set3D(); base.Init(); }
void Init() { Instance = this; Log.WriteLine("CSatEng 0.9.2 // (c) mjt, 2008-2014"); Log.WriteLine("OS: " + System.Environment.OSVersion.ToString()); Log.WriteLine("Renderer: " + GL.GetString(StringName.Renderer)); Log.WriteLine("Vendor: " + GL.GetString(StringName.Vendor)); Log.WriteLine("Version: " + GL.GetString(StringName.Version)); Log.WriteLine(".Net: " + Environment.Version); string version = GL.GetString(StringName.Version); if (version.Contains("Compatibility")) { Settings.UseGL3 = false; } int major = (int)version[0]; int minor = (int)version[2]; if (major < 2) { Log.Error("You need at least OpenGL 2.0 to run this program. Please update your drivers."); } string ext = ""; if (Settings.UseGL3 == false) { ext = GL.GetString(StringName.Extensions); } else { int extC; GL.GetInteger(GetPName.NumExtensions, out extC); for (int q = 0; q < extC; q++) { ext += GL.GetString(StringNameIndexed.Extensions, q) + " "; } } Log.WriteLine("--------------------------------------------"); Log.WriteLine("Extensions:\n" + ext); Log.WriteLine("--------------------------------------------"); if (ext.Contains("texture_non_power_of_two")) { if (Settings.DisableNPOTTextures) { Log.WriteLine("NPOT textures supported but disabled."); Texture.IsNPOTSupported = false; } else { Log.WriteLine("NPOT textures supported."); Texture.IsNPOTSupported = true; } } else { Log.WriteLine("NPOT textures not supported."); Texture.IsNPOTSupported = false; } // löytyykö float texture extension if (ext.Contains("texture_float") && ext.Contains("color_buffer_float")) { if (Settings.DisableFloatTextures) { Log.WriteLine("Float textures supported but disabled."); Texture.IsFloatTextureSupported = false; } else { Log.WriteLine("Float textures supported."); Texture.IsFloatTextureSupported = true; } } else { Log.WriteLine("Float textures not supported."); Texture.IsFloatTextureSupported = false; } // tarkista voidaanko shadereita käyttää. if (!ext.Contains("vertex_shader") || !ext.Contains("fragment_shader")) { Log.Error("Shaders not supported. Please update your drivers."); } if (ext.Contains("EXT_framebuffer_object")) { if (Settings.DisableFbo) { Log.WriteLine("FBOs supported but disabled."); FBO.IsSupported = false; } else { Log.WriteLine("FBOs supported."); FBO.IsSupported = true; } } else { Log.WriteLine("FBOs not supported."); FBO.IsSupported = false; } GL.GetInteger(GetPName.MaxCombinedTextureImageUnits, out Texture.MaxTextures); Log.WriteLine("Max textureUnits: " + Texture.MaxTextures); Texture.BindedTextures = new uint[Texture.MaxTextures]; VSync = Settings.VSync ? VSyncMode.On : VSyncMode.Off; Settings.Device = DisplayDevice.Default; if (Settings.FullScreen) { Settings.Device.ChangeResolution(Settings.Device.SelectResolution(Settings.Width, Settings.Height, Settings.Bpp, 60f)); WindowState = OpenTK.WindowState.Fullscreen; } GL.Enable(EnableCap.DepthTest); GL.ClearDepth(1.0); GL.DepthFunc(DepthFunction.Lequal); GL.ClearColor(0.0f, 0.0f, 0.1f, 0); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); if (Settings.UseGL3 == false) { GL.Enable(EnableCap.Texture2D); GL.Enable(EnableCap.ColorMaterial); GL.Enable(EnableCap.Normalize); } GameClass.Keyboard = Keyboard; GameClass.Mouse = Mouse; GLSLShader.SetShader("default.shader", ""); Loading(); }
public override void Dispose() { if (particleTex != null) particleTex.Dispose(); if (depthShader != null) depthShader.Dispose(); particleTex = null; depthShader = null; particles.Clear(); Log.WriteLine("Disposed: Particles", false); }
public static void UnBindShader() { CurrentShader = null; GL.UseProgram(0); }
public void DataToVBO(Vertex[] vertices, ushort[] indices, VertexMode mode) { if (numOfIndices > 0) Dispose(); int size; vertexFlags = mode; numOfIndices = indices.Length; Vertex.Size = BlittableValueType.StrideOf(vertices); GL.GenBuffers(1, out vertexID); GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BufferData(BufferTarget.ArrayBuffer, (IntPtr)(vertices.Length * Vertex.Size), vertices, usage); GL.GetBufferParameter(BufferTarget.ArrayBuffer, BufferParameterName.BufferSize, out size); if (vertices.Length * BlittableValueType.StrideOf(vertices) != size) Log.Error("DataToVBO: Vertex data not uploaded correctly"); GL.GenBuffers(1, out indexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); GL.BufferData(BufferTarget.ElementArrayBuffer, (IntPtr)(indices.Length * sizeof(ushort)), indices, usage); GL.GetBufferParameter(BufferTarget.ElementArrayBuffer, BufferParameterName.BufferSize, out size); if (indices.Length * sizeof(short) != size) throw new ApplicationException("DataToVBO: Element data not uploaded correctly"); Shader = GLSLShader.Load(); if (Shader != null) { if (Settings.UseGL3) { GL.GenVertexArrays(1, out vaoID); GL.BindVertexArray(vaoID); } GL.BindBuffer(BufferTarget.ArrayBuffer, vertexID); GL.BindBuffer(BufferTarget.ElementArrayBuffer, indexID); Shader.SetAttributes(); if (Settings.UseGL3) GL.BindVertexArray(0); } GLExt.CheckGLError("DataToVBO"); }