News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

I'm not clear on how to do full screen graphics in win32 (XP DirectX).

Started by BlueMR2, September 16, 2014, 11:27:02 PM

Previous topic - Next topic

dedndave

Quote from: Zen on September 19, 2014, 03:44:11 AM
A Device Context is just a data structure. The system uses it to manage the graphic device.

i get that - but it doesn't help a newcomer understand and use it, much

in the movie "The Matrix", they called it "the construct"
as accurate as anything else, still not very helpful - lol

Zen

...I dunno DAVE,...that's about as simple as I can phrase it,...maybe a larger font,...
A DEVICE CONTEXT IS JUST A DATA STRUCTURE.
THE SYSTEM USES IT TO MANAGE THE GRAPHIC DEVICE.

Try this scientific experiment:
Write a GDI application WITHOUT calling: GetDC Function
The GetDC documentation states: The device context is an opaque data structure, whose values are used internally by GDI.
...Here it is in a LARGE font:
The device context is an opaque data structure, whose values are used internally by GDI.


jj2007

Hey, it looks like the Firefox DC occasionally selects the wrong font ::)

Zen

What is a DC?
A Device Context (DC) is core of the GDI (Graphics Device Interface), Windows' graphics library. Behind the scenes the DC is the interface between our applications and the output hardware, however when developing with them we rarely see this aspect and can just think of them as a holder for various drawing objects and properties. As its name suggests, a DC puts all the objects it contains in the context of a specific device which and will work out how to format those objects to be compatible and efficient with the desired device. A DC also stores information about the device it's bound too and what it's capable or rendering, as well as holding various properties that can affect the outcome of various drawing routines.

What Is a Device Context?
The context of a device is the current state of the device hardware. The device driver manages the device context for a process on behalf of the process. The driver must maintain a separate device context for each process that accesses the device. The device driver has the responsibility to restore the correct device context when a process accesses the device.

Really,...what Is a Device Context ???
A device context is a Windows data structure containing information about the drawing attributes of a device such as a display or a printer. All drawing calls are made through a device-context object, which encapsulates the Windows APIs for drawing lines, shapes, and text. Device contexts allow device-independent drawing in Windows. Device contexts can be used to draw to the screen, to the printer, or to a metafile.

This is my personal favorite Device Context function: GetDeviceCaps Function
...Try it,...it's Fun,...it's Informative,...

...By the way,...you can probably GOOGLE just as well as I can,...

Siekmanski

Creative coders use backward thinking techniques as a strategy.

Zen

...It's entirely possible that I skipped my Med,...and went straight to FULL_BLOWN anxiety,...


Gunther

You have to know the facts before you can distort them.

hutch--


TouEnMasm

Fa is a musical note to play with CL

dedndave


Zen

...Ha,...ha,...ha,...
This is what I love about the MASM Forum is that everybody is so dang FUNNY (except, ONAN,...of course,...).
...By the way,...the zen dog (above) obviously has been extensively Photoshopped,...
...He originally was a naked picture of Lindsay Lohan,...

...And, DAVE !!!
Quote from: ...but, Zen - what's a DC ?

...OK,...OK,...if I reveal the BIG SECRET ABOUT DEVICE CONTEXTS (DCs),...will ya quite trying to demolish my brain with yer diabolical Jedi Mind Tricks,...??? OK,...

...If I recall correctly (from Feng Yuan's, Windows Graphics Programming, 2000) there are several HUGE Data Structures maintained in kernel mode address space that GDI secretly uses for validating graphics operations. I wish I still had my old copy of his book, I'd post all the pertinent information. Feng Yuan is alot smarter than I am. But, how the heck did he figure it out,...since all the kernel-mode stuff is OFFICIALLY undocumented ??? Incredibly, he used the kernel-mode debugger (which is included in the old Microsoft Windows Driver Development Kit, DDK),...he somehow found a command that displayed the secret kernel-mode data structures (they had different names,...of course), and noted that many of the fields and values were exactly the same as the fields and values in a GDI Device Context (DC). This was the era of Windows 2000,...so, I don't know if it is still a valid explanation,... 
...But, the REALLY cool aspect of this explanation is that the data is part of a KERNEL-MODE COMPONENT,...which means that the average assembly programmer can neither read nor write to that address. SO,...YOU'LL NEVER REALLY KNOW !!!
SO,...HAH !!!
...But,...I'm thinking,...maybe, we can trick QWORD into figuring it out for us,...
...But, once he realizes he's been savagely duped...he will be mad at us,...and probably seek a terrible revenge,...
...Using QWORD's brain remotely is pretty much like cheating, though,...so, I'd be feeling a little guilty,...

guga

You mean....this ?

http://blogs.msdn.com/b/fyuan/archive/2007/03/20/source-code-for-windows-graphics-programming-win32-gdi-and-directdraw.aspx
http://www.fengyuan.com/readme.html

At google you may find it. I removed the previously direct links to avoid Copyright infringement.
https://www.google.com.br/search?q=%22Windows+Graphics+Programming%22+Win32+GDI+and+DirectDraw+download&newwindow=1&client=firefox-a&hs=DOi&rls=org.mozilla:en-US:official&channel=sb&biw=1920&bih=956&ei=ff8fVLufGYvksATzroLwCA&start=10&sa=N

:t


With the help of the GDI kernel extension, we will examine the GDI objects' kernel data structures.

Device Context in the GDI Engine
The device context is a major GDI object which holds lots of settings for the Win32 API to interact with a graphics device, whether a display card, a printer, a plotter, or an image setter. The GDI stores data for a device context in two places. There is a user mode structure, named DC_ATTR, which stores settings like current pen, current brush, background and foreground color. DC_ATTR structure is shown in Section 4.3. The GDI engine also keeps a structure, DCOBJ, in kernel mode address space which holds complete information for a device context object, including a duplicate of DC_ATTR. For a device context handle, the pKernel field in its GDI object-table entry points to an instance of DCOBJ, while the pUser field points to an instance of DC_ATTR.


// dcobj.h

// Windows 2000, 440(0x1B8) bytes
typedef struct
{
  HPALETTE        hpal;
  void *          ppal;
  void *          pColorSpace;
  unsigned        lIcmMode;
  unsigned        lSaveDepth;
  unsigned        unk1_00000000;
  HGDIOBJ         hdcSave;
  unsigned        unk2_00000000[2];
  void *          pbrFill;
  void *          pbrLine;
  void *          unk3_e1a28d88;
  HGDIOBJ         hpath;      // HPATH
  unsigned        flPath;     // PathFlags
  LINEATTRS       lapath;     // 0x20 bytes
  void *          prgnClip;
  void *          prgnMeta;
  COLORADJUSTMENT ca;         // 0x18 bytes
  unsigned        flFontState;
  unsigned        ufi;
  unsigned        unk4_00000000[12];
  unsigned        fl;
  unsigned        flbrush;
  MATRIX          mxWorldToDevice;
  MATRIX          mxDeviceToWorld;
  MATRIX          mxWorldToPage;
  FLOATOBJ        efM11PtoD;
  FLOATOBJ        efM22PtoD;
  FLOATOBJ        efDxPtoD;
  FLOATOBJ        efDyPtoD;
  FLOATOBJ        efM11_TWIPS;
  FLOATOBJ        efM22_TWIPS;
  FLOATOBJ        efPr11;
  FLOATOBJ        efPr22;
  void *          pSurface;
  SIZE            sizl;
} DCLEVEL;

// Windows 2000, 1548(0x60C) bytes
typedef struct
{
  HGDIOBJ     hHmgr;          // 000
  void *      pEntry;         // 004
  ULONG       cExcLock;       // 008
  ULONG       Tid;            // 00c

  DHPDEV      dhpdev;         // 0x010
  unsigned    dctype;
  unsigned    fs;             // Flags
  void *      ppdev;
  void *      hsem;           // 0x020
  unsigned    flGraphics;
  unsigned    flGraphics2;
  void *      pdcattr;        //       point to user mode DCATTR
  DCLEVEL     dcLevel;        // 0x030 0x1B8(440) bytes
  DC_ATTR     dcAttr;         //       0x1C8(456) bytes
  unsigned    hdcNext;        // 0x3B0
  unsigned    hdcPrev;
  RECTL       erclClip;
  unsigned    unk4_00000000[2];
  RECTL       erclWindow;
  RECTL       erclBounds;
  unsigned    unk5_00000000[4];
  void *      prgnAPI;
  void *      prgnVis;
  void *      prgnRao;
  POINT       FillOrigin;
  unsigned    unk6_00000000[10];
  void *      pca1;           // point to DCLEVEL.ca
  unsigned    unk7_00000000[20];
  void *      pca2;
  unsigned    unk8_00000000[20];
  void *      pca3;
  unsigned    unk9_00000000[20];
  void *      pca4;
  unsigned    unka_00000000[10];
  HFONT       hlfntCur;
  unsigned    unkb_00000000[2];
  void *      prfnt;
  unsigned    unkc_00000000[33];
  unsigned    unkd_0000ffff;
  unsigned    unke_ffffffff;
  unsigned    unkf_00000000[3];
} DCOBJ;




QuoteBut, how the heck did he figure it out,...since all the kernel-mode stuff is OFFICIALLY undocumented ???
Take a look at the source of winNT, Win2K, and WinXP research kernel. The full source code of windows are available on google. Although some structure are not "officially" documented, inside the source code there are comments from where you can help to understand what it is and, therefore, make your own documentation of it.
This is probably how he did it. He got the leaked source code of windows2000 and read it.

Btw....A DC is just an acronym for Dude !! where´s my Car ?  :greensml: :greensml: :greensml:



ZOLTAN !!!
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

qWord

"Windows Graphics Programming: Win32 GDI and DirectDraw" - $174 at amazon, but for free at masmforum?
guga, what is your excuse this time? You may be fair and sign such posts with your real name!
MREAL macros - when you need floating point arithmetic while assembling!

guga

Guga is my real nickname (gustavo is my name ;) ). But...i´m not posting the file here. Just tried to help him with the link from where he can get back at least a ebook version (including the author´s website to get the sources examples). Just a matter of google to find.

U$ 174 ??? I found it for U$ 74,67 http://www.amazon.com/Windows-Graphics-Programming-Hewlett-Packard-Professional/dp/0130869856

£ 49.65 http://www.abebooks.co.uk/Windows-Graphics-Programming-Win32-GDI-DirectDraw/12497242980/bd

The ebook version is not updated, btw.

Sorry about the links, i didn´t meant to break any forum rules, but...personally, i don´t think that even if a few guys dl an ebook (that will be read from once and a while on a couple of pages for their own routines) will avoid the printed book to be sold anyway. Specially, if you consider that the ebook is outdated. We are talking on an universe of 10 or 20 thousand printed book (and sold), against, let´s say, 30 downloads of an outdated ebook version. In general, people who dl an ebook read specific pages for specific routines they are building, whereas, people who buy an book, intends to read it completely (to teach or study at school for example)

I´ll avoid post links if it will break any forum rules, but...i really don´t think that the usage of an ebook is the same as an book you buy on a store. I mean this is 2 different kind of  public. I believe that people who is used to dl is not, at all, the same public that is used to buy an book. Specially because when dl an ebook, people, in general do it for a specific purpose at that time they dl it, and then discard the ebook, deleting the file etc once he have the answer he needs...People who buy a book, have other usage.
Even knowing that it violates Copyright, i´m not entirely against this sort of dls. An ebook is not an DVD, and for example, if you copy a book and give to your friends, IMHO is the best and free way to promote the printed and original version and increase the sells.
Coding in Assembly requires a mix of:
80% of brain, passion, intuition, creativity
10% of programming skills
10% of alcoholic levels in your blood.

My Code Sites:
http://rosasm.freeforums.org
http://winasm.tripod.com

qWord

Quote from: guga on September 22, 2014, 10:38:16 PMI´ll avoid post links if it will break any forum rules, but...i really don´t think that the usage of an ebook is the same as an book you buy on a store. I mean this is 2 different kind of  public. I believe that people who is used to dl is not, at all, the same public that is used to buy an book. [...]People who buy a book, have other usage.
Even knowing that it violates Copyright, i´m not entirely against this sort of dls.
So, because it not a problem for you (no real name nor address), it is also OK for the forum owner? Who will be contacted by lawyers?
MREAL macros - when you need floating point arithmetic while assembling!