Initgraph Function In Dev C%2b%2b
- C++ Basics
Initializing C Graphics Mode: The computer display system must be initialized into graphics mode before calling the graphics function. The “initgraph” function is used to initialize the display into graphics mode. This function is a part of the “graphics.h” header file. DEV is a community of 531,294 amazing developers. We're a place where coders share, stay up-to-date and grow their careers.
The initgraph function takes three parameters, the graphics driver, the graphics mode and the path to the driver file. Once the driver has been loaded, initgraph sets up the numeric values of the graphics mode chosen in the variables gd and gm respectively. How To Use Initgraph In Dev C 4 graphics.h requires a specific library that is only found on Borland compilers (I don't think the newer Borland products even have it anymore). Look up WinBGIm as a possible alternative (however, it too is quite outdated). So in this tutorial, we learned about the different methods by which we can return an array from a C function. For any further questions, feel free to use the comments below. C return array from function – StackOverflow Question, Two Dimensional Array in C – Journal Dev Post. Dev-C is a free IDE for Windows that uses either MinGW or TDM-GCC as underlying compiler. Originally released by Bloodshed Software, but abandoned in 2006, it has recently been forked by Orwell, including a choice of more recent compilers.
Initgraph Function In Dev C 2b 2b Answer
- C++ Object Oriented
- C++ Advanced
- C++ Useful Resources
- Selected Reading
There may be a situation, when you need to execute a block of code several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
Programming languages provide various control structures that allow for more complicated execution paths.
A loop statement allows us to execute a statement or group of statements multiple times and following is the general from of a loop statement in most of the programming languages −
C++ programming language provides the following type of loops to handle looping requirements.
Initgraph Function In Dev C 2b 2b 3c
Sr.No | Loop Type & Description |
---|---|
1 | while loop Repeats a statement or group of statements while a given condition is true. It tests the condition before executing the loop body. |
2 | for loop Execute a sequence of statements multiple times and abbreviates the code that manages the loop variable. |
3 | do...while loop Like a ‘while’ statement, except that it tests the condition at the end of the loop body. |
4 | nested loops You can use one or more loop inside any another ‘while’, ‘for’ or ‘do..while’ loop. |
Loop Control Statements
Loop control statements change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.
C++ supports the following control statements.
Sr.No | Control Statement & Description |
---|---|
1 | break statement Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch. |
2 | continue statement Causes the loop to skip the remainder of its body and immediately retest its condition prior to reiterating. |
3 | goto statement Transfers control to the labeled statement. Though it is not advised to use goto statement in your program. |
The Infinite Loop
A loop becomes infinite loop if a condition never becomes false. The for loop is traditionally used for this purpose. Since none of the three expressions that form the ‘for’ loop are required, you can make an endless loop by leaving the conditional expression empty.
When the conditional expression is absent, it is assumed to be true. You may have an initialization and increment expression, but C++ programmers more commonly use the ‘for (;;)’ construct to signify an infinite loop.
NOTE − You can terminate an infinite loop by pressing Ctrl + C keys.
Graphics programming in C used to drawing various geometrical shapes(rectangle, circle eclipse etc), use of mathematical function in drawing curves, coloring an object with different colors and patterns and simple animation programs like jumping ball and moving cars.
1. First graphics program (Draw a line)
2. Explanation of Code :
The first step in any graphics program is to include graphics.h
header file. The graphics.h
header file provides access to a simple graphics library that makes it possible to draw lines, rectangles, ovals, arcs, polygons, images, and strings on a graphical window.
The second step is initialize the graphics drivers on the computer using initgraph
method of graphics.h
library.
It initializes the graphics system by loading the passed graphics driver then changing the system into graphics mode. It also resets or initializes all graphics settings like color, palette, current position etc, to their default values. Below is the description of input parameters of initgraph function.
graphicsDriver : It is a pointer to an integer specifying the graphics driver to be used. It tells the compiler that what graphics driver to use or to automatically detect the drive. In all our programs we will use
DETECT
macro of graphics.h library that instruct compiler for auto detection of graphics driver.graphicsMode : It is a pointer to an integer that specifies the graphics mode to be used. If
*gdriver
is set toDETECT
, theninitgraph
sets*gmode
to the highest resolution available for the detected driver.driverDirectoryPath : It specifies the directory path where graphics driver files (
BGI files
) are located. If directory path is not provided, then it will search for driver files in current working directory directory. In all our sample graphics programs, you have to change path of BGI directory accordingly where you Turbo C++ compiler is installed.
We have declared variables so that we can keep track of starting and ending point.
No, We need to pass just 4 parameters to the line
function.
line
Function Draws Line From (x1,y1) to (x2,y2) .
Parameter Explanation
- x1 - X Co-ordinate of First Point
- y1 - Y Co-ordinate of First Point
- x2 - X Co-ordinate of Second Point
- y2 - Y Co-ordinate of Second Point
At the end of our graphics program, we have to unloads the graphics drivers and sets the screen back to text mode by calling closegraph
function.
3. Colors in C Graphics Programming
There are 16 colors declared in graphics.h header file. We use colors to set the current drawing color, change the color of background, change the color of text, to color a closed shape etc (Foreground and Background Color). To specify a color, we can either use color constants like setcolor(RED), or their corresponding integer codes like setcolor(4). Below is the color code in increasing order.
Constant | Value | Background? | Foreground? |
---|---|---|---|
BLACK | 0 | Yes | Yes |
BLUE | 1 | Yes | Yes |
GREEN | 2 | Yes | Yes |
CYAN | 3 | Yes | Yes |
RED | 4 | Yes | Yes |
MAGENTA | 5 | Yes | Yes |
BROWN | 6 | Yes | Yes |
LIGHTGRAY | 7 | Yes | Yes |
DARKGRAY | 8 | NO | Yes |
LIGHTBLUE | 9 | NO | Yes |
LIGHTGREEN | 10 | NO | Yes |
LIGHTCYAN | 11 | NO | Yes |
LIGHTRED | 12 | NO | Yes |
LIGHTMAGENTA | 13 | NO | Yes |
YELLOW | 14 | NO | Yes |
WHITE | 15 | NO | Yes |
BLINK | 128 | NO | * |
***** To display blinking characters in text mode, add BLINK to the foreground color. (Defined in conio.h
)
4. Graphics example using color
5. Examples
Initgraph Function In Dev C 2b 2b 1b
Example Statement for Graphics in C Language |
---|
1. Drawing Line in Graphics Mode |
2. Make Static Countdown |
3. Draw Moving a Car |
4. Press Me Button Game |
5. Draw Smiling Face Animation |
6. Make Traffic Light Simulation |