flat assembler
Message board for the users of flat assembler.

Index > Windows > Screen Buffer.

Author
Thread Post new topic Reply to topic
macgub



Joined: 11 Jan 2006
Posts: 348
Location: Poland
macgub 24 Aug 2011, 12:09
I want make simply screen buffer app in windows. I found on forum how to set single pixel, but how to draw whole image? ( i think about both full screen mode and window mode) I prefer 24 bit color. So I ask how to copy from memory to screen image. I dont want use openGL or directX, just screen buffer. I have no experience programming in windows, so if someone could give simple template example, please....
Post 24 Aug 2011, 12:09
View user's profile Send private message Visit poster's website Reply with quote
AsmGuru62



Joined: 28 Jan 2004
Posts: 1638
Location: Toronto, Canada
AsmGuru62 24 Aug 2011, 12:56
Without Windows experience - it will not be easy.
Windows API provides functions to work with double buffer imaging.
In short, it goes like this:

1. You paint the window in response to WM_PAINT message. By processing the message (BeginPaint API) you get back the Device Context (HDC) to pain onto.

2. You create a second HDC (using CreateCompatibleDC API) - this is your memory buffer where you will draw your data pixels.

3. You create a bitmap object - using CreateCompatibleBitmap API.

4. You select the object created in #3 into object created in #2 using SelectObject API.

5. Perform ALL your drawing operation into object from #2 - in other words: paint into memory.

6. In one call to API BitBlt dump memory buffer into screen buffer. Source is your memory buffer from step #2 - destination is your HDC from step #1.

7. De-select your memory buffer (HBITMAP created in step #3) from your object created in step #2

8. Destroy objects created in #2 and #3

9. Call EndPaint to signal to Windows that drawing is over.

If you are planning to do animation - it is better to create and select objects once to speed up the frame rate.

I know - it sounds confusing, but as I said - without knowing Windows - it is not easy. I was planning to write a sample (a game), but never finished it.

Also: Windows does not allow the direct access to screen memory, like in DOS games - unless you want to create your own driver - which is what DirectX is - it is a driver for Windows, but writing drivers is even more complex than my explanations.
Post 24 Aug 2011, 12:56
View user's profile Send private message Send e-mail Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3175
Location: Denmark
f0dder 24 Aug 2011, 13:41
macgub: either go by the APIs (which would be DirectX for giving you the native lowest practical level of access), or you go write for an OS that gives you direct access.

The only way you'd be certain to get direct framebuffer address on Windows is writing a driver - but that's not something you'd want to do, for several reasons. Even if you ignore all the practical reasons, a pretty damn good one is performance... if you want any of that, you'll be using APIs and not even considering framebuffer access.
Post 24 Aug 2011, 13:41
View user's profile Send private message Visit poster's website Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 24 Aug 2011, 21:48
I use this code... work in many windows
http://code.google.com/p/reda4/source/browse/trunk/screenshot/framebuffer.asm

with many fixes but without example in
http://code.google.com/p/reda4/source/browse/trunk/r4asm/r4fasm.asm

I hope this help
Post 24 Aug 2011, 21:48
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 348
Location: Poland
macgub 26 Aug 2011, 07:52
Thanks guys for your replies. I will try understand code that Pabloreda gave links.
Post 26 Aug 2011, 07:52
View user's profile Send private message Visit poster's website Reply with quote
rain_storm



Joined: 05 Apr 2007
Posts: 67
Location: Ireland
rain_storm 13 Sep 2011, 02:49
Here's what I use, there are a lot of corners cut here, but who cares it works and it is easy to understand.

Code:
const int resx = 640;
const int resy = 480;
int pixel[resx*resy];

int main(void)
{
    static PIXELFORMATDESCRIPTOR pfd = { sizeof(PIXELFORMATDESCRIPTOR),1,PFD_DRAW_TO_WINDOW|PFD_SUPPORT_GDI|PFD_DOUBLEBUFFER,PFD_TYPE_RGBA,0x20,0,0,0,0,0,0,0,0,0,0,0,0,0,0x10,0,0,PFD_MAIN_PLANE,0,0,0,0 };
    static BITMAPINFO bmi = { sizeof(BITMAPINFOHEADER),resx,-resy,1,32 };
    static MSG msg;
    static HWND hwnd;
    static HDC hdc;
    int screenx = GetSystemMetrics(SM_CXSCREEN);
    int screeny = GetSystemMetrics(SM_CYSCREEN);
    if (!(hwnd = CreateWindowEx(0,"edit",0,WS_POPUP|WS_MAXIMIZE|WS_VISIBLE,0,0,0,0,0,0,0,0))) return 0;
    if (!(hdc = GetDC(hwnd))) return 0;
    if (!SetPixelFormat(hdc, ChoosePixelFormat(hdc, &pfd), &pfd)) return 0;
    ShowCursor(FALSE);
    do {
        PeekMessage(&msg,0,0,0,PM_REMOVE);
        StretchDIBits(hdc,0,0,screenx,screeny,0,0,resx,resy,pixel,&bmi,0,SRCCOPY);
        SwapBuffers(hdc);
    } while (msg.message != WM_KEYDOWN);
    ReleaseDC(hwnd, hdc);
    DestroyWindow(hwnd);
    return 0;
}
    
Post 13 Sep 2011, 02:49
View user's profile Send private message Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 22 Sep 2011, 14:23
Thank's rain_storm for sharing, I try to test your code, mine have tearing (because I not use double buffer), perhaps you code work better, Im interesting in the speed too.

I try to make the same framework for win64, linux32 and 64 and others OS too, if anyone have a code for doing this please post...fasm better
Post 22 Sep 2011, 14:23
View user's profile Send private message Visit poster's website Reply with quote
macgub



Joined: 11 Jan 2006
Posts: 348
Location: Poland
macgub 27 Sep 2011, 07:39
Quote:
... if anyone have a code for doing this please post...fasm better

I agree with Pabloreda.
If someone could translate this code to fasm, will be great...And maybye not only main procedure, but whole program. It's only reqest... [/b]
Post 27 Sep 2011, 07:39
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4050
Location: vpcmpistri
bitRAKE 27 Sep 2011, 08:09
I've got several examples on the board already:

http://board.flatassembler.net/topic.php?t=8289 win32 & win64
http://board.flatassembler.net/topic.php?p=118955#118955 timer/thread

...there are others, too.
Post 27 Sep 2011, 08:09
View user's profile Send private message Visit poster's website Reply with quote
pabloreda



Joined: 24 Jan 2007
Posts: 116
Location: Argentina
pabloreda 27 Sep 2011, 12:31
t hanks bitRAKE
the first have, hilbertW.asm and hilbertw64 and the second plot.thread0.asm.
nobody work in asm in Linux?
Post 27 Sep 2011, 12:31
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4050
Location: vpcmpistri
bitRAKE 27 Sep 2011, 16:09
From what I've read it appears OpenGL support on Linux is quite good. So, it might be easiest to work with a single API across all platforms. Of course, such simple Windows applications would work through WINE, afaik. Note: I have almost no Linux programming experience. Is OpenGL required to access frame buffer?
Post 27 Sep 2011, 16:09
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 27 Sep 2011, 23:31
Its hard (or maybe impossible) to get to framebuffer with hardware GL.
Maybe with X11 software implementation it is possible?
Post 27 Sep 2011, 23:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.