• Mandlebrot on Xbox 360 (XNA).
    3 replies, posted
I want to learn how to generate a Mandelbrot fractal on the X360. Problem is, I'm not sure how to (at least somewhat) efficiently draw the pixels to the screen. Any brilliant ides?
I know XNA is probably muchly different, but when I need to efficiently render a Bitmap in C#, I use unsafe code to write to the raw bytes. You [B][I]might[/I][/B] be able to do a similar thing with XNA, but I'm no expert in XNA. Here's what I do: [code] void foo() { BitmapData bd = bmp.LockBits(rt.ClientRectangle, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); try { int stride = bd.Stride; unsafe { byte* pixel = (byte*)(void*)bd.Scan0; byte r, g, b; for (int y = 0; y < h; y++) { int yPos = y * stride; for (int x = 0; x < w; x++) { int pos = yPos + (x * 3); // blue pixel[pos + 0] = 127; // green pixel[pos + 1] = (byte)(grid1[x, y]/2D); // red pixel[pos + 2] = (byte)grid1[x, y]; } } } } finally { bmp.UnlockBits(bd); } // do something with the bitmap here } [/code]
Okay, I should be able to write it to a texture after that.
I used XNA to display my mandelbrot. [code] Texture2d texture = new Texture2D(Device, 800, 600, 1, TextureUsage.None, SurfaceFormat.Color); Color[] pixels = new Color[800 * 600]; textue.GetData<Color>(pixels); pixels[1] = Color.Black; texture.SetData<Color>(pixels); [/code]
Sorry, you need to Log In to post a reply to this thread.