1 DirectDraw and Bitmaps Part 1 CIS 487/587 Bruce R. Maxim UM-Dearborn.

Slides:



Advertisements
Similar presentations
OpenGL CMSC340 3D Character Design & Animation. What is OpenGL? A low-level graphics library specification designed for use with the C and C++ provides…
Advertisements

1 2D Graphics CIS 487/587 Bruce R. Maxim UM-Dearborn.
Computer Graphics Tz-Huan Huang National Taiwan University (Slides are based on Prof. Chen’s)
HW/Study Guide. Synchronization Make sure you understand the HW problems!
CSCC69: Operating Systems
Status – Week 257 Victor Moya. Summary GPU interface. GPU interface. GPU state. GPU state. API/Driver State. API/Driver State. Driver/CPU Proxy. Driver/CPU.
The Linux Kernel: Memory Management
CS1061: C Programming Lecture 21: Dynamic Memory Allocation and Variations on struct A. O’Riordan, 2004, 2007 updated.
Dynamic Memory Allocation in C++. Memory Segments in C++ Memory is divided in certain segments – Code Segment Stores application code – Data Segment Holds.
Game Design and Programming. Objectives Classify the games How games are design How games are implemented What are the main components of a game engine.
1 DirectDraw and Bitmaps Part 2 CIS 487/587 Bruce R. Maxim UM-Dearborn.
CS 4731: Computer Graphics Lecture 21: Raster Graphics Part 2 Emmanuel Agu.
Pointers Applications
Java2D Graphics Summary Images,. Full-Screen Exclusive Mode -Full-screen exclusive mode is a powerful feature of J2SE TM version 1.4 that allows the programmer.
1 DirectDraw Basics CIS 487/587 Bruce R. Maxim UM-Dearborn.
OpenGL Pixel Operations, Bitmaps, Fonts and Images The Current Raster Position Current raster position: A position in window coordinates where the next.
Bitmapped Images. Bitmap Images Today’s Objectives Identify characteristics of bitmap images Resolution, bit depth, color mode, pixels Determine the most.
Practical Session 11 Multi Client-Server Java NIO.
1 CISC181 Introduction to Computer Science Dr. McCoy Lecture 19 Clicker Questions November 3, 2009.
Basics of a Computer Graphics System Introduction to Computer Graphics CSE 470/598 Arizona State University Dianne Hansford.
1 Scrolling and Panning CIS 487/587 Bruce R. Maxim UM-Dearborn.
 Bitmap: A bitmap is a rectangular array of 0s and 1s that serves as a drawing mask for a corresponding rectangular portion of the window.  Applications:
Lecture 02: Intro to SDL Topics: Downloading / Installing SDL Linking (in general and for SDL) SDL basics References:
Java: Chapter 1 Computer Systems Computer Programming II.
9/20/20151 Interaction Devices CIS 577 Bruce R. Maxim UM-Dearborn.
Tools for Raster Displays CVGLab Goals of the Chapter To describe pixmaps and useful operations on them. To develop tools for copying, scaling, and rotating.
ECE291 Computer Engineering II Lecture 9 Josh Potts University of Illinois at Urbana- Champaign.
Video Monitor Uses raster scanning to display images –Beam of electrons illuminates phosphorus dots on the screen called pixels. Starting at the top of.
Chapter 2 Getting Started: Drawing Figures. The Framebuffer Lecture 2 Fri, Aug 29, 2003.
Using the JImageViewer classes. JImageViewer classes JImageViewer class JImageViewer class ImagePanel class ImagePanel class Image class Image class.
Lab 8 Bit-Mapped Graphics Moving from text-based graphics to bit- mapped graphics. Easy to draw graphic points and lines using INT 10h, Function 0Ch (write.
Lecture 4 Pixels, Images and Image Files 1. In this Lecture, you will learn the following concepts: Image files (in particular, the BMP file format) How.
Pixels, Images and Image Files 1 By Dr. HANY ELSALAMONY.
CSC Computing with Images
OpenGL-ES 3.0 And Beyond Boston What is EGL? EGL handles: –provides available surface specifications –context management –surface binding –render.
1 Windows GDI Programming CIS 487/587 Bruce R. Maxim UM-Dearborn.
1 Computer Graphics Week2 –Creating a Picture. Steps for creating a picture Creating a model Perform necessary transformation Lighting and rendering the.
NVTune Kenneth Hurley. NVIDIA CONFIDENTIAL NVTune Overview What issues are we trying to solve? Games and applications need to have high frame rates Answer.
ECE291 Lecture 12 Mode 13h Graphics. ECE 291 Lecture 12Page 2 of 27 Lecture outline Color theory Video Hardware Mode 13h Graphics File Formats.
Rick Parent - CIS681 Background Perception Display Considerations Film and Video, Analog and Digital Technology.
Page 1 Data Structures in C for Non-Computer Science Majors Kirs and Pflughoeft Dynamic Memory Allocation Suppose we defined the data type: struct custrec.
ECE291 Computer Engineering II Lecture 15 Josh Potts University of Illinois at Urbana- Champaign.
Chapter 9 DirectDraw 크래용 사용하기
Lecture 7: Intro to Computer Graphics. Remember…… DIGITAL - Digital means discrete. DIGITAL - Digital means discrete. Digital representation is comprised.
Practical Session 11 Multi Client-Server Java NIO.
CS1372: HELPING TO PUT THE COMPUTING IN ECE CS1372 Some Basics.
12/5/2015 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
Images. Digital Images Rectangular arrays of pixel data Pixel - picture element, smallest addressable part of the frame buffer. Color depth - the depth.
Beam Penetration & Shadow Mask Method
1. Cathode Ray Tubes (CRTs) TVs, RGB monitors, o-scopes Flat-Panel Displays PDAs, laptops, calculators, digital watches 2.
GAM666 – Introduction To Game Programming ● DirectDraw, the 2D component of DirectX, uses the term “surface” to mean an area of memory in which pixel data.
2/16/2016 EEC492/693/793 - iPhone Application Development 1 EEC-693/793 Applied Computer Vision with Depth Cameras Lecture 4 Wenbing Zhao
Java & C++ Comparisons How important are classes and objects?? What mechanisms exist for input and output?? Are references and pointers the same thing??
Chapter 16 GPDUMB Engine Part II. 2 GPDUMB2 Engine.
Lecture 11 Text mode video
 Backlight 에서 나온 백색광이 액정 셀을 통과하면 서 투과율이 조절되고 red, green, blue 의 color filter 를 투과해 나오는 빛의 혼합을 통해 색이 구 성됨  Color filter 는 셀사이의 빛을 차단하는 black matrix,
Reference: What is it? A multimedia python library – Window Management – Graphics geometric shapes bitmaps (sprites) – Input Mouse Keyboard.
Computer Graphics: An Introduction
Lecture 11 Virtual Memory
Pixels, Colors and Shapes
Virtual Memory User memory model so far:
U2L4 Encoding Color Images
C Basics.
ECE 391 Exam 2 HKN Review Session
Managed DirectX Joe Gavin.
Microprocessor and Assembly Language
EEC-693/793 Applied Computer Vision with Depth Cameras
EEC-693/793 Applied Computer Vision with Depth Cameras
The Framebuffer 1 Lecture 37 Fri, Nov 30, 2007.
CS-401 Computer Architecture & Assembly Language Programming
Presentation transcript:

1 DirectDraw and Bitmaps Part 1 CIS 487/587 Bruce R. Maxim UM-Dearborn

2 Screen Basics A standard 640x480x8 screen buffer has 307,200 pixels Without 3D acceleration hardware, software-based rasterization is not practical for more than 256 colors For bitmap work this is 3D acceleration is a little less critical

3 16 Bit Encoding There are several 16 bit high-color pixel encoding schemes –Alpha –X –5.6.5 (most common) Getting the pixel format right before plotting is important You can choose to set it to yourself if you wish

4 Writing a Screen Pixel Lock the surface using Lock( ) Build the 16-bit RGB word using the macro _RGB16BIT5.6.5 Write the pixel using a USHORT pointer into VRAM Unlock the primary surface using unlock

5 LaMothe Examples

6 Ddraw 16-bit Pixel Plotting // done as global declarations // builds a 16 bit color value in format (green dominate mode) #define _RGB16BIT565(r,g,b) ((b&31) + ((g&63) << 5) + ((r&31) << 11)) // initializes a direct draw struct #define DDRAW_INIT_STRUCT(ddstruct) {memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct); } inline void Plot_Pixel_Faster16(int x, int y, int red, int green, int blue, USHORT *video_buffer, int lpitch16) { // plots a pixel in 16-bit color mode assumes caller already locked the // surfaceand is sending a pointer and byte pitch to it USHORT pixel = _RGB16BIT565(red,green,blue); // first build up color WORD video_buffer[x + y*lpitch16] = pixel; // write the data } // end Plot_Pixel_Faster16

7 Game_Main( ) // clear ddsd and set size, never assume it's clean DDRAW_INIT_STRUCT(ddsd); // lock the primary surface if (FAILED(lpddsprimary->Lock(NULL, &ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT, NULL))) return(0); int lpitch16 = (int)(ddsd.lPitch >> 1); USHORT *video_buffer = (USHORT *)ddsd.lpSurface; // plot the pixel once position and color is set Plot_Pixel_Faster16(x,y,red,green,blue,video_buffer,lpitch16); // now unlock the primary surface if (FAILED(lpddsprimary->Unlock(NULL))) return(0);

8 Game_Init( ) // create IDirectDraw interface 7.0 object and test for error if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL))) return(0); // set cooperation to full screen if (FAILED(lpdd->SetCooperativeLevel(main_window_handle, DDSCL_FULLSCREEN | DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_ALLOWREBOOT))) return(0); // set display mode to 640x480x16 if (FAILED(lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,0,0))) return(0); // clear ddsd and set size memset(&ddsd,0,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS; // enable valid fields ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; // request primary surface // create the primary surface if (FAILED(lpdd->CreateSurface(&ddsd, &lpddsprimary, NULL))) return(0);

9 Game_Shutdown( ) // blow away the primary surface if (lpddsprimary) { lpddsprimary->Release(); lpddsprimary = NULL; } // end if // blow away the IDirectDraw interface if (lpdd) { lpdd->Release(); lpdd = NULL; } // end if

10 Plotting 24 Bit Pixels inline void Plot_Pixel_24(int x, int y, int red, int green, int blue, UCHAR *video_buffer, int lpitch) { // function plots pixel in 24-bit color mode assumes caller locked surface // and is sending a pointer and byte pitch to it // in byte or 8-bit math the proper address is: 3*x + y*lpitch // this is the address of low order byte which is the Blue channel // since data is in RGB order DWORD pixel_addr = (x+x+x) + y*lpitch; // write the data, first blue video_buffer[pixel_addr] = blue; // now red video_buffer[pixel_addr+1] = green; // finally green video_buffer[pixel_addr+2] = red; } // end Plot_Pixel_24

11 Plotting 32 Bit Pixels // builds a 32 bit color value in A format (8-bit alpha mode) #define _RGB32BIT(a,r,g,b) ((b)+ ((g)<<8) + ((r)<<16) + ((a)<<24)) inline void Plot_Pixel_32(int x, int y, int alpha,int red, int green, int blue, UINT *video_buffer, int lpitch32) { // this function plots a pixel in 32-bit color mode // assuming that the caller already locked the surface // and is sending a pointer and DWORD aligned pitch to it // first build up color WORD UINT pixel = _RGB32BIT(alpha,red,green,blue); // write the data video_buffer[x + y*lpitch32] = pixel; } // end Plot_Pixel_32

12 Animation and Bitmaps DirectDraw gives you two choices for doing continuous animation –Page flipping (using primary and secondary surfaces) –Double buffering (using system memory for back buffer and programmer to flips the pages) In both cases DirectDraw does the hard work of page flipping (regardless of whether VRAM is linear or non-linear)

13 Overview of Double Buffering Game_Init( ) –new is used to allocate double buffer Game_Sutdown( ) –Double buffer must be freed up Game_Main( ) –Double buffer is erased and 5000 pixels are drawn “offline” –Check is made for linear memory and then buffer is copied to screen memory

14 Game_Init( ) // once the primary surface, cooperation, display mode, and palette // are defined // allocate double buffer if ((double_buffer=new UCHAR[SCREEN_WIDTH * SCREEN_HEIGHT])==NULL) return(0);

15 Game_Shutdown( ) // blow away the palette, surface, and direct draw interface first // release the memory used for double buffer if (double_buffer) { delete double_buffer; double_buffer = NULL; } // end if

16 Game_Main( ) UCHAR *primary_buffer = NULL; // alias to primary surface buffer // erase double buffer memset((void *)double_buffer,0, SCREEN_WIDTH*SCREEN_HEIGHT); double_buffer[x+y*SCREEN_WIDTH] = col; // plot at least one pixel // copy the double buffer into the primary buffer DDRAW_INIT_STRUCT(ddsd); // lock the primary surface lpddsprimary->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL); // get video pointer to primary surfce primary_buffer = (UCHAR *)ddsd.lpSurface;

17 Game_Main( ) // test if memory is linear if (ddsd.lPitch == SCREEN_WIDTH) { // copy memory from double buffer to primary buffer memcpy((void *)primary_buffer, (void *)double_buffer, SCREEN_WIDTH*SCREEN_HEIGHT); } // end if else { // non-linear // make copy of source and destination addresses UCHAR *dest_ptr = primary_buffer; UCHAR *src_ptr = double_buffer;

18 Game_Main( ) // memory is non-linear, copy line by line for (int y=0; y < SCREEN_HEIGHT; y++) { // copy line memcpy((void *)dest_ptr, (void *)src_ptr, SCREEN_WIDTH); // advance pointers to next line dest_ptr+=ddsd.lPitch; src_ptr +=SCREEN_WIDTH; } // end for } // end else // now unlock the primary surface if (FAILED(lpddsprimary->Unlock(NULL))) return(0);

19 Back Buffer Steps 1.Allocate memory for back buffer with same pixel dimensions as primary 2.In main loop erase back buffer 3.Perform game logic 4.Render the next frame in the back buffer 5.Copy the back buffer to the primary buffer (surface) 6.Synchronize display to desired frame rate 7.Go to step 2