Ad Code

Introduction Of Graphics in C/C++.

Graphics in C/C++

In this tutorial, we will discuss Graphics in C language and C++.

Using graphics in C is very easy and interesting. You can use standard library functions, but every graphics program should include "graphics.h" library. There are many functions available for graphics programming, including:

initgraph(): This function is used to initialize the graphics mode. Its syntax is:

initgraph(&graphicdriver, &graphicmode, "path");

graphresult(): This function returns an error code.

grapherrormsg(): This function returns an error message string.

outtext(): This function displays a string on the screen.

outtextxy(): This function displays a string at specific points (x,y) on the screen.

Graphics in C++ is also very similar to graphics in C. However, it is more object-oriented, and you can use classes and objects to create graphical applications. Some of the popular C++ graphics libraries are SDL, OpenGL, and SFML.

Using graphics in C/C++ can be a fun and rewarding experience, and can lead to creating visually appealing programs and games.

Our First Program :

 #include<studio.h>
 #include<conio.h>
 #include<graphics.h>
 #include<stdlib.h>
 int main()
  {
   int gd = DETECT, gm, error;
   initgraph(&gd, &gm, "C:\\TC\\BGI");
   error = graphresult();
   if(error!=grOk)
   {
   printf("graphs error %s", grapherrormsg(error);
   exit(1);
   }
   outtext("code&coding");
           outtextxy(50,50,"code&coding");
   getch();
   return 0;
   }


So, we are learnt basic of graphics in C language in this tutorial. You can use this code source in C++. I hope this tutorial was useful for you. Please share your friends.

In next tutorial we will discuss about some shapes in Graphics in C.

Thank you !

Post a Comment

0 Comments

Ad Code