Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9065181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T16:26:18+00:00 2026-06-16T16:26:18+00:00

I’m attempting to draw many textures onto one texture to create a map for

  • 0

I’m attempting to draw many textures onto one texture to create a map for an RTS game, and while I can can draw an individual texture onscreen, drawing them all to a render target seems to have no effect (the window remains AliceBlue when debugging) . I am trying to determine whether or not anything is even drawn to the render target, and so I am trying to save it as a Jpeg to a file and then view that Jpeg, from my desktop. How can I access that Jpeg from MemoryStream?

protected override void LoadContent()
{

         spriteBatch = new SpriteBatch(GraphicsDevice);
         gridImage = new RenderTarget2D(GraphicsDevice, 1000, 1000);
         GraphicsDevice.SetRenderTarget(gridImage);
         GraphicsDevice.Clear(Color.AliceBlue);
         spriteBatch.Begin();


         foreach (tile t in grid.tiles)
         {
             Texture2D dirt = Content.Load<Texture2D>(t.texture);
             spriteBatch.Draw(dirt, t.getVector2(), Color.White);
         }
         test = Content.Load<Texture2D>("dirt");


             GraphicsDevice.SetRenderTarget(null);
             MemoryStream memoryStream = new MemoryStream();

            gridImage.SaveAsJpeg(memoryStream, gridImage.Width, gridImage.Height); //Or SaveAsPng( memoryStream, texture.Width, texture.Height )



         //    rt.Dispose();
             spriteBatch.End();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T16:26:20+00:00Added an answer on June 16, 2026 at 4:26 pm

    I made a simple screenshot method,

      void Screenie()
                {
                    int width = GraphicsDevice.PresentationParameters.BackBufferWidth;
                    int height = GraphicsDevice.PresentationParameters.BackBufferHeight;
    
                    //Force a frame to be drawn (otherwise back buffer is empty) 
                    Draw(new GameTime());
    
                    //Pull the picture from the buffer 
                    int[] backBuffer = new int[width * height];
                    GraphicsDevice.GetBackBufferData(backBuffer);
    
                    //Copy to texture
                    Texture2D texture = new Texture2D(GraphicsDevice, width, height, false, GraphicsDevice.PresentationParameters.BackBufferFormat);
                    texture.SetData(backBuffer);
                    //Get a date for file name
                    DateTime date = DateTime.Now; //Get the date for the file name
                    Stream stream = File.Create(SCREENSHOT FOLDER + date.ToString("MM-dd-yy H;mm;ss") + ".png"); 
    
                    //Save as PNG
                    texture.SaveAsPng(stream, width, height);
                    stream.Dispose();
                    texture.Dispose();
                }
    

    Also, Are you loading Texture2D dirt = Content.Load<Texture2D>(t.texture); Every frame? It looks like it… Dont do that! That will cause massive lag loading hundreds of tiles, hundreds of times per second! instead make a global texture Texture2D DirtDexture and in your LoadContent() method do DirtTexture = Content.Load<Texture2D>(t.texture); Now when you draw you can do spriteBatch.Draw(DirtTexture,...

    Do the same with spriteBatch = new SpriteBatch(GraphicsDevice); and
    gridImage = new RenderTarget2D(GraphicsDevice, 1000, 1000);

    You dont need to make new RenderTarget and Spritebatch each frame! Just do it in the Initialize() Method!

    Also see RenderTarget2D and XNA RenderTarget Sample For more information on using render targets

    EDIT: I realize its all in LoadContent, I didnt see that because the formatting was messed up, remember to add your Foreach (Tile, etc) in your Draw Method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.