static void Main(string[] args) { int rangeX = 32; int rangeY = 1; int rangeZ = 25; ServerLib.MegaGridClient client = new MegaGridClient("http://localhost:3838"); Dictionary <string, string> gsa2names = client.GetNames(rangeX, rangeY, rangeZ); Dictionary <string, RectList> name2rects = client.Names2Rects(gsa2names); Console.WriteLine("Names and Rectangles resolved."); Console.WriteLine("Rendering net grid"); //Grid netGrid = RenderNetGrid(gsa2names, name2rects, rangeX, rangeY, rangeZ); Console.WriteLine("Rendering isometric net grid."); // Grid renderedGrid = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(netGrid, 204, 204, 238, 0, 1, 1, "MegaGrid"); Console.WriteLine("Saving final grid."); // GraphicsApi.SaveFlatPng("\\github\\glyphics2\\megagrid_iso.png", renderedGrid); Console.WriteLine("Rendering mega grid."); Grid grid = RenderFlatGrid(gsa2names, name2rects, rangeX, rangeY, rangeZ); Console.WriteLine("Saving final grid."); GraphicsApi.SaveFlatPng("\\github\\glyphics2\\megagrid_flat.png", grid); Console.WriteLine("Done."); }
static void ExecuteCodeToPng(ScratchControl ctl, string code) { //Glyphics codeString object Code rasterCode = RasterLib.RasterApi.CreateCode(code); //Save final result to PNG file string filenameOrthogonal = "..\\..\\" + RasterLib.RasterApi.CodeToCodename(rasterCode).Name + "-Ortho.PNG"; string filenameIsometric = "..\\..\\" + RasterLib.RasterApi.CodeToCodename(rasterCode).Name + "-Isometric.PNG"; //Execute, render, and save to png Grid grid = RasterLib.RasterApi.CodeToGrid(rasterCode); //Save png's to each if (ctl.FileNameOutOrthogonalAnimated) { GraphicsApi.SaveFlatPng(filenameOrthogonal, RasterLib.RasterApi.Renderer.RenderObliqueCells(grid)); } if (ctl.FileNameOutIsometricAnimated) { GraphicsApi.SaveFlatPng(filenameIsometric, RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, ctl.IsometricBgRgba[0], ctl.IsometricBgRgba[1], ctl.IsometricBgRgba[2], ctl.IsometricBgRgba[3], ctl.IsometricCellWidth, ctl.IsometricCellHeight)); } }
public static void DeployTo(string exePath, GraphicsApi gapi, bool is64bit) { string path = Path.GetDirectoryName(exePath); string fxFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ArxFx", "ReShade.fx"); List<CopyDef> files = GetIncludedFiles(fxFile); files.Add(new CopyDef(fxFile, "ReShade.fx")); string reshadeDllPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ArxFx", "ReShade{0}.dll"); if (gapi == GraphicsApi.Unknown) { var apis = GetAllGraphicsApiList(); foreach (var api in apis) { files.Add(new CopyDef( string.Format(reshadeDllPath, is64bit ? "64" : "32"), api )); } } else { files.Add(new CopyDef( string.Format(reshadeDllPath, is64bit ? "64" : "32"), GetGraphicsApiDll(gapi) )); } CopyFiles(files, path); }
static void Main(string[] args) { //for (int i=0;i<zodiac.Length;i+=2) //s{ // Console.WriteLine("{0:X}, {1:X} ",(uint)zodiac[i], (uint)zodiac[i+1]); //} byte[] unicodeBytes = Encoding.Unicode.GetBytes(zodiac); //♈️ ♉️ ♊️ ♋️ ♌️ ♍️ ♎️ ♏️ ♐️ ♑️ ♒️ ♓️ int bands = zodiac.Length; for (int i = 0; i < bands; i++) { byte v = (byte)(i * (255 / bands)); rgbV.Add(RasterLib.RasterApi.Rgba2Ulong(v, v, v, 255)); } // rgbV.Add(RasterLib.RasterApi.Rgba2Ulong(0, 0, 0, 0)); //rgbV.Add(RasterLib.RasterApi.Rgba2Ulong(0, 0, 0, 0)); //rgbV.Add(RasterLib.RasterApi.Rgba2Ulong(255,255,255,255)); /* * for (int i = 0; i < 360; i += 30) * { * ulong rgb = RasterLib.Utility.Converter.Hsl2Rgb(i, 100, 49); * byte r, g, b, a; * RasterLib.RasterApi.Ulong2Rgba(rgb, out r, out g, out b, out a); * Console.WriteLine("hue "+i + " - rgb " + r + "," + g + "," + b + "," + a); * rgbV.Add(rgb); * }*/ Grid gridIn = GraphicsApi.PngToGrid("c:\\github\\logo.png"); string str = ""; using (var file = new System.IO.StreamWriter("testUnicode.txt", false, Encoding.Unicode)) { for (int y = 0; y < gridIn.SizeY; y++) { for (int x = 0; x < gridIn.SizeX; x++) { CellProperties cp = gridIn.GetProperty(x, y, 0); byte r, g, b, a; RasterLib.RasterApi.Ulong2Rgba(cp.Rgba, out r, out g, out b, out a); string character = Rgb2UnicodeChar(r, g, b); file.Write(character); Console.Write(character); str += character; } file.WriteLine(); str += "\n"; } } Clipboard.SetText(str); }
public static void Control(ScratchControl ctl, RectList rects) { //Then render that to triangles Console.WriteLine("Creating triangle library"); TrianglesList trianglesList = RasterLib.RasterApi.CreateTrianglesList(); foreach (string filename in ctl.FileNamesInStlLibrary) { trianglesList.ImportAndReduceToUnit(filename); } //Render the rectangles out as shapes(Triangles) to a new set of triangles Triangles triangles = RasterLib.RasterApi.Renderer.RenderRectsAsStlMapping(rects, trianglesList); Console.WriteLine("Rendering triangles to grid"); //Reduce scale to 1x1x1, making it 1mm x 1mm x 1mm triangles.CalcNormals(); triangles.ReduceToUnit(); triangles.Translate(0.5f, 0.5f, 0.5f); //Scale up to make an exactly sized models in inches then millimeters const float finalSizeInInches = 2; const float finalSizeInMillimeters = finalSizeInInches * 25.4f; //Inches to millimeters triangles.Scale(finalSizeInMillimeters, finalSizeInMillimeters, finalSizeInMillimeters); //Save final result to STL file Console.WriteLine("Saving triangles to {0}", ctl.FileNameOutStl); RasterLib.RasterApi.SaveTrianglesToStlAscii(ctl.FileNameOutStl, triangles); //So.. as long as we are here.. let's make a preview //Since we can, normalize it now triangles.ReduceToUnit(); //Save a rendering out to a PNG, why not, too. Console.WriteLine("Creating preview grid"); Grid gridFromStl = RasterLib.RasterApi.CreateGrid(96, 96, 96, 4); Console.WriteLine("Rendering triangles to grid"); RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, gridFromStl); //Then render to a new grid Console.WriteLine("Rendering grid to oblique preview grid"); Grid gridObliqueRendered = RasterLib.RasterApi.Renderer.RenderObliqueCells(gridFromStl); //Then save if (ctl.FileNameOutStlPreview != null) { Console.WriteLine("Saving file to {0}", ctl.FileNameOutStlPreview); GraphicsApi.SaveFlatPng(ctl.FileNameOutStlPreview, gridObliqueRendered); } }
public static string GetGraphicsApiDll(GraphicsApi api) { switch (api) { case GraphicsApi.DirectX8: return "d3d8.dll"; case GraphicsApi.DirectX9: return "d3d9.dll"; case GraphicsApi.DirectX10: return "dxgi.dll"; case GraphicsApi.DirectX11: return "dxgi.dll"; case GraphicsApi.OpenGL: return "opengl32.dll"; default: throw new ArgumentOutOfRangeException(nameof(api), api, null); } }
static void Main() { //Create a grid Grid grid = RasterLib.RasterApi.CreateGrid(256, 256, 1, 4); //Draw procedural image to grid DrawProceduralImage(grid); //Save grid to png GraphicsApi.SaveFlatPng("..\\..\\generated.png", grid); Console.WriteLine("Done."); }
private static void DetermineShaderExtension() { // Use reflection to figure out if Shader.Profile is OpenGL (0) or DirectX (1). // May need to be changed / fixed for future shader profiles. var assembly = typeof(Game).GetTypeInfo().Assembly; if (assembly == null) { throw new ShaderLookupException( "Error determining shader profile. Couldn't find assembly. Falling back to OpenGL."); } var shaderType = assembly.GetType(SHADER_TYPE); if (shaderType == null) { throw new ShaderLookupException( $"Error determining shader profile. Couldn't find shader type of '{SHADER_TYPE}'. Falling back to OpenGL."); } var shaderTypeInfo = shaderType.GetTypeInfo(); if (shaderTypeInfo == null) { throw new ShaderLookupException( "Error determining shader profile. Couldn't get TypeInfo of shadertype. Falling back to OpenGL."); } // https://github.com/MonoGame/MonoGame/blob/develop/MonoGame.Framework/Graphics/Shader/Shader.cs#L47 var profileProperty = shaderTypeInfo.GetDeclaredProperty(PROFILE); var value = (int)profileProperty.GetValue(null); switch (value) { case 0: CurrentGraphicsApi = GraphicsApi.OPEN_GL; break; case 1: CurrentGraphicsApi = GraphicsApi.DIRECT_X; break; default: throw new ShaderLookupException("Unknown shader profile."); } }
//Document by codeString example public void DocumentByCode(string documentationPath, string title, string code) { string path = documentationPath; IRenderer renderer = RasterLib.RasterApi.Renderer; Console.WriteLine(title); Grid grid = RasterLib.RasterApi.CodeToGrid(RasterLib.RasterApi.CreateCode(code)); // using () { Grid gridIso = RasterLib.RasterApi.CodeToGrid(RasterLib.RasterApi.CreateCode(code.Replace("WallCube 37", "WallCube 21"))); Grid gridIsometric = renderer.RenderIsometricCellsScaled(gridIso, 255, 255, 255, 255, 6, 6, "Isometric docs"); GraphicsApi.SaveFlatPng(path + title + "-Iso.png", gridIsometric); Grid gridOrtho = renderer.RenderObliqueCells(grid); GraphicsApi.SaveFlatPng(path + title + "-Ortho.png", gridOrtho); int id = RasterLib.RasterApi.GetId(title); if (id >= 0) {//Glyph description Glyph glyph = RasterLib.RasterApi.GetGlyph(id); string description = glyph.Desc; string glyphDoc = "#" + title + "\n" + "\n##Description: " + description + "\n##Arguments: " + glyph.Syntax + "\n" + "\n![](" + title + "-Iso.png)\n" ; //Console.WriteLine(glyphDoc + "\n"); string crCode = TokensToHotlinkedCode(RasterLib.RasterApi.CodeToTokens(RasterLib.RasterApi.CreateCode(code))); glyphDoc += "\nFigure Code:\n" + crCode + "\nCondensed: " + code + "\n"; using (var file = new System.IO.StreamWriter(path + title + ".md")) { file.WriteLine(glyphDoc); } } //Needs example writer for markdown here, if needed //else { } } }
private void RunPngLoadSaveTest(int bpp) { const string cubeCode1 = "Size3D1 4 4 1;PenColorD4 255 255 255 255;FillRect 0 0 0 4 4 4"; const string cubeCode2 = "Size3D2 4 4 1;PenColorD4 255 255 255 255;FillRect 0 0 0 4 4 4"; const string cubeCode3 = "Size3D3 4 4 1;PenColorD4 255 255 255 255;FillRect 0 0 0 4 4 4"; const string cubeCode4 = "Size3D4 4 4 1;PenColorD4 255 255 255 255;FillRect 0 0 0 4 4 4"; const string filename = "test.png"; string cubeCode = ""; //Set BPP if (bpp == 1) { cubeCode = cubeCode1; } if (bpp == 2) { cubeCode = cubeCode2; } if (bpp == 3) { cubeCode = cubeCode3; } if (bpp == 4) { cubeCode = cubeCode4; } //Generate the triangles Code code = RasterLib.RasterApi.CreateCode(cubeCode); Grid gridOut = RasterLib.RasterApi.CodeToGrid(code); //Save and load GraphicsApi.SaveFlatPng(filename, gridOut); Grid gridIn = GraphicsApi.PngToGrid(filename); Assert.IsTrue(GridsAreEqual(gridIn, gridOut)); //If not equal, problem }
public static GraphicsBackend ConvertApiToVeldridGraphicsBackend(GraphicsApi api) { switch (api) { case GraphicsApi.Direct3D11: return(GraphicsBackend.Direct3D11); case GraphicsApi.Metal: return(GraphicsBackend.Metal); case GraphicsApi.OpenGL: return(GraphicsBackend.OpenGL); case GraphicsApi.OpenGLES: return(GraphicsBackend.OpenGLES); case GraphicsApi.Vulkan: return(GraphicsBackend.Vulkan); default: return(GraphicsBackend.OpenGL); //This function is not (!) run if SystemDefault enum option chosen. But defaults to opengl anyway if happens too... } }
static void Main() { //Manually create 64x64x64 grid to draw STL to Grid grid = RasterLib.RasterApi.CreateGrid(64, 64, 64, 4); const string inputFilenameStl = "..\\..\\archquad.stl"; Console.WriteLine("Input filename: {0}", inputFilenameStl); //Load the triangles from the STL file and reduce to a unit 1x1x1 size Triangles triangles = RasterLib.RasterApi.StlToTriangles(inputFilenameStl); triangles.ReduceToUnit(); Console.WriteLine("Triangle count: {0}", triangles.Count); //Render the triangles to the grid, will autosize to grid size RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, grid); //At this point we've loaded and grid has the rendering. So let's make a pretty rendering. //Render the 3D grid to a new 2D grid, in oblique view Grid gridObliqueRendering = RasterLib.RasterApi.Renderer.RenderObliqueCells(grid); //Write out a little bit about the grid Console.WriteLine("Grid: ({0},{1},{2})", grid.SizeX, grid.SizeY, grid.SizeZ); //Just state the dRectory we are writing to. const string outputFilenamePng = "..\\..\\test.png"; Console.WriteLine("\nOutput filename: {0}", outputFilenamePng); //Finally save the oblique rendering out to a png file GraphicsApi.SaveFlatPng(outputFilenamePng, gridObliqueRendering); Console.WriteLine("Done"); }
//Generate documentation for a piece of Glyphics codeString public void DocumentByCode(string documentationPath, string title, string code) { string path = documentationPath; IRenderer renderer = RasterLib.RasterApi.Renderer; Console.WriteLine(title); Grid grid = RasterLib.RasterApi.CodeToGrid(RasterLib.RasterApi.CreateCode(code)); // using () { Grid gridIso = RasterLib.RasterApi.CodeToGrid(RasterLib.RasterApi.CreateCode(code.Replace("WallCube 37", "WallCube 21"))); Grid gridIsometric = renderer.RenderIsometricCellsScaled(gridIso, 255, 255, 255, 255, 6, 6, "Isometric Docs"); GraphicsApi.SaveFlatPng(path + title + "-Iso.png", gridIsometric); Grid gridOrtho = renderer.RenderObliqueCells(grid); GraphicsApi.SaveFlatPng(path + title + "-Ortho.png", gridOrtho); int id = RasterLib.RasterApi.GetId(title); if (id >= 0) {//Glyph description Glyph glyph = RasterLib.RasterApi.GetGlyph(id); string description = glyph.Desc; description = description.Replace("<", "<"); description = description.Replace(">", ">"); string glyphDoc = "<title>" + title + "</title>" + "<h1>" + title + " Glyph function</h1>" + "<h3>Description:</h3>" + description + "<br><img src=\"" + title + "-Ortho.png\">" + "<img src=\"" + title + "-Iso.png\">" ; //Console.WriteLine(glyphDoc + "\n"); string crCode = TokensToHotlinkedCode(RasterLib.RasterApi.CodeToTokens(RasterLib.RasterApi.CreateCode(code))); glyphDoc += "<h3>Figure Code</h3><pre>" + crCode + "</pre><h4>Condensed</h4><pre>" + code + "</pre><br>"; using (var file = new System.IO.StreamWriter(path + title + ".html")) { file.WriteLine(glyphDoc); } } else {//Example string exampleDoc = "<title>" + title + "</title>" + "<h1>" + title + " Glyph Function Example</h1>" ; string str = title + ".png"; str = "<a href=\"" + str + "\"><img src=\"" + str + "\"></a>"; exampleDoc += str + "\n"; string crCode = TokensToHotlinkedCode(RasterLib.RasterApi.CodeToTokens(RasterLib.RasterApi.CreateCode(code))); exampleDoc += "<h3>Example Code</h3><pre>" + crCode + "</pre><h4>Condensed</h4><pre>" + code + "</pre><br>"; using (var file = new System.IO.StreamWriter(path + title + ".html")) { file.WriteLine(exampleDoc); } } } }
public void SetGraphicsApi(GraphicsApi api, Action systemPreAppReinitialisation) { }
public bool IsGraphicsApiSupported(GraphicsApi api) => true;
public static void SuperDebug(ScratchControl ctl) { Grid grid = null; if (ctl.FileNameInCode == null && ctl.FileNameInImage == null && ctl.FileNameInStl == null && ctl.FileNameInSvg == null) { Console.WriteLine("Must have FileNameIn type."); return; } if (ctl.FileNameInSvg != null) { Console.WriteLine("SVG Input filename: {0}", ctl.FileNameInSvg); string codeString = Svg2Gly.ConvertSvg2Gly(ctl.FileNameInSvg); Console.WriteLine("SVG:\n" + codeString); Code code = RasterLib.RasterApi.CreateCode(codeString); if (ctl.Resize != null) { code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]); } Console.WriteLine("Code: {0}\n", codeString); grid = RasterLib.RasterApi.CodeToGrid(code); } else if (ctl.FileNameInStl != null) { grid = RasterLib.RasterApi.CreateGrid(64, 64, 64, 4); Console.WriteLine("STL Input filename: {0}", ctl.FileNameInStl); //Load the triangles from the STL file and reduce to a unit 1x1x1 size Triangles triangles = RasterLib.RasterApi.StlToTriangles(ctl.FileNameInStl); triangles.ReduceToUnit(); Console.WriteLine("Triangle count: {0}", triangles.Count); //Render the triangles to the grid, will autosize to grid size RasterLib.RasterApi.Renderer.RenderTrianglesToGrid(triangles, grid); } else if (ctl.FileNameInImage != null) { Grid gridImg = GraphicsApi.FileToGrid(ctl.FileNameInImage); GridContext gc = new GridContext(gridImg); RasterLib.RasterApi.Painter.FlipY(gc); int div = 63;// 31;// 15; grid = RasterLib.RasterApi.CreateGrid(gridImg.SizeX, 255 / div + 1, gridImg.SizeY, 4); Console.WriteLine("Extruding"); Extrusion(grid, gridImg, div); Console.WriteLine("Rendering"); Grid gridIsometricScaledQuick = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, 0, 0, 0, 0, 4, 4); Console.WriteLine("Saving"); GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaledQuick); Console.WriteLine("Saved"); } else if (ctl.FileNameInCode != null) { string codeString = RasterLib.RasterApi.ReadGlyc(ctl.FileNameInCode).Replace(';', '\n'); Code code = RasterLib.RasterApi.CreateCode(codeString); Console.WriteLine("Code: {0}\n", codeString); Codename codename = RasterLib.RasterApi.CodeToCodename(code); Console.WriteLine("Codename: {0}\n", codename); if (ctl.OutputTokens) { TokenList glyphTokens = RasterLib.RasterApi.CodeToTokens(code); string tokenDesc = "Tokens:\n" + glyphTokens + "\n"; Console.WriteLine(tokenDesc); } if (ctl.Resize != null) { code = RasterLib.RasterApi.CodeToRescaledCode(code, ctl.Resize[0], ctl.Resize[1], ctl.Resize[2]); } grid = RasterLib.RasterApi.CodeToGrid(code); Console.WriteLine("Grid: {0}\n", grid); if (ctl.FileNameOutOrthogonalAnimated || ctl.FileNameOutIsometricAnimated) { ControlAnimator.DoAnimation(ctl, code.codeString, codename.ToString()); } } //DownSolver ds = new GeneralLibrary.DownSolver(codeString); if (ctl.OutputBytes && grid != null) { string bytesDesc = RasterLib.RasterApi.BytesToString(grid.CloneData()); Console.WriteLine("GridBytes:\n{0}\n", bytesDesc); } RectList rects = RasterLib.RasterApi.GridToRects(grid); if (ctl.OutputRectangles)//rects { Console.WriteLine("Rects: {0}\n{1}", rects.Count, rects); RasterLib.RasterApi.BuildCircuit(rects, true); string serialized = RasterLib.RasterApi.RectsToSerializedRectsLimit255(rects).SerializedData; Console.WriteLine("Serialized Rects: (len={0})\n{1}\n", serialized.Length, serialized); RasterLib.RasterApi.SaveFlatText("..\\..\\foo.txt", serialized); //Clipboard.SetText(serialized); SerializedRects serializedRects = new SerializedRects(serialized); RectList rectsDecoded = RectConverter.SerializedRectsToRects(serializedRects); int count = 0; Console.WriteLine("# of Decoded Rects = {0}", rectsDecoded.Count); foreach (Rect rect in rectsDecoded) { Console.WriteLine(count + " : " + rect); count++; } } if (ctl.OutputRenderedAscii) { Console.WriteLine("2d view:\n{0}", RasterLib.RasterApi.Renderer.GridToHexDescription(grid)); Console.WriteLine("3d view:\n{0}", RasterLib.RasterApi.Renderer.GridTo3DDescription(grid, 0, 0, 0)); } if (ctl.OutputSceneGraph) { Scene scene = RasterLib.RasterApi.RectsToScene(rects); Console.WriteLine("Scene: {0}", scene); QuadList quads = RasterLib.RasterApi.RectsToQuads(rects); Console.WriteLine("Quads: {0}", quads); Triangles triangles = RasterLib.RasterApi.QuadsToTriangles(quads); Console.WriteLine("Triangles: {0}", triangles); } if (ctl.FileNameOutStl != null) { ControlStl.Control(ctl, rects); } if (ctl.FileNameOutOrthogonal != null) { Console.WriteLine("Orthogonal Rendering.."); Grid gridOrthogonal = RasterLib.RasterApi.Renderer.RenderObliqueCells(grid); GraphicsApi.SaveFlatPng(ctl.FileNameOutOrthogonal, gridOrthogonal); } if (ctl.FileNameOutIsometric != null) { Console.WriteLine("Isometric Rendering.."); if (ctl.IsometricCellWidth < 1) { ctl.IsometricCellWidth = 1; } if (ctl.IsometricCellHeight < 1) { ctl.IsometricCellHeight = 1; } Grid gridIsometricScaled = RasterLib.RasterApi.Renderer.RenderIsometricCellsScaled(grid, ctl.IsometricBgRgba[0], ctl.IsometricBgRgba[1], ctl.IsometricBgRgba[2], ctl.IsometricBgRgba[3], ctl.IsometricCellWidth, ctl.IsometricCellHeight); GraphicsApi.SaveFlatPng(ctl.FileNameOutIsometric, gridIsometricScaled); } Console.WriteLine(); }
public SetIntersightGraphicsController() { ApiInstance = new GraphicsApi(Config); ModelObject = new GraphicsController(); MethodName = "UpdateGraphicsControllerWithHttpInfo"; }
public GetIntersightGraphicsController() { ApiInstance = new GraphicsApi(Config); MethodName = "GetGraphicsControllerListWithHttpInfo"; }