• Advertisement


  • Content count

  • Joined

  • Last visited

Community Reputation

100 Neutral

About NexusOne

  • Rank
  1. How do I gain pixel-access to the form itself using System.Drawing?
  2. I don't want to make DirectX or OpenGL a dependency, I'd like to do without any external APIs. At least for this game (others I use MDX).
  3. OK, so I'm developing a high-performance 2D game in a System.Windows.Forms.Form window, and I need to use a very fast method of updating the window, so my FPS doesn't suffer. What is the fastest way to display something in a window? Currently I'm using a pictureBox; is there anything faster?
  4. Great news, I figured out what was wrong with my colors. I had completely forgotten to read the bytes of the color in LITTLE-ENDIAN, so what I thought was alpha was actually blue. Of course, I still would like to know why Console.WriteLine crashes XP-Pro x64, but some questions can never be answered...
  5. Quote: Suppose the current pixel in the back buffer was white.. then currentRed = 255, and then you add something to it and end up with something larger than 255, which you then cast to a byte and lose the most significant bits there. If you're trying to do transparency blending, which it looks like you are, then you should multiply currentRed by (1-scale). Are you hoping to write this to be faster than just using System.Drawing.Graphics to draw to the bitmap? I'm not adding newRed onto currentRed. If you look closely, the line you are referring to scales along the line between currentRed and newRed and sets currentRed to a value along that line designated by the newAlpha (remember, "newRed - currentRed" can be negative). Normally I would not bother with pointers in C# at all, in fact I have a beautiful personalized Image class that uses Graphics to do high-level rendering, but it is unfortunately too slow on large image processing for my current purpose, which is a 2D game on my native resolution of 1280 x 1024 in 32-bit color.
  6. Quote: why are you using uint for everything? It seems you should be using byte instead. Where is scanTemp defined? Some of the uints should probably be changed to bytes. I was still writing and re-writing this code. Sorry for the typos, if you scroll up I've corrected them now (unless there are more). Quote: Doesn't console writeline flush itself after the call ? and you're doing it for every pixel, that's a lot text flushing which isn't that quick anyway, you only need to see how slow the debug prints are when you're using directx and that churns out debug text.. This is run from the command line. Console.WriteLine on the command prompt is much faster than the debug prompt in VS. But the Console.WriteLine was only for debugging, it's not staying there. I just need to know how it crashes my computer, or things like this could happen in the future. On a separate question, if one of you runs this code and uncomments the commented out part (it's necessary for it to work), does this method work for you guys? For me the colors end up badly distorted (trying saving the image to view it). If you run it, remember that both images have to already be in PixelFormat.Format32bppArgb. Obviously you can take out the Console.WriteLine if you run it on your computer. But I wonder if yours would crash or if it's just bc I'm on x64. Things seem to go wrong all the time on this OS. That's why I'm wondering if the colors will be correct for someone else who runs this even though they become incorrect over here.
  7. Quote: If only it were possible to get the forum to format your code for you... CM Thanks
  8. There is only 1 thread running (other than unrelated window listeners and such). I'm running from the command prompt, and the code is compiled with /platform:86 so it's 32 bit and emulated for my OS (required to work with some 32-bit DLLs). I'll try your suggestions first chance tomorrow. For now here's my code. Some variables renamed here and whatnot for readability, so there may be typos. The method is supposed to draw one image (fore) on top of another (presumably larger) image (back) with the top-left of fore positioned at x,y on back. public void drawImage(Bitmap fore, Bitmap back, int x, int y){ if(fore == null || back == null) return; int foreWidth = fore.Width, foreHeight = fore.height; int realMinX = max(0, x), realMinY = max(0, y), realMaxX = min(x + subWidth, width), realMaxY = min(y + subHeight, height); if(realMinX >= back.width || realMinY >= back.height || realMaxX <= 0 || realMaxY <= 0) return; uint currentAlpha, currentRed, currentGreen, currentBlue, newAlpha, newRed, newGreen, newBlue; unsafe{ BitmapData backData = back.LockBits(new Rectangle(realMinX, realMinY, realMaxX - realMinX, realMaxY - realMinY), ImageLockMode.ReadWrite, PixelFormat.Format32bppArgb); BitmapData foreData = fore.LockBits(new Rectangle(0, 0, subWidth, subHeight), ImageLockMode.ReadOnly, PixelFormat.Format32bppArgb); byte* backScan = (byte*)(backData.Scan0), foreScan = (byte*)(foreData.Scan0); int backStride = backData.Stride, foreStride = foreData.Stride; int backDataWidth = backData.Width, backDataHeight = backData.Height, foreDataWidth = foreData.Width, foreDataHeight = foreData.Height; uint* pointer1, pointer2; float scale; for(int i = 0; i < backDataHeight; i++, backScan += backStride - backDataWidth * 4, foreScan += foreStride - foreDataWidth * 4){ for(int j = 0; j < backDataWidth; j++, backScan += 4, foreScan += 4){ pointer1 = (uint*)(foreScan); pointer2 = (uint*)(backScan); newAlpha = *foreScan; Console.WriteLine(newAlpha); //kills computer /*if(newAlpha == 255) *pointer2 = *pointer1; else if(newAlpha == 0); else{ newRed = *(foreScan + 1); newGreen = *(foreScan + 2); newBlue = *(foreScan + 3); currentAlpha = *backScan; currentRed = *(backScan + 1); currentGreen = *(backScan + 2); currentBlue = *(backScan + 3); scale = newAlpha / 255f; *(backScan + 1) = (byte)(currentRed + (newRed - currentRed) * scale); *(backScan + 2) = (byte)(currentGreen + (newGreen - currentGreen) * scale); *(backScan + 3) = (byte)(currentBlue + (newBlue - currentBlue) * scale); }*/ } } fore.UnlockBits(foreData); back.UnlockBits(backData); } } [Edited by - NexusOne on October 16, 2006 12:01:08 PM]
  9. I have a block of code I'm trying to debug. It uses a BitmapData object and iterates through the colors for fast image updating. While debugging I put in a Console.WriteLine command. But when it runs with this line the computer completely freezes, so that the mouse moves but nothing else works (i.e. can't click anywhere, windows are don't even say "not responding", they are fully dead and mouse clicks do nothing anywhere on the monitor (other windows, taskbar, etc). When I turn off the computer (which I'm forced to) and turn it on again, it occasionally gives me a BSOD (this is XP Pro x64) upon restart but it disappears too fast for me to read it then says "startup failed" and gives me a list of other startup options. When run without the Console.WriteLine none of this occurs. How is a writeline killing my computer?? My pointers in the bitmap memory are correct!
  10. Most CS students didn't do CS before college. You should be fine (honestly) as long as you have a passion for it. And the game industry really isn't that exclusive a club.
  11. Weird Billboard Rotation

    Well, for my purpose I really need it rotated correctly in all 3 dimensions. Thanks though.
  12. Weird Billboard Rotation

    But IS it really gimbal lock? Here's the new code I tried: Matrix rotate = Matrix.RotationQuaternion(Quaternion.RotationAxis(crossProduct, normal.angleRadians(camVec))); device.Transform.World = rotate * translation; and guess what? the same rotational error occurred. But quaternions can't have gimbal lock!
  13. Weird Billboard Rotation

    I'm not sure if you'd call this an update, but someone insists that the problem I have is "gimbal lock". I remember having a "gimbal lock" problem in a previous application but I never solved it, so that's no help to me, unless someone here knows how to get around it (the real problem comes in the call to rotate the billboard normal vector to the facing-camera vector, so I'm looking for a rotate-vectorA-to-vectorB solution about an arbitrary axis). Thanks
  14. Weird Billboard Rotation

    yea sry, typo The billboard and camera can be pretty much anywhere for this to happen. I have multiple such billboards all over the place and they all do this. The camera moves with mouse-button control so it can be in any location as well.
  15. Weird Billboard Rotation

    In world coords, the billboards face the camera (thus being billboards), so if a billboard is at (x, y, z) and the camera is at (m, n, o) the billboard faces (m-x, n-y, o-p). I tried normalizing but it didn't make a difference. Interestingly, although when the camera faces near (-1, 0, 0) the billboards rotate, when it faces (1, 0, 0) instead they do not.
  • Advertisement