/* ====================================================================== $Day: $ (003) $Date: $ $Creator: Emmanuel Vaccaro $ $Notice: (C)Copyright 2014 by Emmanuel Vaccaro. All Rights Reserved. $ ====================================================================== */ Hand made hero Day 003 – Allocating a Backbuffer Step 1). Set up Windows callbacks for Buffer allocation – First, we need to set up a few global variables: global_variable BITMAPINFO BitmapInfo; global_variable void *BitmapMemory; global_variable HBITMAP BitmapHandle; global_variable HDC BitmapDeviceContext; We will need to tell Windows what we want to write onto the buffer that we create. To do this, we need to set up the following code: internal void Win32ResizeDIBSection(int Width, int Height) { if (BitmapHandle) //<-- If BitmapHandle DOES exist { DeleteObject(BitmapHandle); } if (!BitmapDeviceContext) //<-- If BitmapDeviceContext does NOT exist (!) { BitmapDeviceContext = CreateCompatibleDC(0); } BitmapInfo.bmiHeader.biSize = sizeof(BitmapInfo.bmiHeader); //<-- Number of bytes required by ‘bmiHeader’ structure BitmapInfo.bmiHeader.biWidth = Width; //<-- Width of bitmap in pixels BitmapInfo.bmiHeader.biHeight = Height; //<-- Height of bitmap in pixels BitmapInfo.bmiHeader.biPlanes = 1; //<-- Number of planes for device BitmapInfo.bmiHeader.biBitCount = 32; //<-- Number of bits per pixel BitmapInfo.bmiHeader.biCompression = BI_RGB; //<-- Type of bitmap compression //See BitmapInfo: //http://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx BitmapHandle = CreateDIBSection( BitmapDeviceContext, //<-- Handle to device context &BitmapInfo, //<-- Pointer to bitmapinfo structure DIB_RGB_COLORS, //<-- The type of data contained in the bmiColors array member of BITMAPINFO structure &BitmapMemory, //<-- A pointer to a variable that receives a pointer to location of DIB bit values 0, 0); //See CreateBigSection(): //http://msdn.microsoft.com/en-us/library/windows/desktop/dd183494%28v=vs.85%29.aspx }

Next, we’re going to call this method from the ‘Win32MainWindowCallback’ under our ‘switch(Message)’ statement and inside of ‘case WM_SIZE’: case WM_SIZE: { RECT ClientRect; GetClientRect(Window, &ClientRect);

//<-- Creates Rectangle //<-- Obtains the Window’s client dimensions int Width = ClientRect.right - ClientRect.left; //<-- Sets Width int Height = ClientRect.bottom - ClientRect.top; //<-- Sets Height Win32ResizeDIBSection(Width, Height); //<-- Calls our prior function to create buffer OutputDebugStringA("WM_SIZE\n");

} break; Step 2). Updating the Window – Next, we need to specify exactly what we want to do when the Window’s ‘WM_SIZE’ message gets called as well as what we want to do when Updating the window: internal void Win32UpdateWindow(HDC DeviceContext, int X, int Y, int Width, int Height) { StretchDIBits( DeviceContext, //<-- Handle of Device Context X, Y, Width, Height, //<-- To RECT (dest) X, Y, Width, Height, //<-- From RECT (src) BitmapMemory, //<-- The memory allocation of the bitmap specified earlier &BitmapInfo, //<-- The bitmap information we specified earlier DIB_RGB_COLORS, //<-- Specifies how to render colours SRCCOPY); //<-- A raster-operation code } Now we’re going to have to replace some code inside of our ‘Win32MainWindowCallback’ function. Inside our ‘switch(Message)’, replace the ‘case WM_PAINT’ with this: case WM_PAINT: { PAINTSTRUCT Paint; HDC DeviceContext; DeviceContext = BeginPaint(Window, &Paint); int X = Paint.rcPaint.left; int Y = Paint.rcPaint.top; int Width = Paint.rcPaint.right - Paint.rcPaint.left; int Height = Paint.rcPaint.bottom - Paint.rcPaint.top; Win32UpdateWindow(DeviceContext, X, Y, Width, Height); //<-- Our call to Update the window EndPaint(Window, &Paint); } break; Done! The above mentioned code is just the ground work needed to cover Allocating Buffers. Stay tuned for the next stream where we get this all up and running!

HandMade Hero Day 003 - Allocating a Back Buffer (Emmanuel ...

//http://msdn.microsoft.com/en-us/library/windows/desktop/dd183376(v=vs.85).aspx. BitmapHandle = CreateDIBSection(. BitmapDeviceContext, //<-- Handle to ...

113KB Sizes 3 Downloads 203 Views

Recommend Documents

HandMade Hero Day 001 - Setting Up the Windows Build ...
There was a problem previewing this document. Retrying. ... HandMade Hero Day 001 - Setting Up the Windows Build (Emmanuel Vaccaro) .pdf. HandMade ...

emmanuel smith - GitHub
with talented co-workers and utilising dynamic processes. Work History. Jul 2014 - ... Providing consulting on SAP's BusinessObjects software for many clients.

A HERO - School education
Jan 20, 2015 - Spanish is the official language in New Mexico ..... food c. strengthd. dress. Ans.: b. food. 7. It was believed that the three ...... 2. c. an American.

'A Hero'? -
6) Swami had always slept beside his ………… A] Himself. B] Granny C] Mother D] Father. 7) 'It is disgraceful sleeping beside granny or mother like a baby.' Who said this? A] Swami B] Granny C] Mother D] Father. 8) Swami's father sat …….gazi

'A Hero'? -
6) Swami had always slept beside his ………… A] Himself. B] Granny C] Mother D] Father. 7) 'It is disgraceful sleeping beside granny or mother like a baby.' Who said this? A] Swami B] Granny C] Mother D] Father. 8) Swami's father sat …….gazi

A Buffer Overflow Study
This means that when a program is run, the next instruction address is stored in .... When speaking of heap overflow we will regroup heap, bss, and data buffer ...

Allocating Group Housing
Nov 18, 2016 - theme in the matching literature,9 thus it might be expected that this ... To evaluate this claim formally, we add an initial stage to the model in ...

buffer final.pdf
hidrógeno (H+. ) por cada molécula, y una base es una sustancia que libera uno o más iones. hidroxilos (OH-. ) por cada molécula, como uno de los productos ...

2010 - emmanuel carraud.pdf
Why$and$How$to$develop$a$. successful$iPhone$app?$ Emmanuel(Carraud. CEO(MagicSolver.com(. [email protected]. Page 1 of 23 ...

Programme-Emmanuel-Macron.pdf
Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

003.PDF
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. 003.PDF. 003.

Forested Buffer Strips - Davey Tree
which is the basic source of energy for the stream ecosystem .... odologies, see Guide 05 Index of Titles or call the ... contact: ODNR Public Information Center.

Allocating radio resources in mobile communications system
May 21, 2012 - Telecommunications System (E-UMTS) is provided. A pre ... Delay time before the terminal transmits data is reduced and unnecessary ...

Dynamically Allocating the Resources Using Virtual Machines
Abstract-Cloud computing become an emerging technology which will has a significant impact on IT ... with the help of parallel processing using different types of scheduling heuristic. In this paper we realize such ... business software and data are

A Recommendation Framework for Allocating Global Software Teams ...
Global Software Teams in Software Product Line Projects ... deadlines, many companies are adopting Software Product Line ..... predicting future trends [10].

[G229.Ebook] Emmanuel Joseph Sieyes Ecrits Politiques ...
[G229.Ebook] Emmanuel Joseph Sieyes Ecrits Politiq ... ression By Roberto Zapperi Emmanuel Joseph Sieyaes. [G229.Ebook] Emmanuel Joseph Sieyes Ecrits ...

Allocating radio resources in mobile communications system
May 21, 2012 - System information or paging message (810). (56). References Cited. U.S. PATENT DOCUMENTS. 5,659,756 A. 8/1997 Hefferon et a1.

The Cauchy problem at a node with buffer
Nov 29, 2011 - existence and well posedness of solutions to the Cauchy problem, by ..... Definition 6 We say that a wave (ρl,ρr) in an arc is a big shock if ρl < σ

A Joint Relay Selection and Buffer Management ... - IEEE Xplore
Dept. of Computer Science, UCLA. Los Angeles, USA. {tuanle, kalantarian, gerla}@cs.ucla.edu. Abstract—Due to the unstable network topology of Delay.

A DTN Routing and Buffer Management Strategy for ... - IEEE Xplore
Dept. of Computer Science, UCLA. Los Angeles, USA. {tuanle, kalantarian, gerla}@cs.ucla.edu. Abstract—Delay Tolerant Networks (DTNs) are sparse mobile.