Skip to content

Commit 0f32fae

Browse files
committed
fixes a bug with MonoGame and FNA when creating a texture at runtime
fixes Mono not finding the dylib by prepending "lib"
1 parent 7f3739a commit 0f32fae

File tree

3 files changed

+30
-30
lines changed

3 files changed

+30
-30
lines changed
File renamed without changes.

src/ImGui.NET.SampleProgram.XNA/ImGui.NET.SampleProgram.XNA.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
<ItemGroup>
1717
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/win-x64/cimgui.dll" CopyToOutputDirectory="PreserveNewest" />
18-
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/osx-x64/cimgui.dylib" CopyToOutputDirectory="PreserveNewest" />
18+
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/osx-x64/libcimgui.dylib" CopyToOutputDirectory="PreserveNewest" />
1919
<Content Include="$(RepositoryRootDirectory)/deps/cimgui/linux-x64/cimgui.so" CopyToOutputDirectory="PreserveNewest" />
2020
</ItemGroup>
2121

src/ImGui.NET.SampleProgram.XNA/SampleGame.cs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,18 @@ protected override void Initialize()
3737

3838
protected override void LoadContent()
3939
{
40-
// Texture loading example
40+
// Texture loading example
4141

42-
// First, load the texture as a Texture2D (can also be done using the XNA/FNA content pipeline)
43-
_xnaTexture = Texture2D.FromStream(GraphicsDevice, GenerateImage(300, 150));
42+
// First, load the texture as a Texture2D (can also be done using the XNA/FNA content pipeline)
43+
_xnaTexture = CreateTexture(GraphicsDevice, 300, 150, pixel =>
44+
{
45+
//Console.WriteLine( pixel );
46+
var red = (pixel % 300) / 2;
47+
return new Color(red, 1, 1);
48+
});
4449

45-
// Then, bind it to an ImGui-friendly pointer, that we can use during regular ImGui.** calls (see below)
46-
_imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
50+
// Then, bind it to an ImGui-friendly pointer, that we can use during regular ImGui.** calls (see below)
51+
_imGuiTexture = _imGuiRenderer.BindTexture(_xnaTexture);
4752

4853
base.LoadContent();
4954
}
@@ -107,28 +112,23 @@ protected virtual void ImGuiLayout()
107112
}
108113
}
109114

110-
private static Stream GenerateImage(int width, int height)
111-
{
112-
var stream = new MemoryStream();
113-
var random = new Random(42);
114-
115-
var bmp = new System.Drawing.Bitmap(width, height);
116-
var graphics = System.Drawing.Graphics.FromImage(bmp);
117-
graphics.Clear(System.Drawing.Color.Black);
118-
119-
for (int i = 0; i < 100; i++)
120-
{
121-
var size = random.Next(10, 50);
122-
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));
123-
124-
graphics.DrawEllipse(pen, random.Next(0, width), random.Next(0, height), size, size);
125-
}
126-
127-
bmp.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp);
128-
129-
stream.Position = 0;
130-
131-
return stream;
132-
}
133-
}
115+
public static Texture2D CreateTexture(GraphicsDevice device, int width, int height, Func<int, Color> paint)
116+
{
117+
//initialize a texture
118+
var texture = new Texture2D(device, width, height);
119+
120+
//the array holds the color for each pixel in the texture
121+
Color[] data = new Color[width * height];
122+
for(var pixel = 0; pixel < data.Length; pixel++)
123+
{
124+
//the function applies the color according to the specified pixel
125+
data[pixel] = paint( pixel );
126+
}
127+
128+
//set the color
129+
texture.SetData( data );
130+
131+
return texture;
132+
}
133+
}
134134
}

0 commit comments

Comments
 (0)