AccueilAccueil  FAQFAQ  RechercherRechercher  Dernières imagesDernières images  S'enregistrerS'enregistrer  Connexion  
Le Deal du moment : -29%
PC portable Gamer ERAZER DEPUTY P60 – ...
Voir le deal
999.99 €

 

 [C#/XNA/WPF] Intégrer XNA à WPF

Aller en bas 
3 participants
AuteurMessage
Oculus
Utilisateur confirmé: Rang *****



Messages : 1688

[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF EmptyLun 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-4

Dans 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 Wink
Revenir en haut Aller en bas
Oculus
Utilisateur confirmé: Rang *****



Messages : 1688

[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF EmptyMar 15 Mai 2012 - 22:39

Quelqu'un a pas une idée parce que c'est vraiment bête comme truc...
Revenir en haut Aller en bas
SPLN
Utilisateur confirmé: Rang ***
SPLN


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)

[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF EmptyMer 16 Mai 2012 - 10:07

Sincèrement j'ai fait que très peu de C#. Mais avec la fonction rechercher j'ai trouvé ça dans ton cs:
Code:
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            texture = base.Content.Load<Texture2D>("mont");
        }

Je n'ai vu nullepart ni une variable, ni une classe GraphicDevice du coup la valeur par défaut est null sauf si elle aurait été importé. Du coup il faut chercher de ce coté là. Sinon tu peux peut-être checher sur MSDN: http://msdn.microsoft.com/en-us/library/bb200104.aspx
Pour le rendu graphique: http://msdn.microsoft.com/en-us/library/bb197298.aspx ; http://msdn.microsoft.com/en-us/library/bb194908.aspx

Après je ne peux pas plus t'aider :v/

_________________
SP Lecteur Multimedia
I am an [C#/XNA/WPF] Intégrer XNA à WPF Gmq4 in the GM Quiz!
Revenir en haut Aller en bas
http://sp-lecteur-multimedia.skyrock.com/
Wargamer
*Excellent utilisateur*
Wargamer


Messages : 6938
Projet Actuel : Bataille de cake au fruits

[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF EmptyMer 16 Mai 2012 - 13:18

GraphicDevice = this.CreateGraphics();?

_________________
[C#/XNA/WPF] Intégrer XNA à WPF Wargamer3
Règle #1 du CBNA, ne pas chercher à faire dans la subtilité; personne comprend
Revenir en haut Aller en bas
Oculus
Utilisateur confirmé: Rang *****



Messages : 1688

[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF EmptyMer 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.
Revenir en haut Aller en bas
Contenu sponsorisé





[C#/XNA/WPF] Intégrer XNA à WPF Empty
MessageSujet: Re: [C#/XNA/WPF] Intégrer XNA à WPF   [C#/XNA/WPF] Intégrer XNA à WPF Empty

Revenir en haut Aller en bas
 
[C#/XNA/WPF] Intégrer XNA à WPF
Revenir en haut 
Page 1 sur 1

Permission de ce forum:Vous ne pouvez pas répondre aux sujets dans ce forum
Forum Le CBNA :: Développement :: Programmation-
Sauter vers: