Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm playing around with random map generation and what I want to do is:

  1. Input a command to generate a random map.
  2. A texture will be created resembling the generation, each pixel resembling each tile.
  3. A new window will pop-up, without removing the original one, that will contain the texture.

I know how to do this except for the last part. Would someone please tell me how to create a new window and draw a texture to this window?

share|improve this question
add comment

1 Answer 1

up vote 4 down vote accepted

Unfortunately there isn't anything in the XNA framework which could help you, but there are two other solutions:

The second solution is simpler because you can use it in this way:

System.Windows.Forms.Form form = new System.Windows.Forms.Form();
form.Show();

Then if you want to show the texture in the new form you should create a bitmap, and you can do it in this way (you have to add a reference to System.Drawing and System.IO):

System.IO.MemoryStream ms = new System.IO.MemoryStream();
Texture2D texture = Content.Load<Texture2D>( "Images\\test" ); //example
texture.SaveAsJpeg( ms, texture.Width, texture.Height );
System.Drawing.Bitmap bmp = new System.Drawing.Bitmap( ms );

The complete code could be:

protected override void Update(GameTime gameTime){
    //...

    ShowForm(CreateBitmap(texture));
    base.Update(gameTime);
}

private Bitmap CreateBitmap(Texture2D texture){
    System.IO.MemoryStream ms = new System.IO.MemoryStream();
    texture.SaveAsJpeg( ms, texture.Width, texture.Height );
    return new System.Drawing.Bitmap( ms );
}

private void ShowForm(Bitmap bmp){
    System.Windows.Forms.Form form = new System.Windows.Forms.Form();
    form.Location = new System.Drawing.Point(100, 100); //example
    form.Text = "Texture2D";
    form.BackgroundImage = bmp; //Set the texture as background 
    form.ClientSize = bmp.Size;
    form.Show();
}
share|improve this answer
1  
Thanks man, I just added this and it works perfectly, brilliant answer! –  John Oct 3 '12 at 21:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.