Windows Programming with MFC. Computer Graphics Hardware. Computer Graphics. Binghamton University. EngiNet. Thomas J. Watson

Similar documents
Types of CRT Display Devices. DVST-Direct View Storage Tube

Comp 410/510. Computer Graphics Spring Introduction to Graphics Systems

Computer Graphics: Overview of Graphics Systems

Part 1: Introduction to Computer Graphics

Computer Graphics. Introduction

2.2. VIDEO DISPLAY DEVICES

Part 1: Introduction to computer graphics 1. Describe Each of the following: a. Computer Graphics. b. Computer Graphics API. c. CG s can be used in

CMPE 466 COMPUTER GRAPHICS

Reading. 1. Displays and framebuffers. History. Modern graphics systems. Required

Reading. Displays and framebuffers. Modern graphics systems. History. Required. Angel, section 1.2, chapter 2 through 2.5. Related

Introduction to Computer Graphics

3. Displays and framebuffers

Downloads from:

Displays. History. Cathode ray tubes (CRTs) Modern graphics systems. CSE 457, Autumn 2003 Graphics. » Whirlwind Computer - MIT, 1950

Objectives: Topics covered: Basic terminology Important Definitions Display Processor Raster and Vector Graphics Coordinate Systems Graphics Standards

Reading. Display Devices. Light Gathering. The human retina

Overview of Graphics Systems

PTIK UNNES. Lecture 02. Conceptual Model for Computer Graphics and Graphics Hardware Issues

1. Introduction. 1.1 Graphics Areas. Modeling: building specification of shape and appearance properties that can be stored in computer

Computer Graphics : Unit - I

CS2401-COMPUTER GRAPHICS QUESTION BANK

These are used for producing a narrow and sharply focus beam of electrons.

Computer Graphics Prof. Sukhendu Das Dept. of Computer Science and Engineering Indian Institute of Technology, Madras Lecture - 5 CRT Display Devices

MODULE I MCA COMPUTER GRAPHICS ADMN APPLICATIONS OF COMPUTER GRAPHICS

Computer Graphics. Raster Scan Display System, Rasterization, Refresh Rate, Video Basics and Scan Conversion

Monitor and Display Adapters UNIT 4

CS 4451A: Computer Graphics. Why Computer Graphics?

Lecture 14: Computer Peripherals

Computer Graphics Hardware

Computer Graphics NV1 (1DT383) Computer Graphics (1TT180) Cary Laxer, Ph.D. Visiting Lecturer

iii Table of Contents

Display Devices & its Interfacing

Display Technologies CMSC 435. Slides based on Dr. Luebke s slides

Manual Version Ver 1.0

UNIT 1 INTRODUCTION TO COMPUTER

Hitachi Europe Ltd. ISSUE : app084/1.0 APPLICATION NOTE DATE : 28/04/99

Design of VGA Controller using VHDL for LCD Display using FPGA

Graphics Concepts. David Cairns

A+ Certification Guide. Chapter 7 Video

TV Character Generator

7thSense Design Delta Media Server

TechNote: MuraTool CA: 1 2/9/00. Figure 1: High contrast fringe ring mura on a microdisplay

Lab Determining the Screen Resolution of a Computer

Start with some basics: display devices

High Performance Raster Scan Displays

Module 7. Video and Purchasing Components

LA1500R USER S GUIDE.

VGA Port. Chapter 5. Pin 5 Pin 10. Pin 1. Pin 6. Pin 11. Pin 15. DB15 VGA Connector (front view) DB15 Connector. Red (R12) Green (T12) Blue (R11)

Display Systems. Viewing Images Rochester Institute of Technology

2.4.1 Graphics. Graphics Principles: Example Screen Format IMAGE REPRESNTATION

Chapter 3. Display Devices and Interfacing

ME EN 363 ELEMENTARY INSTRUMENTATION Lab: Basic Lab Instruments and Data Acquisition

USB Mini Spectrum Analyzer User Manual TSA Program for PC TSA4G1 TSA6G1 TSA8G1

15 Inch CGA EGA VGA to XGA LCD Wide Viewing Angle Panel ID# 833

E X P E R I M E N T 1

B. TECH. VI SEM. I MID TERM EXAMINATION 2018

Technology White Paper Plasma Displays. NEC Technologies Visual Systems Division

USB Mini Spectrum Analyzer User Manual PC program TSA For TSA5G35 TSA4G1 TSA6G1 TSA12G5

Designing Custom DVD Menus: Part I By Craig Elliott Hanna Manager, The Authoring House at Disc Makers

Dektak Step by Step Instructions:

KRAMER ELECTRONICS LTD. USER MANUAL

1 Your computer screen

General Items: Reading Materials: Miscellaneous: Lecture 8 / Chapter 6 COSC1300/ITSC 1401/BCIS /19/2004. Tests? Questions? Anything?

GONBES Technology Co.,Ltd

VARIOUS DISPLAY TECHNOLOGIESS

Lab experience 1: Introduction to LabView

Introduction...2. Features...2 Safety Precautions...2. Installation...4

Lecture Flat Panel Display Devices

ivw-fd122 Video Wall Controller MODEL: ivw-fd122 Video Wall Controller Supports 2 x 2 Video Wall Array User Manual Page i Rev. 1.

VIDEO 101 LCD MONITOR OVERVIEW

S op o e p C on o t n rol o s L arni n n i g n g O bj b e j ctiv i e v s

HyperMedia User Manual

Understanding Multimedia - Basics

AC335A. VGA-Video Ultimate Plus BLACK BOX Back Panel View. Remote Control. Side View MOUSE DC IN OVERLAY

L14 - Video. L14: Spring 2005 Introductory Digital Systems Laboratory

ivw-ud322 / ivw-ud322f

Linkage 3.6. User s Guide

Stimulus presentation using Matlab and Visage

User Manual. Multi-Screen Splicing Processor J6

Design and Implementation of an AHB VGA Peripheral

USB Mini Spectrum Analyzer User s Guide TSA5G35

12.1 Inch CGA EGA VGA SVGA LCD Panel - ID #492

D-ILA PROJECTOR DLA-G15 DLA-S15

decodes it along with the normal intensity signal, to determine how to modulate the three colour beams.

Video Scaler Pro with RS-232

LedSet User s Manual V Official website: 1 /

Setting Up the Warp System File: Warp Theater Set-up.doc 25 MAY 04

Module 1: Digital Video Signal Processing Lecture 3: Characterisation of Video raster, Parameters of Analog TV systems, Signal bandwidth

INTERLACE CHARACTER EDITOR (ICE) Programmed by Bobby Clark. Version 1.0 for the ABBUC Software Contest 2011

SIDRA INTERSECTION 8.0 UPDATE HISTORY

PROFESSIONAL D-ILA PROJECTOR DLA-G11

PROFESSIONAL D-ILA PROJECTOR DLA-G11

Project Title. SPANA Development of Multimedia Tool for Learning Speech. Analysis. Supervisor: Dr. M.W. Mak

Scan Converter Installation Guide

HD-A60X Series Asynchronous-Synchronous operate manual

HyperMedia Software User Manual

IMS B007 A transputer based graphics board

J6 User Manual. User Manual. Multi-Screen Splicing Processor J6. Xi an NovaStar Tech Co., Ltd. Rev1.0.1 NS

ENERGY STAR Program Requirements Product Specification for Televisions. Eligibility Criteria Version 5.3

Lab 1 Introduction to the Software Development Environment and Signal Sampling

Transcription:

Binghamton University EngiNet State University of New York EngiNet Thomas J. Watson School of Engineering and Applied Science WARNING All rights reserved. No Part of this video lecture series may be reproduced in any form or by any electronic or mechanical means, including the use of information storage and retrieval systems, without written approval from the copyright owner. 2008 The Research Foundation of the State University of New York CS 460/560 Computer Graphics Professor Richard Eckert Lecture # 3 February 5, 2008 Windows Programming with MFC Computer Graphics Hardware 1

MFC Programming MFC: The Microsoft Foundation Library Additional Notes: http://www.cs.binghamton.edu/~reckert/360/class14.htm http://www.cs.binghamton.edu/~reckert/360/class15.htm http://www.cs.binghamton.edu/~reckert/360/10.html MFC The Microsoft Foundation Class (MFC) Library-- A Hierarchy of C++ classes designed to facilitate Windows programming An alternative to using Win32 API functions A Visual C++ Windows app can use either Win32 API, MFC, or both Some Characteristics of MFC Offers convenience of REUSABLE CODE Many tasks in Windows apps are provided by MFC Programs can inherit and modify this functionality as needed MFC handles many clerical details in Windows pgms Functionality encapsulated in MFC Classes Produce smaller executables Can lead to faster program development MFC Programs must be written in C++ and require the use of classes Programmer must have good grasp of OO concepts Help on MFC Classes See Online Help (Index) on: MFC Hierarchy Hierarchy Chart On the Web: http://msdn.microsoft.com/library/default.asp?url=/library/enus/vcmfc98/html/_mfc_class_library_reference_introduction.asp Base MFC Class CObject: At top of hierarchy ("Mother of almost all MFC classes) Provides features like: Serialization Runtime class information Diagnostic & Debugging support Some important macros All its functionality is inherited by any classes derived from it 2

Some Important Derived Classes CFile CArchive CDC CGdiObject CMenu CCmdTarget: Encapsulates message passing process and is parent of: CWnd Base class from which all windows are derived Encapsulates many important windows functions and data members Examples: m_hwnd stores the window s handle Create( ) creates a window Most common subclasses: CFrameWindow CView CDialog CCmdTarget also parent of: CWinThread: Defines a thread of execution and is the parent of: CWinApp Encapsulates an MFC application Controls following aspects of Windows programs: Startup, initialization, execution, the message loop, shutdown An application should have one CWinApp object When instantiated, application begins to run CDocument Primary task in writing an MFC program To create/modify classes Most will be derived from MFC library classes MFC Class Member Functions Most functions called by an application will be members of an MFC class Examples: ShowWindow()--a member of CWnd class TextOut()--a member of CDC LoadBitmap()--a member of CBitmap Applications can also call API functions directly Use global scope resolution operator :: Example ::UpdateWindow(hWnd); MFC Global Functions Not members of any MFC class Independent of or span MFC class hierarchy Example: AfxMessageBox() 3

Message Processing under MFC API mechanism: switch/case statement in app s WndProc Under MFC, WndProc is buried in MFC framework Message handling mechanism: Message Maps" lookup tables the MFC WndProc searches A Message Map contains: A Message number A Pointer to a message-processing function These are members of CWnd You override the ones you want your app to respond to Like virtual functions Message-mapping macros set these up MFC Windows Programming (App/Window Approach) Simplest MFC programs must contain two classes derived from the hierarchy: 1. An application class derived from CWinApp Defines the application provides the message loop 2. A window class usually derived from CWnd or CFrameWnd Defines the application's main window To use these & other MFC classes you must have: #include <Afxwin.h> in the.cpp file MFC Windows Programming (Document/View Approach) Frequently need to have different views of same data Doc/View approach achieves this separation: Encapsulates data in a CDocument class object Encapsulates data display mechanism & user interaction in a CView class object Document Interfaces Single Document interface (SDI) app Program deals with one document at a time Example Microsoft Notepad Multiple Document Interface (MDI) app Program organized to handle multiple documents simultaneously Example of an MDI application: Microsoft Word Relationship between Documents, Views, and Windows 4

Document/View Programs Almost always have at least four classes derived from: CFrameWnd CDocument CView CWinApp Usually put into separate declaration (.h) and implementation (.cpp) files Lots of initialization code Could be done by hand, but nobody does it that way Microsoft Developer Studio AppWizard and ClassWizard Tools AppWizard Tool that generates a Doc/View MFC program framework automatically Can be built on and customized by programmer Fast, efficient way of producing Windows Apps Creates functional CFrameWnd, CView, CDocument, CWinApp classes After AppWizard does it's thing: Application can be built and run Full-fledged window with all common menu items, tools, etc. Other Visual Studio Wizards Dialog boxes that assist in generating code Generate skeleton message handler functions Set up the message map Connect resources & user-generated events to program response code Insert code into appropriate places in program Code then can then be customized by hand Create new classes or derive classes from MFC base classes Add new member variables/functions to classes In.NET many wizards available through Properties window SKETCH Application Example of Using AppWizard and ClassWizard User can use mouse as a drawing pencil Left mouse button down: lines in window follow mouse motion Left mouse button up: sketching stops User clicks "Clear" menu item window client area is erased Sketch data (points) won't be saved So leave document (CSketchDoc) class created by AppWizard alone Base functionality of application (CSketchApp) and frame window (CMainFrame) classes are adequate Leave them alone Use ClassWizard to add sketching to CView class 5

Sketching Requirements Each time mouse moves: If left mouse button is down: Get a DC Create a pen of drawing color Select pen into DC Move to old point Draw a line to the new point Make current point the old point Select pen out of DC Variables BOOLEAN m_butdn CPoint m_pt, m_ptold COLORREF m_color CDC* pdc Steps in Preparing SKETCH 1. File / New / Project Project Type: Visual C++ Projects Template: MFC Application Enter name: Sketch 2. In Welcome to MFC Application Wizard Application type: Single Document Application Take defaults for all other screens 3. Build Application --> Full-fledged SDI App with empty window and no functionality 4. Add member variables to CSketchView Can do manually in.h file Easier to: Select Class View pane Click on SketchViewclass Note member functions & variables Right click on CSketchView class Choose Add / Variable Launches Add Member Variable Wizard Variable Type: enter CPoint Name: m_pt Access: Public (default) Note after Finish that it s been added to the.h file Repeat for other variables (or add directly in.h file): CPoint m_ptold bool m_butdn COLORREF m_color CDC* pdc 5. Add message handler functions: Select CSketchView in Class View Select Messages icon in Properties window Results in a list of WM_ messages Scroll to WM_LBUTTONDOWN & select it Add the handler by clicking on down arrow and <Add> OnLButtonDown Note that the function is added in the edit window and the cursor is positioned over it: After TODO enter following code: m_butdn = TRUE; m_ptold = point; 6

Repeat process for WM_LBUTTONUP handler: Scroll to WM_LBUTTONUP Click: <Add> OnLButtonUp, Edit Code by adding: m_butdn = FALSE; Repeat for WM_MOUSEMOVE Scroll to WM_MOUSEMOVE Click: <Add> OnMouseMove Edit by adding code: if (m_butdn) { pdc = GetDC(); m_pt = point; CPen newpen (PS_SOLID, 1, m_color); CPen* ppenold = pdc->selectobject (&newpen); pdc->moveto (m_ptold); pdc->lineto (m_pt); m_ptold = m_pt; pdc->selectobject (ppenold); } 6. Initialize variables in CSketchView constructor Double click on CSketchView constructor CSketchView(void) in Class View After TODO, Add code: m_butdn = FALSE; m_pt = m_ptold = CPoint(0,0); m_color = RGB(0,0,0); 7. Changing Window s Properties Use window s SetWindowXxxxx() functions In CWinApp-derived class before window is shown and updated Example: Changing the default window title m_pmainwnd->setwindowtextw( TEXT( Sketching Application )); There are many other SetWindowXxxxx() functions that can be used to change other properties of the window 8. Build and run the application Menus and Command Messages User clicks on menu item WM_COMMAND message is sent ID_XXX identifies which menu item (its ID) No predefined handlers We write the OnXxx() handler function Must be declared in.h file and defined in.cpp file Event handler wizard facilitates this 7

Adding Color and Clear Menu Items to SKETCH App Resource View (sketch.rcfolder) Double click Menu folder Double click IDR_MAINFRAME menu Add: Drawing Color popup menu item with items: Red, ID_DRAWING_COLOR_RED (default ID) Blue, ID_DRAWINGCOLOR_BLUE Green, ID_DRAWINGCOLOR_GREEN Black, ID_DRAWINGCOLOR_BLACK Add another main menu item: Clear Screen, ID_CLEARSCREEN Set Popup property to False Add Menu Item Command Handler Function One way: Use Event Handler Wizard In Resource View bring up menu editor Right click on Red menu item Select Add Event Handler Event Handler Wizard dialog box Class list: CSketchView Message type: COMMAND Function handler name: accept default OnDrawingcolorRed Click on Add and edit After TODO in editor enter following code: m_color = RGB(255,0,0); Another Method of Adding a Menu Item Command Handler In Class View Select CSketchView In Properties window select Events (lightning bolt icon) Scroll down to: ID_DRAWINGCOLOR_RED Select COMMAND Click <Add> OnDrawingcolorRed handler Edit code by adding: m_color = RGB(255,0,0); Repeat for ID_DRAWINGCOLOR_BLUE Code: m_color = RGB(0,0,255); Repeat for ID_DRAWINGCOLOR_GREEN Code: m_color = RGB(0,255,0); Repeat for ID_DRAWINGCOLOR_BLACK Code: m_color = RGB(0,0,0); Repeat for ID_CLEAR Code: Invalidate(); 8

Destroying the Window Build and Run the Application Just need to call DestroyWindow() Do this in the CMainFrame class usually in response to a Quit menu item Computer Graphics Hardware Graphics Hardware Display Devices Vector Scan Image stored as line segments (vectors) that can be drawn anywhere on display device Raster Scan Image stored as a 2D array of color values in a memory area called the frame buffer Each value stored corresponds to an accessible point on display device Both based historically on CRT (TV) Electron beam accelerated toward screen focused deflected strikes phosphorescent material on screen -->pixel that glows A Pixel Visible point where electron beam hits screen Screen phosphors glow & fade Have a finite size Not a mathematical point 9

Resolution Maximum number of pixels that can be plotted without overlap Expressed as: # horizontal X # vertical pixels Depends on: phosphor used focusing system (how small a point) Speed/precision of deflection system video memory size (raster scan)--as we'll see Aspect Ratio Ratio of # of pixel columns to # of pixel rows Examples: SVGA VESA mode 100h: 640 X 400, A.R. = 1.6 Standard Windows: 640 X480. A.R. = 1.33 Pixel Ratio (often called Aspect Ratio) Ratio of pixel height to pixel width Ratio of # of horizontal pixels to vertical pixels needed to produce equal length lines For a square screen, A.R. = P.R. If Pixel Ratio!= 1, figures are distorted Dot Pitch Minimum distance between centers of adjacent pixels of same color Should be less than 0.28 mm for sharp images For fixed sized screen Decreasing distance between pixels ==> Increase Resolution So dot pitch determines max resolution Persistence After beam leaves a phosphor, it fades Definition of persistence: Time to reduce initial intensity by 10% Value depends on type of phosphor (10-100 msec.) Finite persistence==>screen must be redrawn Refreshrate determined by persistence Example: If persistence = 20 msec 1st pixel on screen invisible after that time ==> screen must be refreshed once every 20 msec so refresh rate must be > 50 Hz. Graphics Hardware Systems If refresh is too slow: flicker If refresh is too fast: shadowing (ghosting) CPU--Runs program in main memory specifies what is to be drawn CRT--does the actual display Display Controller--Provides analog voltages needed to move beam and vary its intensity DPU generates digital signals that drive display controller (offloads task of video control to separate processor) VRAM--Stores data needed to draw the picture Dual-ported (written to by CPU, read from by DPU) Fast (e.g., 1000X1000, 50 Hz ==> 20 nsec access time!) Also called Refresh Buffer or Frame Buffer I/O devices--interface CPU with user 10

Flat-Panel Displays Technologies to replace CRT monitors Reduced volume, weight, power needs Thinner: can hang on a wall Two categories Emissive and non-emissive Flat Panel Displays: Emissive Devices Convert electrical energy to light Plasma panels (gas-discharge displays) Voltages fired to intersecting vertical/horizontal conductors cause gas to glow at that pixel Resolution determined by density of conductors Pixel selected by x-y coordinates of conductors These are raster devices Other technologies All require storage of x-y coordinates of pixels Examples: Thin-film electroluminescent dipslays LEDs Flat CRTs Flat Panel Displays: Non-emissive Devices Use optical effects to convert ambient light to pixel patterns Example: LCDs Pass polarized light from surroundings through liquid crystal material that can be aligned to block or transmit the light Voltage applied to 2 intersecting conductors determines whether the liquid crystal blocks or transmits the lighe Like emissive devices, require storage of x-y coordinates of pixel to be illuminated Vector Scan Systems Also called random, stroke, calligraphic displays Images drawn as line segments (vectors) Beam can be moved to any position on screen Refresh Buffer stores plotting commands So Refresh Buffer often called "Display File provides DPU with needed endpoint coordinates Pixel size independent of frame buffer ==> very high resolution 11

Advantages of Vector Scan High resolution (good for detailed line drawings) Crisp lines (no "jaggies") High contrast (beam can dwell on a pixel==>very intense) Selective erase (remove commands from display file) Animation (change line endpoints slightly after each refresh) Disadvantages of Vector Scan Complex drawings can have flicker Many lines so if time to draw > refresh time ==> flicker High cost--very fast deflection system needed Hard to get colors No area fill so it s difficult to use for realistic (shaded) images 1960s Technology, only used for special purpose stuff today Raster Scan Systems (TV Technology) Beam continually traces a raster pattern Intensity adjusted as raster scan takes place In synchronization with beam Beam focuses on each pixel Each pixel s intensity stored in frame buffer So resolution determined by size of frame buffer Each pixel on screen visited during each scan Scan rate must be >= 30 Hz to avoid flicker Simplest system: one bit per pixel frame buffer called a bitmap Gray Scale: N bits/pixel 2^N intensities possible memory intensive Example:1000 X 1000 X 256 shades of gray ==> 8 Mbits 12

Scan Conversion Process of determining which pixels need to be turned on in the frame buffer to draw a given graphics primitive Need algorithms to efficiently scan convert graphics primitives like lines, circles, etc. Advantages of Raster Scan Systems Low cost (TV technology) Area fill (entire screen painted on each scan) Colors Selective erase (just change contents of frame buffer) Bright display, good contrast but not as good as vector scan can be: can t make beam dwell on a pixel Disadvantages Large memory requirement for high resolution (but cost of VRAM has decreased a lot!) Aliasing (due to finite size of frame buffer) Finite pixel size Jagged lines (staircase effect) Moire patterns, scintillation, "creep" in animations Raster scan is the principal now technology for graphics displays! 13