Introduction to Graphics with graphics.h and initgraph() Function in C Language
Graphics programming in C language allows programmers to create different graphical objects and shapes such as lines, rectangles, circles, ellipses and arcs. We can also fill colours in graphical objects and create simple animation programs such as a jumping ball, rainbow, moving fan and moving car. In traditional C graphics programming, the graphics.h header file is used to access graphics library functions. It provides functions to draw lines, rectangles, circles, ellipses, arcs and display text in a graphics window. The graphics.h library and BGI graphics system are associated with traditional Turbo C/C++ environments. They are not part of the standard C language or its standard library. Modern compilers such as GCC do not normally provide graphics.h by default. A compatible graphics library or an appropriate graphics environment is required.
C लैंग्वेज में Graphics Programming के द्वारा Programmer विभिन्न Graphical Objects और Shapes जैसे Lines, Rectangles, Circles, Ellipses तथा Arcs तैयार कर सकते हैं। हम Graphical Objects में Colours भी भर सकते हैं तथा Jumping Ball, Rainbow, Moving Fan और Moving Car जैसे सामान्य Animation Programs बना सकते हैं। Traditional C Graphics Programming में Graphics Library के Functions का उपयोग करने के लिए graphics.h Header File को Include किया जाता है। इसमें Lines, Rectangles, Circles, Ellipses, Arcs बनाने तथा Graphics Window में Text Display करने के लिए Functions उपलब्ध होते हैं। graphics.h Library तथा BGI Graphics System का उपयोग मुख्यतः Traditional Turbo C/C++ Environment में किया जाता है। ये Standard C Language या इसकी Standard Library का हिस्सा नहीं हैं। GCC जैसे Modern Compilers में सामान्यतः graphics.h पहले से उपलब्ध नहीं होती। इसके लिए Compatible Graphics Library या उपयुक्त Graphics Environment की आवश्यकता होती है।
Graphics Header File in C
The graphics.h header file contains declarations of graphics-related functions, constants and other definitions used by the traditional BGI graphics library. To use these functions, we include the header file at the beginning of a graphics program.
Traditional BGI Graphics Library में Graphics से संबंधित Functions, Constants तथा अन्य Definitions उपलब्ध होते हैं। इन Functions का उपयोग करने के लिए Graphics Program की शुरुआत में graphics.h Header File को Include किया जाता है।
Syntax:
#include <graphics.h>initgraph() Function in C Graphics
The initgraph() function is used to initialize the graphics system in traditional BGI graphics programming. It loads the required graphics driver, initializes the graphics mode and switches the program from text mode to graphics mode. It also initializes graphics settings such as the background colour, drawing colour and current graphics position.
Traditional BGI Graphics Programming में initgraph() Function का उपयोग Graphics System को Initialize करने के लिए किया जाता है। यह आवश्यक Graphics Driver को Load करता है, Graphics Mode को Initialize करता है तथा Program को Text Mode से Graphics Mode में परिवर्तित करता है। यह Background Colour, Drawing Colour तथा Current Graphics Position जैसी Settings को भी Initialize करता है।
Syntax of initgraph()
The syntax of the initgraph() function is:
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);initgraph() Function का Syntax निम्नलिखित है:
void initgraph(int *graphdriver, int *graphmode, char *pathtodriver);Parameters of initgraph()
The initgraph() function accepts three parameters:
initgraph() Function में तीन Parameters का उपयोग किया जाता है:
1. graphdriver
It is a pointer to an integer that specifies the graphics driver to be used. In traditional BGI programming, the constant DETECT is used to request automatic detection of the available graphics driver.
यह एक Integer Pointer होता है जो उपयोग किए जाने वाले Graphics Driver को निर्धारित करता है। Traditional BGI Programming में उपलब्ध Graphics Driver का Automatic Detection करने के लिए DETECT Constant का उपयोग किया जाता है।
2. graphmode
It is a pointer to an integer that specifies the graphics mode. When DETECT is used for automatic driver detection, the graphics system selects a suitable graphics mode and stores the detected mode through this parameter.
यह एक Integer Pointer होता है जो Graphics Mode को निर्धारित करता है। जब Automatic Driver Detection के लिए DETECT का उपयोग किया जाता है, तब Graphics System उपयुक्त Graphics Mode का चयन करके इस Parameter के माध्यम से उस Mode को निर्धारित करता है।
3. pathtodriver
It specifies the directory path where the BGI graphics driver files are located. In traditional Turbo C installations, this path usually points to the BGI directory.
यह BGI Graphics Driver Files के संग्रहित होने वाले Directory Path को दर्शाता है। Traditional Turbo C Installation में यह Path सामान्यतः BGI Directory को दर्शाता है।
Example of initgraph() Function
The following statement initializes the graphics system using automatic driver detection:
निम्नलिखित Statement Automatic Driver Detection का उपयोग करके Graphics System को Initialize करता है:
int gd = DETECT;int gm;initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
Explanation:
gdis the graphics driver variable.gmis the graphics mode variable.DETECTrequests automatic graphics driver detection.&gdand&gmpass the addresses of these variables."C:\\TURBOC3\\BGI"specifies the BGI driver directory. This path must be changed according to the actual installation directory.
व्याख्या:
gdGraphics Driver Variable है।gmGraphics Mode Variable है।DETECTAutomatic Graphics Driver Detection का निर्देश देता है।&gdतथा&gmइन Variables के Addresses Pass करते हैं।"C:\\TURBOC3\\BGI"BGI Driver Directory का Path दर्शाता है। इस Path को अपने Computer में उपलब्ध वास्तविक Installation Directory के अनुसार बदलना चाहिए।
C Program to Initialize Graphics Mode Using initgraph()
The following program demonstrates how to initialize graphics mode and draw some basic graphical shapes using traditional BGI graphics functions.
निम्नलिखित Program में Traditional BGI Graphics Functions का उपयोग करके Graphics Mode Initialize करना तथा कुछ Basic Graphical Shapes बनाना प्रदर्शित किया गया है।
Program:
#include <graphics.h>#include <conio.h>#include <stdio.h>int main(void){int gd = DETECT, gm;int errorcode;initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");errorcode = graphresult();if (errorcode != grOk){printf("Graphics initialization failed: %s\n",grapherrormsg(errorcode));return 1;}line(50, 50, 250, 50);rectangle(50, 80, 200, 160);circle(300, 120, 50);ellipse(450, 120, 0, 360, 80, 40);outtextxy(150, 220, "Welcome to C Graphics");getch();closegraph();return 0;}
Output: A graphics window displays a line, rectangle, circle, ellipse and a text message.
आउटपुट: Graphics Window में एक Line, Rectangle, Circle, Ellipse तथा एक Text Message दिखाई देता है।
Explanation:
#include <graphics.h>includes the graphics library header file.#include <conio.h>is used for the traditionalgetch()function.gdandgmare variables used for graphics driver and graphics mode.initgraph()initializes the graphics system.graphresult()checks whether graphics initialization was successful.line()draws a line.rectangle()draws a rectangle.circle()draws a circle.ellipse()draws an ellipse.outtextxy()displays text at the specified coordinates.getch()waits for a key press.closegraph()closes the graphics system and returns to text mode.
व्याख्या:
#include <graphics.h>Graphics Library की Header File को Include करता है।#include <conio.h>का उपयोग Traditionalgetch()Function के लिए किया जाता है।gdतथाgmGraphics Driver और Graphics Mode के Variables हैं।initgraph()Graphics System को Initialize करता है।graphresult()यह जाँचता है कि Graphics Initialization सफल हुआ है या नहीं।line()एक Line बनाता है।rectangle()एक Rectangle बनाता है।circle()एक Circle बनाता है।ellipse()एक Ellipse बनाता है।outtextxy()निर्धारित Coordinates पर Text Display करता है।getch()किसी Key के Press होने की प्रतीक्षा करता है।closegraph()Graphics System को बंद करके Text Mode में वापस आता है।
Important Points About initgraph()
initgraph()is a function of the traditional BGI graphics library.It initializes the graphics driver and graphics mode.
DETECTis used for automatic graphics driver detection.The address operator (
&) is used to pass the addresses of the driver and mode variables.The BGI directory path must be correct for the selected graphics environment.
graphresult()can be used to check graphics initialization errors.closegraph()is used to close the graphics system.graphics.his not a standard C header file.initgraph()Traditional BGI Graphics Library का Function है।यह Graphics Driver तथा Graphics Mode को Initialize करता है।
Graphics Driver का Automatic Detection करने के लिए
DETECTका उपयोग किया जाता है।Driver तथा Mode Variables के Addresses Pass करने के लिए Address Operator (
&) का उपयोग किया जाता है।चुने गए Graphics Environment के अनुसार BGI Directory का Path सही होना चाहिए।
Graphics Initialization में Errors जाँचने के लिए
graphresult()का उपयोग किया जा सकता है।Graphics System को बंद करने के लिए
closegraph()का उपयोग किया जाता है।graphics.hStandard C Header File नहीं है।
Computer graphics in C allows programmers to create graphical shapes, display text and develop simple animations. The traditional BGI graphics library provides functions such as initgraph(), line(), rectangle(), circle() and ellipse() to perform graphics operations.
C Language में Computer Graphics के द्वारा Programmer Graphical Shapes बना सकते हैं, Text Display कर सकते हैं तथा Simple Animations तैयार कर सकते हैं। Traditional BGI Graphics Library में Graphics Operations के लिए initgraph(), line(), rectangle(), circle() तथा ellipse() जैसे Functions उपलब्ध होते हैं.
Comments
Post a Comment