News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

writing to frame buffer

Started by www.:).com, November 15, 2010, 12:50:11 AM

Previous topic - Next topic

www.:).com

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.

dedndave

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

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

www.:).com

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?

Farabi

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.
Those who had universe knowledges can control the world by a micro processor.
http://www.wix.com/farabio/firstpage

"Etos siperi elegi"

hutch--

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.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

www.:).com


japheth

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.

hutch--

Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth


www.:).com

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?

japheth

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.






BogdanOntanu

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.
Ambition is a lame excuse for the ones not brave enough to be lazy.
http://www.oby.ro

www.:).com

Thanks for your help, and how do I include the IDirectDrawSurface::Lock() function, is it in windows.inc?

japheth

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.