winzip icon

Direct Memory Addressing (Fast Pixels) in DirectX7

Submitted on: 2/8/2015 9:02:00 AM
By: KRADLE OF FILTH (from psc cd)  
Level: Advanced
User Rating: By 2 Users
Compatibility: VB 5.0, VB 6.0
Views: 1349
     Also known as Direct Memory Access. This is based on Andre Lamothe's method of plotting pixels. The purpose of this is to show people how to do direct memory addressing on the backbuffer surface to draw pixels extremly fast. Microsoft has hidden some useful things within DirectX in VB that make stuff like this possible. The main one that is needed is the pointer to the backbuffer surface called lpSurface (located and hidden in DDSURFACEDESC2.) If you want to see other hidden members, just go in object browser, right click, and goto Show Hidded Members. We now need an array that will point to the lpSurface (using Safe Array of course) that we can use to actually draw the pixels. We will call it Video_Buffer(). Depending on the color mode you are using though, you will need to declare Video_Buffer() with the same number of bytes the color mode is. For example, Video_Buffer() as Integer (2 bytes) for 16 bit color mode (2 bytes). Now the formula to plot the pixel is this: Video_Buffer(X + Y * Memory_Pitch) = Color. The memory pitch (lPitch, located in DDSURFACEDESC2) models the fact that a video card might have some extra memory per line because of caches or hardware addressing. For example, your resolution set at 640x480x8 shows you have 640 bytes per line on the screen, but the memory pitch is set at 1024 bytes per line in video memory. Of course, depending on what color mode you are using, you have to divide the memory pitch by the number of bytes your color mode is. Before you can actually write the pixel though, you have to lock the backbuffer surface and obtain the correct memory pitch (if you didn't, the memory pitch is useless.) Then you write the pixel, and unlock the backbuffer when done. I have three examples of how this can be useful. My only problem now is figuring out a way to Fillmemory in words (2 bytes) and Dwords (4 bytes) for fast scanline drawing. I have the assembly source code commented within this program (written by Andre Lamothe) but don't know how to use it in Visual Basic nor do I have any experience in assembly. Oh, well, at least I got this far. This program is heavily commented for those who are beginners. VOTES AND COMMENTS PLEASE!!!

winzip iconDownload code

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. Afterdownloading it, you will need a program like Winzip to decompress it.Virus note:All files are scanned once-a-day by Planet Source Code for viruses, but new viruses come out every day, so no prevention program can catch 100% of them. For your own safety, please:
  1. Re-scan downloaded files using your personal virus checker before using it.
  2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.
  3. Scan the source code with Minnow's Project Scanner

If you don't have a virus scanner, you can get one at many places on the net

Other 2 submission(s) by this author


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)

Other User Comments

 There are no comments on this submission.

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)

To post feedback, first please login.