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 static new Texture2D Load(string fileName, bool origCenter) { Texture t = Texture.Load(fileName); Texture2D tex = new Texture2D(); tex.textureName = fileName; tex.TextureID = t.TextureID; tex.Width = t.Width; tex.Height = t.Height; tex.RealWidth = t.RealWidth; tex.RealHeight = t.RealHeight; tex.Target = t.Target; tex.CreateVBO(origCenter); return(tex); }
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> /// lataa skybox (ei cubemap). skyName on nimen alkuosa eli esim plainsky_ jos tiedostot on plainsky_front.jpg, plainsky_back.jpg jne /// ext on tiedoston pääte eli esim jpg, dds /// </summary> public static Sky Load(string skyName, string ext) { Sky sky = new Sky(); string[] sideStr = { "top", "bottom", "left", "right", "front", "back" }; Node skyNode = new Node(); DotScene ds = DotScene.Load("sky/sky.scene", skyNode); int side = 0; TextureLoaderParameters.WrapModeS = TextureWrapMode.ClampToEdge; TextureLoaderParameters.WrapModeT = TextureWrapMode.ClampToEdge; TextureLoaderParameters.FlipImages = false; skyNode.GetList(true); for (int q = 0; q < ObjList.Count; q++) { OgreMesh m = ObjList[q] as OgreMesh; if (m != null) { sky.skyboxSides[side] = m; m.Boundings = null; m.CastShadow = false; string fileName = skyName + sideStr[side] + "." + ext; m.MaterialName = fileName; m.Material = Material.GetMaterial(fileName + "_material"); m.Material.Textures[Settings.COLOR_TEXUNIT].Tex = Texture.Load(m.MaterialName); side++; } } TextureLoaderParameters.FlipImages = true; TextureLoaderParameters.WrapModeS = TextureWrapMode.Repeat; TextureLoaderParameters.WrapModeT = TextureWrapMode.Repeat; return(sky); }
void LoadMD5(string fileName) { Name = fileName; // Initialize everything string line, textureName = ""; int i; Buffer t = new Buffer(); meshCount = 0; using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName)) { { while ((line = file.ReadLine()) != null) { Cleanstring(ref line); // Read number of joints if (ParseLine(ref t, line, "numJoints %d")) { numJoints = t.ibuffer[0]; baseSkel = new MD5Joint[numJoints]; } // Read number os meshes if (ParseLine(ref t, line, "numMeshes %d")) { numMesh = t.ibuffer[0]; model = new MD5Mesh[numMesh]; meshes = new List <Vertex[]>(numMesh); } // Parse model joints if (line.Equals("joints {")) { for (i = 0; i < numJoints; i++) { line = file.ReadLine(); Cleanstring(ref line); ParseLine(ref t, line, "%s %d ( %f %f %f ) ( %f %f %f )"); baseSkel[i].name = t.sbuffer; baseSkel[i].parent = t.ibuffer[0]; baseSkel[i].pos.X = t.fbuffer[0]; baseSkel[i].pos.Y = t.fbuffer[1]; baseSkel[i].pos.Z = t.fbuffer[2]; baseSkel[i].orient = new Quaternion(t.fbuffer[3], t.fbuffer[4], t.fbuffer[5], 1); QuaternionExt.ComputeW(ref baseSkel[i].orient); } } // Parse model meshes if (line.Equals("mesh {")) { while (!line.Equals("}")) { line = file.ReadLine(); Cleanstring(ref line); // Read texture name if (line.StartsWith("shader")) { string str = line.Substring(7); textureName = Settings.TextureDir + str; textureName = textureName.Replace(",", "."); } // Read mesh data if (ParseLine(ref t, line, "numverts %d")) { model[meshCount].numVert = t.ibuffer[0]; model[meshCount].verts = new MD5Vertex[model[meshCount].numVert]; model[meshCount].texture = Texture.Load(textureName); for (i = 0; i < model[meshCount].numVert; i++) { line = file.ReadLine(); ParseLine(ref t, line, "vert %d ( %f %f ) %d %d"); model[meshCount].verts[t.ibuffer[0]].uv.X = t.fbuffer[0]; model[meshCount].verts[t.ibuffer[0]].uv.Y = 1 - t.fbuffer[1]; model[meshCount].verts[t.ibuffer[0]].startw = t.ibuffer[1]; model[meshCount].verts[t.ibuffer[0]].countw = t.ibuffer[2]; } } if (ParseLine(ref t, line, "numtris %d")) { model[meshCount].numTris = t.ibuffer[0]; model[meshCount].faces = new int[model[meshCount].numTris][]; for (i = 0; i < model[meshCount].numTris; i++) { line = file.ReadLine(); ParseLine(ref t, line, "tri %d %d %d %d"); model[meshCount].faces[t.ibuffer[0]] = new int[3]; model[meshCount].faces[t.ibuffer[0]][0] = t.ibuffer[3]; // poly toisin päin model[meshCount].faces[t.ibuffer[0]][1] = t.ibuffer[2]; model[meshCount].faces[t.ibuffer[0]][2] = t.ibuffer[1]; } } if (ParseLine(ref t, line, "numweights %d")) { model[meshCount].numWeights = t.ibuffer[0]; model[meshCount].weights = new MD5Weight[model[meshCount].numWeights]; for (i = 0; i < model[meshCount].numWeights; i++) { line = file.ReadLine(); ParseLine(ref t, line, "weight %d %d %f ( %f %f %f )"); model[meshCount].weights[t.ibuffer[0]].joint = t.ibuffer[1]; model[meshCount].weights[t.ibuffer[0]].bias = t.fbuffer[0]; model[meshCount].weights[t.ibuffer[0]].pos.X = t.fbuffer[1]; model[meshCount].weights[t.ibuffer[0]].pos.Y = t.fbuffer[2]; model[meshCount].weights[t.ibuffer[0]].pos.Z = t.fbuffer[3]; } } } meshCount++; } } } } int maxvert = 0; for (int k = 0; k < numMesh; k++) { if (model[k].numVert > maxvert) { maxvert = model[k].numVert; } } for (int k = 0; k < numMesh; k++) { finalVert = new Vector3[maxvert]; normals = new Vector3[maxvert]; } skeleton = baseSkel; // prepare model for rendering PrepareMesh(); for (int q = 0; q < numMesh; q++) { Vertex[] v = meshes[q]; ushort[] ind = new ushort[v.Length]; for (ushort w = 0; w < ind.Length; w++) { ind[w] = w; } // luo vbo ja datat sinne model[q].vbo = new VBO(BufferUsageHint.DynamicDraw); model[q].vbo.DataToVBO(v, ind, VBO.VertexMode.UV1); } // laske normaalit for (int k = 0; k < numMesh; k++) { MathExt.CalcNormals(ref finalVert, ref model[k].faces, ref normals, false); } Log.WriteLine("Model: " + Name, false); }
void LoadMaterial(string fileName) { using (System.IO.StreamReader file = new System.IO.StreamReader(Settings.ModelDir + fileName)) { // tiedosto muistiin string data = file.ReadToEnd(); // pilko se string[] lines = data.Split('\n'); Material mat = new Material(); int curTexture = -1; for (int q = 0; q < lines.Length; q++) { string line = lines[q]; line = line.Trim('\r', '\t', ' '); if (line.StartsWith("//")) { continue; } string[] ln = line.Split(' '); // pilko datat if (ln[0] == "material") { curTexture = -1; mat = Material.CreateMaterial(ln[1]); Log.WriteLine("Material: " + mat.materialName, false); continue; } if (ln[0] == "shader") { mat.ShaderName = ln[1]; // ota shaderin nimi continue; } // lataa texture if (ln[0] == "texture") { curTexture++; if (ln[1] == "none") { continue; } mat.Textures[curTexture].Tex = Texture.Load(ln[1]); continue; } if (ln[0] == "tex_coord_set") { mat.Textures[curTexture].TexCoordSet = uint.Parse(ln[1]); continue; } if (ln[0] == "env_map") { if (ln[1] == "spherical") { mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.Spherical; } else if (ln[1] == "cubic_reflection") { mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.CubicReflection; } else { mat.Textures[curTexture].EnvMap = TextureInfo.EnvMaps.None; } continue; } // Ambient color if (ln[0] == "ambient") { mat.AmbientColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), 1); continue; } // Diffuse color if (ln[0] == "diffuse") { mat.DiffuseColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), 1); continue; } // Specular color if (ln[0] == "specular") { mat.SpecularColor = new Vector4(MathExt.GetFloat(ln[1]), MathExt.GetFloat(ln[2]), MathExt.GetFloat(ln[3]), MathExt.GetFloat(ln[4])); continue; } } } }