Presentation is loading. Please wait.

Presentation is loading. Please wait.

Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana.

Similar presentations


Presentation on theme: "Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana."— Presentation transcript:

1 Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana

2 OperationSymbol AND& Inclusive OR| Exclusive OR (XOR)^ Right Shift>> Left Shift<< Complement~ Programming In C++, Lecture 13 By Umer Rana Bitwise Operators

3 AND Operator (&) Require two operands and will perform bit comparisons. AND & will copy a bit to the result if it exists in both operands. Programming In C++, Lecture 13 By Umer Rana

4 OR Operator (|) OR | will copy a bit if it exists in either operand. Programming In C++, Lecture 13 By Umer Rana

5 XOR Operator (^) XOR ^ Return 1 value when 1 is set in either bit set of operand (but not both). Programming In C++, Lecture 13 By Umer Rana

6 Complement Operator (~) This operator is unary (requires one operand) and has the effect of 'flipping' bits. Programming In C++, Lecture 13 By Umer Rana

7 Right Shift >> and Left Shift << The left operands value is moved left or right by the number of bits specified by the right operand. For example: Programming In C++, Lecture 13 By Umer Rana

8 The Character Display Memory Communication between the adaptor and the computer takes place using a special section of memory as a sort of common ground. This section of memory is physically located on the adaptor board and can be accessed both by the microprocessor and by the display screen. The normal character display consist of 25 rows and 80 columns in a display screen. Two bytes in the memory are used for each character: one to hold the extended ASCII character code, and one to hold the attribute. Thus 4,000 bytes of memory are needed to represent Programming In C++, Lecture 13 By Umer Rana

9 Far Pointers When we call a C library routine to display a character on the screen, it calls a routine in ROM BIOS. The ROM BIOS puts the character on the screen by placing the values from the character’s extended code and attribute byte in the appropriate address. By using Far Pointer we can inserts values from these bytes directly in to memory, we can save a lot of time, because (among other reasons) we eliminate the overhead of calling one routine that calls another. int *ptr; /* looks plausible */ ptr=0xB0000 /* but */ *(ptr) = ch; /* won’t work */ Programming In C++, Lecture 13 By Umer Rana

10 Segments The normal pointer variable type (no matter what data type it points to) consists of a two-byte quantity, while the address B0000 hex is a two and one-half byte number. The reason is that normal pointers are used to contain address in only one segment. To handle this situation we use a special set of registers called segment registers. Addresses outside a segment are formed by combining the starting address of a segment, called the segment address. [ The starting address of the segment is placed in a segment register. Programming In C++, Lecture 13 By Umer Rana

11 The Attribute Byte Attribute byte is divided into 4 sections. Two of these sections consist of a single bit. Bit 3 and 7. Bit 3 controls intensity, and bit 7 controls blinking. If one of these bits is set to 1, the corresponding attribute (blinking or intensified) is turned on; when the bit is set to 0, the attribute is off. The two other sections of the attribute byte consist of three bits each. Bits 0,1 and 2 make up the “foreground color”, while bits 4,5 and 6 make up the “background color”. 000 000 means non display and 000 001 means underline 000 111 means dark background and 111 000 means reverse video Programming In C++, Lecture 13 By Umer Rana

12 Modes Programmer can choose a variety of different modes, or formats. Each mode provides a different combination of graphics characteristics. These characteristics include the resolution, the number of possible colors, whether text or graphics are to be displayed, and other elements. Resolution Graphics images on a computer screen are composed of tiny dots called pixels, pixels are arranged on a screen in horizontal rows: there are a fixed number of rows, and each row contains a certain number of pixels The no. of pixels used on a screen called resolution. For example, mode 4 uses a resolution of 200 rows, each 320 pixels across. This is abbreviated 320 by 200, or 320x200. Direct Access Colour Graphics Graphic Modes and Resolution Programming In C++, Lecture 13 By Umer Rana

13 Some modes exist only to place text on the screen, others are made for graphics. In the graphics mode each bit, or each group of bits, corresponds to a particular pixel (dot) on the screen. But as in the text mode, a group of bits (actually two bytes) corresponds to a character. Direct Access Colour Graphics Text / Graphics Programming In C++, Lecture 13 By Umer Rana

14 If you’re using the monochrome monitor or adaptor, when you first turn on your monitor, it will boot-up in mode 7. if you’re using a color display with CGA, EGA or VGA you’ll probably boot up in mode 3, a text only mode. Neither of these modes permits you to do graphics. To draw graphics on the color screen, you’ll need to know how to switch from mode or mode 3 to a graphics mode. To select mode, we make use of a ROM BIOS routine called Set Video Mode. This involves putting 0 in the AH register, the desired mode number in the AL register, and executing an interrupt number 10 (hex). Direct Access Colour Graphics Setting Modes Programming In C++, Lecture 13 By Umer Rana

15 The simplest way to display graphics images on a screen is to use a ROM routine called Write Dot. Direct Access Colour Graphics Display Pixels With ROM Routines Programming In C++, Lecture 13 By Umer Rana

16 All the graphics adaptors are capable of generating 16 colors. Even in mode 4, which allows only 8 colors. That program uses a variation of the Set Color Palette ROM routine to change the background. We specify that we want to change the background by placing a 0 in the BH register instead of a 1as we do previously. Direct Access Colour Graphics Setting Color Palette & Background Programming In C++, Lecture 13 By Umer Rana

17 Graphics Functions Programming In C++, Lecture 13 By Umer Rana For Text-Mode Functions graphics display is not necessary; you can use either the monochrome display (mode 7); or the text mode on a graphics display (mode 3). Windows A major purpose of the C text-mode functions is to permit the use of windows. A window is simply a rectangular area of the screen that forms a boundary for video output. Turbo c graphics functions make it easy to manipulate text in a window instead of in the entire screen. Text-Mode Functions

18 Graphics Functions Programming In C++, Lecture 13 By Umer Rana #include #define LEFT 10 #define TOP 8 #define RIGHT 52 #define BOT 21 #define HEIGHT (BOT-TOP+1) void main( ) {int j; window ( LEFT, TOP, RIGHT, BOT); textcolor(RED); textbackground (GREEN); cput("Greetings"); gotoxy(15,8); }. Text-Mode Functions See the color chart from the page No. 465

19 Another text-mode function, movetext(), copies a rectangular area of text from one part of the screen to another. movetext(LEFT, TOP, RIGHT, BOT, Destination LEFT, Destination TOP) Programming In C++, Lecture 13 By Umer Rana Graphics Functions Moving Text

20 The text on a rectangular part of the screen can be saved in memory, and later restored to the same or a different location on the screen. gettext() Save the contents of the entire screen to ta memory Buffer. puttext() Moves text from memory back to the screen. Programming In C++, Lecture 13 By Umer Rana Graphics Functions Saving & Restoring Screen Text

21 Initializing Graphics Mode Before any of the graphics-mode functions can be used, the graphics systems must be initialized by the function initgraph(). This function loads a graphics drive from the disk and changes the display to the appropriate graphics mode. Class Activity Using initgraph() to initialize the system, and then draws a circle and line. Draw Line Style and Rectangle.. Draw Colored Circle and Line.. Draw Ellipse and Polygons… Programming In C++, Lecture 13 By Umer Rana Graphics Functions Graphics Mode Funtions

22 #include int main( ) { initwindow(400, 300, "First Sample"); //circle(x,y,radius) circle(100, 50, 40); getch(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Circle

23 #include int main( ) { initwindow(400, 300, "First Sample"); //line(Start x,Start y, End x, End y) line(100,100,500,500); getch(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Line

24 #include int main( ) { initwindow(400, 300, "First Sample"); setlinestyle(1,0,1); line(100,100,500,500); getch(); return 0; } setlinestyle( int linestyle, unsigned upattern, int hickness ); Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Line With Style Name Value Description SOLID_LINE0Solid line DOTTED_LINE1Dotted line CENTER_LINE2Centered line DASHED_LINE3Dashed line USERBIT_LINE 4 User-defined line style NameValue Description NORM_WIDTH11 pixel wide THICK_WIDTH 33 pixels wide Line Style Line Width

25 #include int main( ) { initwindow(400, 300, "First Sample"); //setcolor(Int color (between 0-15) ); (See on Page 465 ) setcolor(2); setlinestyle(1,0,1); line(100,100,500,500); getch(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Line With Color

26 #include int main( ) { initwindow(400, 300, "First Sample"); // void ellipse(int x, int y, int StartAngle, int EndAngle, int x-radius, int y-radius); ellipse(100, 100, 0, 360, 50, 25); getch(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Ellipse

27 #include int main( ) { initwindow(400, 300, "First Sample"); // rectangle(int left, int top, int right, int bottom); rectangle(50,50,150,180); getch(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Rectangle

28 main() { int gd = DETECT, gm; initwindow(400, 300, "First Sample"); //void arc(int x, int y, int Start Angle, int EndAngle, int radius); arc(100, 100, 0, 135, 50); getch(); } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Draw Arc

29 http://www.programmingsimplified.com/c/graphics.h/ Programming In C++, Lecture 13 By Umer Rana Graphics Functions For More Detail. Please Visit this web site for more Graphics Options

30 Turbo C can fill the outlines of graphics shapes with color by using several functions. – setfillstyle() – floodfill() Any many more functions are given by C Lanaguage Programming In C++, Lecture 13 By Umer Rana Graphics Functions Filling & Patterns

31 int main() { initwindow(400, 300, "First Sample"); // void setfillstyle( int pattern, int color); setfillstyle(6, 2); circle(100, 100, 50); //void floodfill(int x, int y, int border); floodfill(100, 100, WHITE); closegraph(); } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Filling & Patterns

32 Turbo C makes available functions that will draw text characters in graphics mode. They make it possible to change text fonts and vary the size of text. Programming In C++, Lecture 13 By Umer Rana Graphics Functions Text & Graphics

33 main() { int gd = DETECT, gm; initgraph(&gd, &gm, "C:\\TC\\BGI"); //void bar(int left(x-axis), int top(y-axis), int right(x-axis), int bottom(y-axis)); bar(100, 100, 200, 400); } Programming In C++, Lecture 13 By Umer Rana Graphics Functions Graphics

34 Viewports Viewports provide a way to restrict to an arbitrary size the area of the screen used for drawing. The viewport is created with the setviewport() function. The function clearviewport() erases the image from the viewport by leaving the rest of the screen untouched. Pixels Individual pixels can be plotted using the putpixel() function. This is useful when graphing mathematical functions, and in “draw” or “paint” type programs that enable the user to create complex images. Programming In C++, Lecture 13 By Umer Rana Graphics Functions

35 Viewports int mainVP() { //void setviewport(int left, int top, int right, int bottom, int clip); setviewport(10, 10, 50, 50, 1); rectangle(50,50,150,180); circle(50, 50, 55); getch(); closegraph(); return 0; } Programming In C++, Lecture 13 By Umer Rana Graphics Functions

36 Pixels #include main() { initwindow(700, 700, "First Sample"); // void putpixel(int x, int y, int color); putpixel(25, 25, RED); getch(); } Programming In C++, Lecture 13 By Umer Rana Graphics Functions


Download ppt "Programming In C++ Spring Semester 2013 Lecture 13 Programming In C++, Lecture 13 By Umer Rana."

Similar presentations


Ads by Google