I would like to know how to write directly to a frame's(window) buffer(video memory) in windows. How would I obtain where the memory is stored and how would I write to it.
- I don't wan't to have to use DirectX, OpenGL, ect.
wellll - with 16-bit code, you can do that, but it isn't all that easy (except mode 13h)
under windows 32, you probably want to learn DirectX or OpenGL
You cannot directly access the Video Memory since windows did not allow you to draw into it, if you insist windows will generate a GPF.
So the only way is, you write the pixel data to RAM and then use BitBlt to transfer the pixel data from RAM to VRAM.
Before you can draw anything to the VRAM first you will need to create a BITMAP object and a DC object. To make thing easier take a look to Donkey Graph Lib and see the code on PutPixel function.
Or, if you see this code and understand how to use it
fLayer struct
DC dword 0
bmp dword 0
fLayer ends
fNewLayer proc uses esi lpLayerStruct:dword,_width:dword,height:dword
mov esi,lpLayerStruct
invoke CreateCompatibleDC,0
.if eax==0
invoke MessageBox,0,0,0,0
.endif
mov [esi].fLayer.DC,eax
invoke CreateIndependantBitmap,eax,_width,height
mov [esi].fLayer.bmp,eax
invoke SelectObject,[esi].fLayer.DC,[esi].fLayer.bmp
invoke DeleteObject,eax
ret
fNewLayer endp
fDeleteLayer proc uses esi lpLayerStruct:dword
mov esi,lpLayerStruct
invoke DeleteObject,[esi].fLayer.bmp
invoke DeleteDC,[esi].fLayer.DC
ret
fDeleteLayer endp
You can access the frame buffer by using this code.
.data
lpfLayer dd 0
bm BITMAP dd 0
.code
lea ecx,lpfLayer
invoke GetObject,[ecx].fLayer.hBmp,sizeof BITMAP,addr bm
mov eax,bm.bmBits
; Now eax contain the frame buffer address, put the pixel data there.
If you can't access the video ram directly then how do things like DirectX, OpenGl and what I used to use in C++ GDI(Graphics Device Interface) write to it?
Quote from: www.:).com on November 15, 2010, 01:05:15 PM
If you can't access the video ram directly then how do things like DirectX, OpenGl and what I used to use in C++ GDI(Graphics Device Interface) write to it?
Both work as a driver. Only Driver that able to access memory freely, it known as Ring 0 mode or something.
Writing to video memory is a DOS era leftover, you use to write to A000h for VGA and higher up for text mode but you have no access at the video memory in a protected mode operating system like Windows. OpenGL and DirectX simulate screen memory with a surface that you can write to but you have no way to write directly to video memory.
On modern machines the old GDI is reasonably fast but if you are into games or animation you need to use the modern stuff if you are doing much.
ok thanks
In fact, if you're using DirectX and set the "cooperative level" to both EXCLUSIVE and FULLSCREEN, you do have direct access to the video memory in Windows.
:bg
Yes,
Via DirectX. :P
That would be nice to know how to do, so do I just set a window(frame) to full screen and I get direct access to vidmem?
- If so where is the video memory located in memory?
Quote from: www.:).com on November 16, 2010, 01:30:44 PM
That would be nice to know how to do, so do I just set a window(frame) to full screen and I get direct access to vidmem?
- If so where is the video memory located in memory?
After you'd called the IDirectDrawSurface::Lock() function, (part of) the video memory is mapped in the process' address space. The pointer to video memory will be DDSURFACEDESC.lpSurface then.
Quote from: japheth on November 16, 2010, 02:03:33 PM
After you'd called the IDirectDrawSurface::Lock() function, (part of) the video memory is mapped in the process' address space. The pointer to video memory will be DDSURFACEDESC.lpSurface then.
Be careful to also respect the Pitch of the surface ;)
Also be careful because reading from video memory will be very slow since the GPU pipeline does not like it.
Then you can never outperform the video to video Bitblt of the video board hardware in ASM. Practically the video board does it 100 to 1000 times faster when compared to what you can do in ASM via direct video memory access (write only).
For older boards it used to be the case that you could outperform the system to video Bitblt but only by a small margin (approximatively 5%). Today for new boards even this transfer is hardware accelerated and you can not outperform it anymore.
Thanks for your help, and how do I include the IDirectDrawSurface::Lock() function, is it in windows.inc?
Quote from: www.:).com on November 16, 2010, 03:19:17 PM
Thanks for your help, and how do I include the IDirectDrawSurface::Lock() function, is it in windows.inc?
No. Actually, there is no "IDirectDrawSurface::Lock" function. It was an abbreviation of "the Lock() method of the IDirectDrawSurface interface".
Now, before you start asking questions like "What is an interface" and "How do I call this Lock() method" ... , this DirectDraw stuff is not meant for absolute beginners. You'll have to study it ... and perhaps some other APIs as well.
ok I'll do a web search on it, thanks.
Also how would i use bitblt to transfer my buffer to the frame. would it be something like this:
.data
buffer db 64000 dup(0) ; define bytes depending on size of frame
.code
invoke BeginPaint, hWnd, addr st ; st being the paint struct, hWnd being the frame.
invoke bitblt, eax, 0, 0, 320, 200, buffer, 0, 0, SCR_COPY; eax being the return value from Begin Paint -- ??the return value is stored in eax??
got info about bitblt at http://msdn.microsoft.com/en-us/library/dd183370(VS.85).aspx
Quote from: www.:).com on November 16, 2010, 04:59:47 PM
ok I'll do a web search on it, thanks.
Also how would i use bitblt to transfer my buffer to the frame. would it be something like this:
.data
buffer db 64000 dup(0) ; define bytes depending on size of frame
.code
invoke BeginPaint, hWnd, addr st ; st being the paint struct, hWnd being the frame.
invoke bitblt, eax, 0, 0, 320, 200, buffer, 0, 0, SCR_COPY
; eax being the return value from Begin Paint -- ??the return value is stored in eax??
got info about bitblt at http://msdn.microsoft.com/en-us/library/dd183370(VS.85).aspx
No... it is not that GDI kind of BitBlt ...
It will be one of the methods on one of the interfaces of DirectX that you need to learn and study.
IMHO you are way over your head and probably going in the wrong direction anyway.
DirectX is not friendly for ASM users, it only nice to C++ programmers. You better switch to OpenGL.