I want to draw 2D sprite.
And here is strange thing: if i Sprite.Draw2D with first overload:
using (Sprite Spr = new Sprite(Gfx))
{
Spr.Begin(SpriteFlags.AlphaBlend);
int SprY = Gfx.PresentationParameters.BackBufferHeight/2;
int SprX = Gfx.PresentationParameters.BackBufferWidth/2;
Spr.Draw2D(Tex, new Point(0,0), 0.0f, new Point(SprX,SprY), Color.White);
Spr.End();
while (!Spr.Disposed)
Spr.Dispose();
}
It locating right in 128,128.
But I want to scale-down my image.
So i use 3rd overload of Sprite.Draw2D:
Spr.Draw2D(Tex, new Rectangle(0, 0, 1024, 1024), new Rectangle(0,0,256,256), new Point(SprX,SprY) , Color.White);
Then, it draws to weired position(but correct-sized).
I found-out that width of screen in case of 3rd overload = 1280.
And no matter of PresentationParameters or ViewPort sizes. Even on other machine it is 1280, and center will be 640.
I've tryed to debug Gfx(Device) object and see if any appereance of '1280' number, and it is appear in Gfx.DisplayMode. Unfortunatly, i cant set this parameter because "Device.SetDisplayMode is deprecated" as MSDN says. And DisplayMode.Width is differs between two computers i've test my 'game' on.
Probably i've missed something realy HUGE and stack on it.
By the way, im using DirectX libs from "C:\Windows\Microsoft.NET\DirectX for Managed Code\1.0.2902.0" if this matters.
Related
I am using pipeline.exe tool, to convert an .fbx file I made using Blender (using the default Blender 2.73a export settings) to .xnb, and then manually copy and paste it in my content directory (Is this one of the correct ways to convert it properly ?).
After watching this video https://www.youtube.com/watch?v=u7tLYMPC828 I saw that you have to convert the .fbx file that you create using blender, to a new .fbx file, using a tool called fbx converter 2013, and then use that file in the pipeline.exe tool, to produce the final .xnb file. Without doing that, I can't even see my model when drawn on the screen.
With the steps I described above, I managed to see the .xnb file on my screen but it was not exactly the original model I had made. For example:
As you can see the real model I got (after the convertion with the fbx converter 2013) is much longer, whereas the one on the left (the one I draw in my game), is like packed in a small square.
If you are using blender, please let me know how do you import the .fbx to your Monogame project. (Or you can suggest to me another software you are using to make models and tell me your method of importing models to Monogame)
This is how I am drawing my model:
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
Vector3 modelPosition = new Vector3(-25, 0, 0);
float modelRotation = 0;
float aspectRatio = graphics.GraphicsDevice.Viewport.AspectRatio;
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in Brick.Meshes)
{
Vector3 cameraPosition = new Vector3(0.0f, 0.0f, 50.0f);
foreach (BasicEffect effect in mesh.Effects)
{
effect.EnableDefaultLighting();
effect.World = Matrix.CreateRotationZ(modelRotation)*
Matrix.CreateTranslation(modelPosition);
effect.View = Matrix.CreateLookAt(cameraPosition,
Vector3.Zero, Vector3.Up);
effect.Projection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(45.0f), aspectRatio, 1.0f, 10000.0f);
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
base.Draw(gameTime);
}
Edit: I also tried exporting to .X from blender and when i converted to .xnb, loaded the model and drew it, nothing shows up.
Ok, I finally realized what the problem was... my drawing code was incorrect. I tried https://msdn.microsoft.com/en-us/library/bb197293(v=xnagamestudio.31).aspx code from msdn website and it all worked out. I am stupid. Also, downloading https://msxna.codeplex.com/releases/view/117230 and installing all the files in the correct order (following the instructions .txt) fixed the monogame content project error I was having where I couldn't create the project (error missing project subtype 6D335F3A-9D43-41b4-9D22-F6F17C4BE596), obviously because I hadn't installed things properly.
So this is a continuation of a question I asked earlier today. I've built myself some nice looking ribbon trails using XNA 3.1's DrawUserPrimitives method, essentially by expanding a polygon as motion occurs. It all looks super sleek and nice, except for one thing - anti-aliasing. I cannot for the life of me work out how to apply it.
I've set this in the game constructor:
graphics.PreferMultiSampling = true;
And I've also added this to test for the hardware:
graphics.PreparingDeviceSettings += new EventHandler<PreparingDeviceSettingsEventArgs>((sender, e) =>
{
PresentationParameters parameters = e.GraphicsDeviceInformation.PresentationParameters;
parameters.MultiSampleQuality = 0;
#if XBOX
pp.MultiSampleType = MultiSampleType.FourSamples;
return;
#else
int quality;
GraphicsAdapter adapter = e.GraphicsDeviceInformation.Adapter;
SurfaceFormat format = adapter.CurrentDisplayMode.Format;
if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.FourSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.FourSamples;
}
else if (adapter.CheckDeviceMultiSampleType(DeviceType.Hardware, format, false, MultiSampleType.TwoSamples, out quality))
{
parameters.MultiSampleType = MultiSampleType.TwoSamples;
}
#endif
});
By adding some print lines, I know my hardware can support 4 sample AA, but this all seems to make no difference. I just can't seem to get this to work.
Here's a screenshot of one of my trails with all of that code applied:
I'd really appreciate some help. I looked at this a while ago for a solution to a different problem, and couldn't get it to work then, either.
Well, cheers.
Fixed this one, too!
The issue was that, while the back buffer was getting the right anti-alias settings, the render target wasn't. This meant that drawing to the render target was done without AA, but the texture that was then drawn to the back buffer was done with it. I've fixed it now.
I am currently trying to overlay two bitmaps using WriteableBitmapEx using this method found in the documentation:
writeableBmp.Blit(new Point(10, 10), bitmap, sourceRect,
Colors.White,WriteableBitmapExtensions.BlendMode.Additive);
I installed the package via NuGet which adds ...WinPhone.dll and WinPhoneXnaDependant.dll which seems to cause the problem. Here's the code I'm currently writing:
WriteableBitmap result = new WriteableBitmap(results, null);
WriteableBitmap overlay = new WriteableBitmap(0, 0).FromResource("Images/VizageOverlay.png");
var cropped = result.Crop(96, 0, 480, 728);
cropped.Blit(new Point(0, 0), overlay, new Point(0,0),
WriteableBitmapExtensions.BlendMode.Additive);
However, an error states that the WriteableBitmapExtensions.BlendMode.Additive *exists in both* the aforementioned dlls. I've tried getting rid of both and keeping one but I need both it appears for the above code.
Any ideas?
Remove the reference to the WinPhoneXnaDependant if you're not creating a XNA project.
If the problem persists, ping the author, René Schulte on Twitter.
Never saw that. A rebuild might help and you can just remove the reference to the XNA project. The WriteableBitmapExWinPhoneXnaDependant.dll contains XNA-dependent code like write to MediaLibrary. It's separated so the WBX lib can be used in background agents which prohibits the usage of such XNA code.
I have the following code, which in iOS 4 produces the look of a "disabled" UISegmentedControl. As the attentive reader will notice, I am developing in MonoTouch, thus the c# syntax.
private void MakeOverlayOnLastRatingSegment()
{
RemoveOverlayOnLastRatingSegment();
lastRatingDisabledLayer = new CALayer();
lastRatingDisabledLayer.Frame = new RectangleF(new PointF(0, 0), segmLastRating.Frame.Size);
lastRatingDisabledLayer.CornerRadius = 10.0f;
lastRatingDisabledLayer.BackgroundColor = UIColor.FromRGBA(0.5f, 0.5f, 0.5f, 0.2f).CGColor;
segmLastRating.Layer.AddSublayer(lastRatingDisabledLayer);
}
And the result is:
But on iOS5 the result is a bit different. The segment before the selected cell is written on top of my gray layer. It takes a bit close look - more evident on a real device instead of simulator. For some reason the screendump from the simulator is very light.
Has anyone else experienced this, and do somebody have a workaround?
Best regards
/Anders
Could you add your overlay layer to the layer of the segmented control’s superview? Or perhaps the segmented control’s layer’s superlayer?
I would like to write a simple 2D game in Mono/Gtk#with MonoDevelop 2.4. My first interest was to display a PNG image for the player character in the Window canvas (later I will respond to keyboard events in order to move it). However, I have found out a disturbing problem here: while I get a Gtk.Image object for the player character, the DrawImage method of the Gdk Window needs a Gdk image. How could I convert the first one to the latter?
public static void ShowImage(Gdk.Window w, Gtk.Image image)
{
w.DrawImage( Style.ForegroundGC( StateType.Normal ),
image, // ERROR
0, 0, image.Pixbuf.Width, image.Pixbuf.Height,
image.Pixbuf.Width, image.Pixbuf.Height
);
}
This is might appear simplistic, but honestly I haven't found the answer yet.
Gtk.Image.ImageProp is a property holding the Gdk.Image held in the Gtk.Image widget.
public static void ShowImage(Gdk.Window w, Gtk.Image image)
{
w.DrawImage( Style.ForegroundGC( StateType.Normal ),
image.ImageProp, // TRY THIS
0, 0, image.Pixbuf.Width, image.Pixbuf.Height,
image.Pixbuf.Width, image.Pixbuf.Height
);
}
Here is a link to the GTK# documentation.
Gtk.Image is a widget (or a control in winforms terminology).
see: http://library.gnome.org/devel/gtk/unstable/GtkImage.html
From your problem description I don't think you want to be using a Gtk.Image, but a Gdk.Image.
IE. change your ShowImage method to: public static void ShowImage(Gdk.Window w, Gdk.Image image)