CSE3AGT Paul Taylor 2010. Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed. Procedure-Driven Programming Event-Driven Programming Events Messages Event Handlers GUI Windows and Multitasking Queues ( System.
Advertisements

DirectInput® 9.0 C. Shane Evans / Bernard George Program Manager DirectX Microsoft ® Corporation.
Computer Graphics1 Windows NT Graphics Interface.
C Structures and Memory Allocation There is no class in C, but we may still want non- homogenous structures –So, we use the struct construct struct for.
GUI Programming Alex Feldmeier.
Cosc 5/4730 Input Keyboard, touch, and Accelerometer.
Events Chapter 7. Interactive Real world is interactive User determines order of actions instead of programmer.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
Mouse-Based Viewing & Navigation Glenn G. Chappell U. of Alaska Fairbanks CS 381 Lecture Notes Monday, November 3, 2003.
Memory management under Windows The Need for Memory:-  The window environment and most applications that run under it need access to phenomenal amounts.
MICROSOFT WORD GETTING STARTED WITH WORD. CONTENTS 1.STARTING THE PROGRAMSTARTING THE PROGRAM 2.BASIC TEXT EDITINGBASIC TEXT EDITING 3.SAVING A DOCUMENTSAVING.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Keyboard In computing, a keyboard is an input device, partially modeled after the typewriter keyboard, which uses an arrangement of buttons or keys, to.
Prepared by Fareeha Lecturer DCS IIUI 1 Windows API.
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
Server Sockets: A server socket listens on a given port Many different clients may be connecting to that port Ideally, you would like a separate file descriptor.
Visual Basic 2005 CHAPTER 2 Program and Graphical User Interface Design.
Chapter 1: Hello, MFC Windows Programming Model Department of Digital Contents Sang Il Park.
Chapter 1: Hello, MFC Your first MFC Application Department of Digital Contents Sang Il Park.
Douglas Boling President Boling Consulting Inc. SESSION CODE: WEM304.
1 Programs Composed of Several Functions Syntax Templates Legal C++ Identifiers Assigning Values to Variables Declaring Named Constants String Concatenation.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
Winsock Programming Blocking and Asynchronous Sockets for Windows.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Chapter 3 The mouse and the Keyboard. Getting input from the Mouse.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
CNS 1410 Graphical User Interfaces. Obectives Students should understand the difference between a procedural program and an Event Driven Program. Students.
1 Copyright © 2004, Oracle. All rights reserved. Introduction to PL/SQL.
CIS 3.5 Lecture 2.2 More programming with "Processing"
Bitmap (Chapter 15).
Chapter2: Drawing a Window. Review: Introducing MFC.
CSE 381 – Advanced Game Programming User Interface & Game Events Management.
Haptic & Direct User Input with DirectInput ® 8 API Graphics Lab. Korea Univ.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Dialog boxes Modal and modeless dialog boxes Displaying about dialog box: case WM_COMMAND : switch (LOWORD (wParam)) { case IDM_APP_ABOUT : DialogBox (hInstance,
Quanta Confidential QUANTA WBU Study Report 1 昭正 2008/08/01.
Microsoft Visual Basic 2010 CHAPTER TWO Program and Graphical User Interface Design.
How to write a MSGQ Transport (MQT) Overview Nov 29, 2005 Todd Mullanix.
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
Introduction to Game Programming Pertemuan 11 Matakuliah: T0944-Game Design and Programming Tahun: 2010.
The WM_NCHITTEST Message  This is an internal message used by Windows for generating all the other mouse messages.  Though it almost never needs to be.
Chapter 16 GPDUMB Engine Part II. 2 GPDUMB2 Engine.
Learning Programming Windows API Morpheus Feb-28, 2008.
Implement User Input Windows Development Fundamentals LESSON 2.4A.
Procedural programming Procedural programming is where you specify the steps required. You do this by making the program in steps. Procedural programming.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
CS 134 Alternate Inputs.
Winter 2009 Tutorial #6 Arrays Part 2, Structures, Debugger
CHAPTER 5 Input Control © 2008 Cengage Learning EMEA.
Windows Programming Lecture 10.
Programming Input Devices
Interfacing.
Windows Programming Lecture 09.
Window.
Windows Programming Model
Basic Troubleshooting Techniques
Game Programming (User Input)
The program in traditional OS
Windows Programming Lecture 12
Keyboard and mouse in Windows API
Windows Programming Lecture 13
HW for Computer Graphics
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/19.
ECE 352 Digital System Fundamentals
GUI Socket Application
Presentation transcript:

CSE3AGT Paul Taylor 2010

Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT (windows error message value)

Some Short Examples ID3D10Texture2D* pBackBuffer; HWND g_hWnd = NULL; HRESULT hr; hr = g_pSwapChain->GetBuffer(...) if( FAILED( hr) )

The Windows Message Pump What do messages do? – Handles Window Messages (Maximise, Minimise, etc) – Handles basic Keyboard and Mouse commands How do you send a message? – SendMessage() or – PostMessage()

What does a message look like? typedef struct { HWND hwnd; // Handle to the procedure that receives the message. UINT message; // Specifies the message identifier. WPARAM wParam; // Specifies additional information about the message. LPARAM lParam; // Specifies additional information about the message. DWORD time; // time at which the message was posted. POINT pt; // Specifies the cursor position when the message was posted. } MSG, *PMSG; Declaration: MSG myMsg; MSDN:

The WM_MOUSEMOVE Message UINT Message = WM_MOUSEMOVE wParam: MK_CONTROL The CTRL key is down. MK_LBUTTON The left mouse button is down. MK_MBUTTON The middle mouse button is down. MK_RBUTTON The right mouse button is down. MK_SHIFT The SHIFT key is down. lParam: The low-order word specifies the x-coordinate of the cursor. The coordinate is relative to the upper- left corner of the client area. The high-order word specifies the y-coordinate of the cursor. The coordinate is relative to the upper- left corner of the client area. xPos = GET_X_LPARAM(lParam); yPos = GET_Y_LPARAM(lParam);

The Basic Windows Message Loop // Program Init while(GetMessage(&Msg, NULL, 0, 0) > 0) { TranslateMessage(&Msg); DispatchMessage(&Msg); Game Code! } // Program Shutdown

Issues for Games GetMessage() will wait until it receives a message to return Messages happen regularly, but not regularly enough for us The solution is PeekMessage()

A Better Message Loop PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE); while (mssg.message!=WM_QUIT) { if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&mssg); DispatchMessage(&mssg); } else { // Game Code! }

The Best Message Loop PeekMessage( &mssg, NULL, 0, 0, PM_NOREMOVE); while (mssg.message!=WM_QUIT) { if (PeekMessage( &mssg, NULL, 0, 0, PM_REMOVE)) { TranslateMessage(&mssg); DispatchMessage(&mssg); } // Game Code! }

>>A Nice Program Flow<< Win32/dx9A4.aspx

XInput = Simple! Comprises only two extra sources – XInput.h – Xinput.lib Main Functions: – XInputGetState – XInputSetState – XInputGetDSoundAudioDeviceGuids

All we can get is the current state How do we detect button presses? Avoiding Multiple Trigger situations?

We store the previous state typedef struct _XINPUT_GAMEPAD { WORD wButtons; BYTE bLeftTrigger; BYTE bRightTrigger; SHORT sThumbLX; SHORT sThumbLY; SHORT sThumbRX; SHORT sThumbRY; } XINPUT_GAMEPAD, *PXINPUT_GAMEPAD;

Direct Input Uses The Common Object Model (COM) – Input Devices – Keyboard, Mouse, Joystick, Force-Feedback Consists of two types of objects: – IDirectInput8 Interface – DirectInputDevice (one for each device) LPDIRECTINPUTDEVICE8 lpdiSomeDevice;

DirectInput Process Overview 1)Create the DirectInput Object 2)Enumerate DirectInput Devices 3)Create Device Object(s) 4)Set up the Device(s) 5)Acquire the Device (Get access to it) 6)Retrieve Data (using access) 7)Use the Data! 8)Release Devices (Un-Acquire then Release) 9)Release DirectInput

Action Mapping Instead of using the specific axis or buttons Abstract the input to a set of ‘Actions’ #define INPUT_LEFTRIGHT_AXIS 1L DIINPUT structures: // Genre Specific Bindings {INPUT_LEFTRIGHT_AXIS, DIAXIS_SPACESIM_LATERAL, 0, "Turn",}, // Programmer Created Mapping {INPUT_TURNLEFT, DIKEYBOARD_LEFT, 0, "Turn left", }, {INPUT_LEFTRIGHT_AXIS, DIMOUSE_XAXIS, 0, "Turn", }, SpaceSim Genre:

Is Action Mapping useful? Pros – Makes multi-device programming more manageable Cons – Takes Effort to set up – Has many Predefined Mappings you may not like Best used only on multi-device games – Otherwise complexity > reward

Descriptors Structures used by API calls for initialisation – You’ve seen a few already. Why are they used? Is there any way to make them easier / quicker to fill out?

MSG example: typedef struct { HWND hwnd; UINT message; WPARAM wParam; LPARAM lParam; DWORD time; POINT pt; } MSG, *PMSG; BOOL PeekMessage( LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax, UINT wRemoveMsg ); But we still have to fill out all those values 

Cheating with DESCRIPTORS Most Descriptors require a LOT of NULL values – This takes ages to fill in by hand. It’s standard to use a block format to set the whole descriptor to null before. Declare the structure: DXGI_SWAP_CHAIN_DESC swapDesc; Wipe it!: ZeroMemory( & swapDesc, sizeof(swapDesc));

News Time! OpenGL 4.0 Spec Released platform-graphics-acceleration-with-op/ Wii Death thought-loaded-gun-was-Wii-controller-in-fatal-accident.html

Resources he_game_loop.htm