flat assembler
Message board for the users of flat assembler.

flat assembler > High Level Languages > [solved]learning directdraw

Author
Thread Post new topic Reply to topic
vivik



Joined: 29 Oct 2016
Posts: 428
I will ask all directdraw related questions here.

Don't get how clippers work in directdraw windowed mode. When I draw a surface, if even one pixel of it is outside the screen, nothing gets drawn.

This is how I initialize everything:

Code:
                // Create the clipper using the DirectDraw object
                res = g_pDD->CreateClipper(0, &g_pClipper, NULL);
                if (DDFailedCheck(res, "Create clipper"))
                        FUCK();
                
                // Assign your window's HWND to the clipper
                res = g_pClipper->SetHWnd(0, g_hwnd);
                if (DDFailedCheck(res, "Assign hWnd to clipper"))
                        FUCK();
                
                // Attach the clipper to the primary surface
                res = g_pDDS->SetClipper(g_pClipper);
                if (DDFailedCheck(res, "Set clipper"))
                        FUCK();    


And this is how I draw:

Code:
        int off_y = 200;

        RECT where;
        where.left = 0;
        where.top = 0 + off_y;
        where.right = g_image_w;
        where.bottom = g_image_h + off_y;

        g_pDDSBack->Blt(&where, g_pDDS_image, NULL, DDBLT_WAIT, NULL);    


BltFast doesn't work either:

Code:
        g_pDDSBack->BltFast(0, 200, g_pDDS_image, NULL, DDBLTFAST_NOCOLORKEY);    


Last edited by vivik on 03 Apr 2018, 17:36; edited 1 time in total
Post 03 Apr 2018, 07:46
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 428
Got it working. Just added the same clipper to the backbuffer as well. BltFast doesn't work, but Blt works.
Post 03 Apr 2018, 17:36
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 428
Not a question, just wanted to say. DirectDraw reacted very weirdly to trying to draw beyond the borders of the window. I tried to draw image of width 60 to rect [-60...0] or [-60...-1], that is just to the left of window border, and it lagged, and after a while screen went black for a few seconds. And after that, explorer didn't run, could only see mouse. Alt-tab and windows key didn't work, but ctrl-shift-escape and ctrl-alt-delete did. Also, ctrl-alt-del, closing session and reopening it actually caused bsod

Probably just a buggy driver.

Also, don't try to draw without Sleep(1); at the end, it draws too fast to notice, only 1/7 of frames actually get visible. I know there are other ways to do delay, Sleep works fine for me for now. Need to measure fps somehow though.

I need examples of games/programs that use directdraw. Or games for windows in general.
Post 10 May 2018, 16:34
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 428
A bit about fps and tearing.

I'm lucky to own a computer with a fried videocard, gdi and directdraw based games still work fine on it, as long as you play in windowed mode or in a small enough screen resolution. I guess I'll just keep it for visual novels and emulators.

Bejeweled 2 Deluxe still works fine, even shows 90 fps most of the time. I saw hidden depths in this game, I learned that they use both directdraw and direct3d8 (or 7?) for this game depending on what computer it's run on. Graphics are even slightly different for both versions, title screen and level transition effects. I actually downloaded and compiled (!!!) popcap framework, there is some good info in the documents.

Can't avoid tearing though, all methods fail, directdraw->GetMonitorFrequency, directdraw->WaitForVerticalBlank, directdraw->GetScanLine. They work on a working computer, but not on that one. Maybe I can assume that frequency is 75 hertz, and just use timers, manually...

http://www.sega-16.com/forum/showthread.php?29176-DirectDraw-Tearing

https://www.codeproject.com/Articles/4436/Tearing-free-drawing-with-GDI

http://www.virtualdub.org/blog/pivot/entry.php?id=74
Post 29 Jun 2018, 20:07
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 428
I'm not sure if directdraw is any better than gdi in this scenario, the "no hardware acceleration" case. I guess it's slightly better, since you can actually lock a surface and access the raw data in it. With gdi, you need to construct .bmp file in memory first, obliviously not efficient. I even made a thread about this before somewhere.

You still need gdi for rendering text though. You may use bitmap fonts in some cases, but chinese has to use the os provided fonts, simply due to it's size. TrueType font rendering is a surprisingly complicated matter.

One thing I noticed, some games display very rough, pixelarted text when you scroll through it fast (AIR for example), but show properly smoothed text with shadow under it when it stays. I'm curious how they keep resources, because game lags for a few seconds when a new image loads.

They are also clever with transitions. They try to not update the whole screen at the same time, they fade left part of the screen to black, middle part, right part. They probably use dirty rects here too. I'm not sure if you can use dirty rects in directdraw, I know it has clipper lists, but it's probably different. Also, how can I see if half of a window is closed by some other window, and I need to render only half of what I usually render. The latter is most likely impossible.

I hope to make a few games for Kolibri os, doubt they have drivers for videocards and such. Doubt I'll ever do that though.

About directdraw text editor, I guess I'll have 1 frontbuffer and 2 or 3 backbuffers. I'll render the entire screen in one backbuffer, and prerender the screen above and the screen below. In cases where I scroll too fast, I'll render only 1 backbuffer.
Post 29 Jun 2018, 20:43
View user's profile Send private message Reply with quote
vivik



Joined: 29 Oct 2016
Posts: 428
I need to find out if i can make scrolling faster. Directdraw is fast enough when run in a small window, but for larger windows the delay is noticeable. For cases when only part of the window needs redrawing, i probably can just redraw that part of the screen and that's it.

directdraw + dirty rects, how?
Post 30 Aug 2018, 19:33
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-2018, Tomasz Grysztar.

Powered by rwasa.