Showing posts with label Knowledge Base. Show all posts
Showing posts with label Knowledge Base. Show all posts

Sunday, 8 June 2008

Copying a Dynamically Created Bitmap to a Texture2D with XNA

I am sure someone has done it before, but I couldn't find any complete example in the web, so I wrote my own code: essentially it allows you to create a texture from a dynamically created Bitmap object. So you don't have to load the Bitmap from a file but you can dynamically create one in memory, do some GDI+ drawing on it (e.g for procedural textures) and then load it to a texture and use it. This can be useful if you want to programmatically create textures. Even though I have not tried it yet, you should be able to even update the texture before every frame using this method. This is the code:

using SD = System.Drawing;
using SDI = System.Drawing.Imaging;

// ...

protected override void LoadContent()
{
// Create Bitmap that we want edit and transfer to a texture
SD.Bitmap bitmap = new SD.Bitmap(100, 100);

// Create Graphics for the bitmap
SD.Graphics bitmapGraphics = SD.Graphics.FromImage(bitmap);

// Do some drawing with GDI+, e.g.
bitmapGraphics.Clear(SD.Color.CornflowerBlue);
// ... what ever you want to do :)

// Get rid of the graphcis object
bitmapGraphics.Dispose();

// Initialize our custom texture (should be defined in the class)
customTexture = new Texture2D(this.GraphicsDevice, bitmap.Width, bitmap.Height, 0, TextureUsage.None, SurfaceFormat.Color);

// Lock the bitmap data
SDI.BitmapData data = bitmap.LockBits(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height), System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);

// calculate the byte size: for PixelFormat.Format32bppArgb (standard for GDI bitmaps) it's the hight * stride
int bufferSize = data.Height * data.Stride; // stride already incorporates 4 bytes per pixel

// create buffer
byte[] bytes = new byte[bufferSize];

// copy bitmap data into buffer
Marshal.Copy(data.Scan0, bytes, 0, bytes.Length);

// copy our buffer to the texture
customTexture.SetData(bytes);

// unlock the bitmap data
bitmap.UnlockBits(data);
}

Using a standard Windows.Form for XNA Projects

Something that I found very helpful was the article by Pedro Güida. It tells you how to render the standard XNA output to a standard Windows.Form. Why would you want to do that? Well, some say it's good for writing level editors, but in my case it was useful since I wanted to override the Forms WinProc, which isn't possible in the Game class delivered by the XNA templates. There are some other solutions that accomplish that, but Pedro's solution is the only one that let's you still use the comfortable Game's class in conjunction with a standard Form. So here you go :) Thanks Pedro for this elegant and simple solution!

Saturday, 2 February 2008

Deactivate Flash in Firefox

Firefox can cause high amount of CPU-load when displaying multiple tabs with flash content. A very nice little plug-in for Firefox is Flashblock (must be good, considering it's name ;). You can either download it from the developer's website, or via the firefox addon-page. What it does is initially replacing every flash animation on a web page you load with a little spacer. Clicking on the spacer loads the appropriate flash movie. The effect is that it dramatically reduces the CPU load, as it suppresses all flash movies by default (a nice side-effect is that lots of adds disappear, as they are often implemented in flash). It also supports a white-list of pages on which flash should be loaded as usual, so you can add pages like youtube.com if you don't want to click on the spacer every time.

Monday, 5 November 2007

European Qosmio HD Component Out

I can now confirm that my European Qosmio G30 (which normally ships with the "D-Terminal to Scart" adapter) can output HD via a component. However, the "D-Terminal to Component" adaptor is not available in Europe but has to be ordered from the US. To get it, I called Toshiba and they referred me to their supplier for spare parts (who ships to Europe). The actual product I had to order is:
  • "D TO 3-RCA CABLE: Quosmio G15-AV501" (the "u" in Quosmio is also in the invoice ;)
Toshiba assigns different codes for their Quosmio models in the US, however, the G15 would not directly be the equivalent of my European G30, I believe. However, I think the cable would work with all Toshiba products, which have a D-Terminal (I *think* so, but don't quote me on it!) and which graphics card can do HD in its driver settings.
Consequently, contrary to several forum posts, Toshiba has not "butchered" the D-Terminal, and no hardware modification is necessary on the European Qosmios to output HD. You just need the magic cable, which is admittedly hard to get in Europe.

Saturday, 21 April 2007

SSL 3.0 "Seite kann nicht angezeigt werden"

Ich hatte das Problem, dass ein bestimmter Rechner innerhalb meines Rechners keine SSL 3.0 Seiten anzeigen konnte. IE zeigt "Seite kann nicht angezeigt werden" an, Firefox "Ungueltiger Nachrichten-Authentifizierungsheader empfangen". Nach langen rumprobieren habe ich das Problem gefunden: Der besagte Rechner war in meinem Router als DMZ eingetragen. Irgendwie hat das dann dazu gefuehrt dass SSL 3.0 nicht mehr geht. Wenn irgendjemand eine technische Erklaerung dafuer hat, bitte bei mir melden!

SSL 3.0 "Page cannot be displayed"

Yesterday I solved a weird problem where one of the machines in my network couldn't display any SSL 3.0 encrypted pages. IE would tell me "Page cannot be displayed", Firefox would pop up a window saying something like "Received invalid message header". I found the reason for this very surprising: in my router the DMZ was stet to the machines IP address and that somehow kept SSL 3.0 from working properly on that machine. If anyone can give me a technical explanation for this I would be very happy.