Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals.

Slides:



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

1 Windows Programming CIS 577 Bruce R. Maxim UM-Dearborn.
Computer Graphics1 Windows NT Graphics Interface.
 Use the Left and Right arrow keys or the Page Up and Page Down keys to move between the pages. You can also click on the pages to move forward.  To.
QT – Introduction C++ GUI Programming with Qt 4 Blanchette and Summerfield, Ch. 1 Miller, 2004.
Introduction to Windows Programming. First Windows Program This program simply displays a blank window. The following code is the minimum necessary to.
IN-LAB # 1 - GETTING STARTED - BUT FIRST: 1.Project ideas - watch the scope!!! 2.Check accounts 3. Either myself or the TA need to check you off BEFORE.
Simple Gui in C++. Project Selecting So Far Registering the window class Creating the window.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
First Windows Program Hello Windows. 2 HELLOWIN.C #include LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ; int WINAPI WinMain (HINSTANCE hInstance,
Intro to Windows Programming Basic Ideas. Program Entry Point Int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
Building a Win32API Application Raw access to the API.
Windows Programming Basic & OpengGL Under Win32 戴明仁
GVE, Hallym University, Song, Chang Geun, Ph.D. 컴퓨터 그래픽스 응용 한림대학교 컴퓨터공학부 송 창근.
Win32 API Programming Event-driven, graphics oriented Example: User clicks mouse over a program’s window area (an event) -- – Windows decodes HW signals.
Further Programming for 3D applications CE Introduction to Further Programming for 3D application Bob Hobbs Faculty of Computing, Engineering 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.
Getting Started The structure of a simple wxWidgets program, Look at where and how a wxWidgets application starts and ends, how to show the main window,
Overview of Previous Lesson(s) Over View  Visual C++ provides us with 3 basic ways of creating an interactive Windows application  Using the Windows.
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.
QT – Introduction C++ GUI Programming with Qt 4
Server Core is the preferred deployment configuration.
CSE3AGT Paul Taylor Stupid Conventions! l = Long p = Pointer h = handle g = global wnd = Windows WM = Windows Message d3d = Direct3D hr = HRESULT.
Further games and graphics concepts COSE50581 Introduction to Module and Recap Bob Hobbs Faculty of Computing, Engineering and Technology Staffordshire.
BZUPAGES.COM Visual Programming Lecture – 2 Miss. SADAF MAJEED SIAL Computer Science Department Bahauddin Zakariya University Multan.
CS350 – Windows Programming Formerly and more properly named: Event Driven Programming Dr. Randy Ribler.
RIGHT Mouse Button Formatting Cut Copy Paste Save LEFT Mouse Button MAIN BUTTON Single clicks Double clicks Drag Highlight.
GAM666 – Introduction To Game Programming You must use special libraries (aka APIs – application programming interfaces) to make something other than a.
Menu Messages  Besides the all-important WM_COMMAND message, window provides five other messages at various stages of menu selection:  WM_SYSCOMMAND.
Lecture 7 Menu, controls, scroll bars. Menu Menu item sends WM_COMMAND message to the application window Menu is attached to window when the window is.
GUI-Based Programming ECE 417/617: Elements of Software Engineering Stan Birchfield Clemson University.
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.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
Programming Input Devices. Getting the device state Schemes for processing input – Polling – Callbacks Ways to intercept messages from input devices –
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.
Menus  Menus is a feature which is common to almost every windows applications. It is the one of the most common user interface elements around.  Windows.
Introduction to OpenGL
Learning Programming Windows API Morpheus Feb-28, 2008.
Overview of Previous Lesson(s) Over View  Windows Programming  WinMain()  Where execution of the program begins and basic program initialization is.
Our good old first Win32 programme of lecture 8 #include int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
W indows Programming Lecture 08. Brief History of Win Windows is announced 1984 Work begins on Word for Windows 1.0 November 1985: Windows 1.0.
Lecture 8: Discussion of papers OpenGL programming Lecturer: Simon Winberg Attribution-ShareAlike 4.0 International (CC BY-SA 4.0)
Windows Programming Lecture 14. WM_PAINT message Whenever an application receives the WM_PAINT message, whether the entire window needs repainting? WM_PAINT.
Windows Programming Lecture 11
Windows Programming Lecture 10.
Visual Programming Lecture 1 & 2
Windows Programming Lecture 09.
Window.
Building a Win32API Application
18 & 19.
Chapter 1 Hello, MFC.
Windows Programming Model
Aspect-Oriented Programming
Windows Desktop Applications
Event Driven Programming
Windows Programming using Dev C++
Queued and Nonqueued Messages
The program in traditional OS
Windows Programming Lecture 12
Windows Programming Lecture 13
Building a Win32API Application
CS 1253 Visual Programming Unit I Windows Environment
Windows Programming Lecture 15
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/10.
Graphics Laboratory Korea University
Windows Development Dynadata Copyright, 2014 © DynaData S.A. 1/19.
GUI Socket Application
Presentation transcript:

Direct3D Workshop November 17, 2005 Workshop by Geoff Cagle Presented by Players 2 Professionals

Workshop Breakdown ► Part 1: Graphics Pipeline ► Part 2: Projection Space ► Part 3: Windows Programming ► Intermission ► Part 4: Setting Up Direct3D ► Part 5: Using Direct3D

Notes and Code Samples ► You can download these notes and all the code samples from

Part 3 Windows Programming

code1.cpp ► This part of the workshop is basically a big explanation for code1.cpp which creates a window. ► You may find it helpful to look at code1.cpp as you go through the slides.

What is a “window?” ► The most obvious windows are the application windows on your desktop. ► The term “window” also refers to any child window or control (such as a button) within a window. ► Windows are organized in a hierarchy.

Example - Calculator

Event Driven Programming ► Windows programming is event driven. ► An event driven program sits and waits for an event to process. ► Events include moving or sizing a window, clicking the mouse button over a window, or typing keys on the keyboard. ► Windows programs are notified of events by messages sent from the OS.

Win32 API ► We will use the Win32 Platform API to write a windows program.  Typically more tedious, but we only need to create one window.  Faster and Smaller executable.  Written in C. ► Other options include:  MFC, Qt, wxWindows, SDL,.NET Forms

WinMain ► Instead of main, windows programs use WinMain ► WinMain has different parameters:  HINSTANCE hInstance – a handle to the program  HINSTANCE hPrevInstance – no longer used.  LPSTR lpCmdLine – unparsed command line. Doesn’t include executable’s filename.  int nCmdShow – Specifies how the window should be initially shown (ie. Minimized, Maximized, Normal) ► WinMain must have a WINAPI modifier.  int WINAPI WinMain (…) ► WinMain still returns an integer like main.

Headers ► To use the Win32 API we need to #include windows.h ► If we #define WIN32_LEAN_AND_MEAN before #including windows.h, the compiler will skip compiling the more rarely used windows code.

Windows Program Outline ► Create Window Class ► Create Window ► Show the Window ► Enter Message Loop

Window Classes ► A window class acts as a template for window creation. ► Window classes are not classes in the C++ sense. ► We can set such properties as:  Name of the window class – important for identifying it later!  Window style – How it looks and its default behaviors.  Window procedure – a pointer to function that handles messages for a window.  Default cursor, icon, and menu.

Creating a Window Class ► Fill out a WNDCLASS or WNDCLASSEX structure. ► Use the structure to register the class with a call to RegisterClass or RegisterClassEx, respectively.

Create the Window ► Create a Window with a call to CreateWindow or CreateWindowEx. ► Some of the parameters you will need to enter include:  The name of a window class.  The name of the window.  A handle to a parent window. ( NULL if no parent)  Initial size and position of the window. ► CreateWindow and CreateWindowEx will return a window handle ( HWND ) if successful or NULL if failed.

Showing the Window ► When we create a window it starts off hidden. ► To show the window you must call ShowWindow (hWnd, nCmdShow)  hWnd – returned from CreateWindow / Ex.  nCmdShow – parameter from WinMain.  This will send a message to the window telling it to show. ► Call UpdateWindow (hWnd) to force the window to process the show message immediately.

Message Loops ► A message loop is needed to forward messages to their windows. ► There are different ways to make a message loop but here is the most common one: MSG msg = {0}; // returns FALSE when message is WM_QUIT while (GetMessage (&msg, NULL, 0, 0)) { TranslateMessage (&msg); // translate keyboard messages. DispatchMessage (&msg); // send message to its window. }

Message Loop (Cont’d) ► The loop uses:  A MSG structure – Holds message information.  GetMessage – Retrieves the next message. Waits for a message if the message queue is empty.  TranslateMessage – Translate some keyboard messages.  DispatchMessage – Dispatches the message to the appropriate windows procedure.

Windows Procedure ► Every window has an associate procedure for handling messages. ► Windows procedures have the following format:  LRESULT CALLBACK ProcName (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp);

Window Procedure Example ► Here is an example procedure: LRESULT CALLBACK WndProc (HWND hwnd, UINT msg, WPARAM wp, LPARAM lp) { switch (msg) { case WM_DESTROY: PostQuitMessage (0); return 0; } return DefWindowProc (hwnd, msg, wp, lp); }

Window Procedure Parameters ► The procedure has 4 parameters:  HWND hwnd – handle to the window receiving the message. This is useful when multiple windows share the same procedure. You can think of it sort of like a this pointer.  UINT msg – The message.  WPARAM wp and LPARAM lp – These are parameters to the message and may represent different things.

Window Procedure Return ► When the procedure completely handles a message, it should return 0. ► The procedure should let the OS handle all other messages by calling DefWindowProc and then return its result.

WM_DESTROY and WM_QUIT ► For this workshop we only want to handle one message: WM_DESTROY.  This message is called when a window is closed.  Note that just because the window is destroyed, the program will still run.  To end the program we send WM_QUIT by calling PostQuitMessage.

WM_* ► Other messages you may want to handle include:  WM_CREATE  WM_SIZE  WM_LBUTTONDOWN  WM_LBUTTONUP  WM_MOUSEMOVE  WM_KEYDOWN  WM_KEYUP ► Check MSDN literature for information about these messages:

Code1.cpp ► This completes Part 3 of the workshop. ► To see how this all works check out code1.cpp, included with this workshop.

Make sure you select Win32 Project.

Make sure you create an empty project.

Code1.exe in Action

References 1. Programming Windows 5 th Edition by Charles Petzold. The definitive guide to Win32 API Programming. 2. MSDN’s Win32 API Reference: asp?url=/library/en- us/winprog/winprog/windows_api_start_p age.asp asp?url=/library/en- us/winprog/winprog/windows_api_start_p age.asp asp?url=/library/en- us/winprog/winprog/windows_api_start_p age.asp