fixes a bug with MonoGame and FNA when creating a texture at runtime

fixes Mono not finding the dylib by prepending "lib"
internals
Mike 6 years ago
parent 7f3739a64e
commit 0f32fae4cd
  1. 0
      deps/cimgui/osx-x64/libcimgui.dylib
  2. 2
      src/ImGui.NET.SampleProgram.XNA/ImGui.NET.SampleProgram.XNA.csproj
  3. 58
      src/ImGui.NET.SampleProgram.XNA/SampleGame.cs

@ -15,7 +15,7 @@
<ItemGroup> <ItemGroup>
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/win-x64/cimgui.dll" CopyToOutputDirectory="PreserveNewest" /> <Content Include="$(RepositoryRootDirectory)/deps/cimgui/win-x64/cimgui.dll" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/osx-x64/cimgui.dylib" CopyToOutputDirectory="PreserveNewest" /> <Content Include="$(RepositoryRootDirectory)/deps/cimgui/osx-x64/libcimgui.dylib" CopyToOutputDirectory="PreserveNewest" />
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/linux-x64/cimgui.so" CopyToOutputDirectory="PreserveNewest" /> <Content Include="$(RepositoryRootDirectory)/deps/cimgui/linux-x64/cimgui.so" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup> </ItemGroup>

@ -37,13 +37,18 @@ namespace ImGuiNET.SampleProgram.XNA
protected override void LoadContent() protected override void LoadContent()
{ {
// Texture loading example // Texture loading example
// First, load the texture as a Texture2D (can also be done using the XNA/FNA content pipeline) // First, load the texture as a Texture2D (can also be done using the XNA/FNA content pipeline)
_xnaTexture = Texture2D.FromStream(GraphicsDevice, GenerateImage(300, 150)); _xnaTexture = CreateTexture(GraphicsDevice, 300, 150, pixel =>
{
//Console.WriteLine( pixel );
var red = (pixel % 300) / 2;
return new Color(red, 1, 1);
});
// Then, bind it to an ImGui-friendly pointer, that we can use during regular ImGui.** calls (see below) // Then, bind it to an ImGui-friendly pointer, that we can use during regular ImGui.** calls (see below)
_imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture); _imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
base.LoadContent(); base.LoadContent();
} }
@ -107,28 +112,23 @@ namespace ImGuiNET.SampleProgram.XNA
} }
} }
private static Stream GenerateImage(int width, int height) public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func<int, Color> paint)
{ {
var stream = new MemoryStream(); //initialize a texture
var random = new Random(42); var texture = new Texture2D(device, width, height);
var bmp = new System.Drawing.Bitmap(width, height); //the array holds the color for each pixel in the texture
var graphics = System.Drawing.Graphics.FromImage(bmp); Color[] data = new Color[width * height];
graphics.Clear(System.Drawing.Color.Black); for(var pixel = 0; pixel < data.Length; pixel++)
{
for (int i = 0; i < 100; i++) //the function applies the color according to the specified pixel
{ data[pixel] = paint( pixel );
var size = random.Next(10, 50); }
var pen = new System.Drawing.Pen(System.Drawing.Color.FromArgb(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255)), random.Next(1, 4));
//set the color
graphics.DrawEllipse(pen, random.Next(0, width), random.Next(0, height), size, size); texture.SetData( data );
}
return texture;
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp); }
}
stream.Position = 0;
return stream;
}
}
} }
Loading…
Cancel
Save