Oculus Utilisateur confirmé: Rang *****
Messages : 1688
| Sujet: [C#/XNA/WPF] Intégrer XNA à WPF Lun 14 Mai 2012 - 19:21 | |
| Salut à tous, J'ai suivis un tuto, mais il y a quelques incohérences ou du moins pour moi. Je suis arrivé à compiler en modifiant quelques trucs mais rien ne s'affiche voila mon code et le tuto : http://aerilys.fr/blog/?tag=xna-4Dans le projet Content Pipeline Extension, j'ai supprimé le .cs de base et j'ai mis ceci. - Code:
-
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Threading; using System.Text; using System.Windows; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework.Content.Pipeline; using Microsoft.Xna.Framework.Content.Pipeline.Graphics; using Microsoft.Xna.Framework.Content.Pipeline.Processors; using Microsoft.Xna.Framework.Audio; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.GamerServices; using Microsoft.Xna.Framework.Input; using Microsoft.Xna.Framework.Media;
namespace XNARender { public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; SpriteBatch spriteBatch;
Texture2D texture;
RenderTarget2D target; // Objet qui contiendra notre scène après le rendu public WriteableBitmap bitmap = new WriteableBitmap(800, 460, 96, 96, System.Windows.Media.PixelFormats.Bgra32, null); // l’objet à transmettre à WPF Microsoft.Xna.Framework.Color[] colors = new Microsoft.Xna.Framework.Color[800 * 460]; // le tableau qui nous permettra de remplir notre image
private DispatcherTimer timer; // Puisque nous allons recréer le cycle de vie d’un jeu XNA, nous aurons besoin d’un timer private GameTime gameTime = new GameTime();
public Game1() { graphics = new GraphicsDeviceManager(this); Content.RootDirectory = "Content"; this.Initialize(); this.LoadContent(); this.timer = new System.Windows.Threading.DispatcherTimer(); timer.Interval = TimeSpan.FromSeconds(1 / 60); timer.Tick += new EventHandler(TimerRender); gameTime = new GameTime(); }
protected override void Initialize() { base.Initialize(); } protected override void LoadContent() { spriteBatch = new SpriteBatch(GraphicsDevice); texture = base.Content.Load<Texture2D>("mont"); } void TimerRender(object sender, EventArgs e) { this.Update(gameTime); this.Draw(gameTime); } protected override void Update(GameTime gameTime) { base.Update(gameTime); }
protected override void Draw(GameTime gameTime) { graphics.GraphicsDevice.SetRenderTarget(target); // on indique que l'on veut effectuer le rendu dans notre RenderTarget GraphicsDevice.Clear(Microsoft.Xna.Framework.Color.CornflowerBlue);
spriteBatch.Begin(); spriteBatch.Draw(texture, new Rectangle(0, 0, 200, 200), Microsoft.Xna.Framework.Color.White); spriteBatch.End(); base.Draw(gameTime); // on fait le rendu de la scène
// Nous allons ecrire dans notre WriteableBitmap et lui assigner les pixels de notre scène bitmap.Lock(); unsafe { int bb = (int)bitmap.BackBuffer; foreach (Microsoft.Xna.Framework.Color color in colors) { *((int*)bb) = color.B | (color.G << 8) | (color.R << 16) | (color.A << 24); bb += sizeof(IntPtr); } } bitmap.AddDirtyRect(new System.Windows.Int32Rect(0, 0, 800, 460)); bitmap.Unlock(); while (true) { } } } } Dans le projet WPF : - Code:
-
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using XNARender;
namespace WPFWindow { /// <summary> /// Logique d'interaction pour MainWindow.xaml /// </summary> public partial class MainWindow : Window { XNARender.Game1 game;
public MainWindow() { InitializeComponent(); }
private void ButtonClcik(object sender, RoutedEventArgs e) { game = new XNARender.Game1(); RenderImage.Source = game.bitmap; } } } Et j'ai aussi un projet de contenu vide avec une image de-dans. Avec ce code vous aurez cette exception : "GraphicsDevice ne doit pas avoir la valeur Null lors de la création de nouvelles ressources." Merci d'avance |
|
Oculus Utilisateur confirmé: Rang *****
Messages : 1688
| Sujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF Mar 15 Mai 2012 - 22:39 | |
| Quelqu'un a pas une idée parce que c'est vraiment bête comme truc... |
|
SPLN Utilisateur confirmé: Rang ***
Messages : 588 Localisation : Sur son ordinateur *vous vois* arrêtez de me regarder comme ça Projet Actuel : En quête de projet(s)!
Mes projets:
SP Lecteur Multimedia (Stand by)
S-Portable Graphics (demo1.8 is out! demo2.0 is planned)
SSB RPG (Stand by)
| Sujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF Mer 16 Mai 2012 - 10:07 | |
| |
|
Wargamer *Excellent utilisateur*
Messages : 6938 Projet Actuel : Bataille de cake au fruits
| Sujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF Mer 16 Mai 2012 - 13:18 | |
| GraphicDevice = this.CreateGraphics();? _________________ Règle #1 du CBNA, ne pas chercher à faire dans la subtilité; personne comprend |
|
Oculus Utilisateur confirmé: Rang *****
Messages : 1688
| Sujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF Mer 16 Mai 2012 - 15:43 | |
| Ah oui c'est bon ça compile : - Code:
-
PresentationParameters pp; GraphicsDevice gd;
public Game1() { pp = new PresentationParameters(); pp.BackBufferFormat = SurfaceFormat.Color; pp.DepthStencilFormat = DepthFormat.Depth24; pp.PresentationInterval = PresentInterval.Immediate; pp.IsFullScreen = false; pp.DeviceWindowHandle = Window.Handle; gd = new GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.Reach, pp); Bon il reste un problème et pas un petit : Update et Draw ne s’exécute pas et j'ai aucun rendu dans ma fenêtre. |
|
Contenu sponsorisé
| Sujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF | |
| |
|