11 Replies - 45616 Views - Last Post: 25 February 2010 - 02:11 AM Rate Topic: -----

#1 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

How to use graphics.h in Code Block compiler?

Posted 24 February 2010 - 10:38 PM

Hallo. I want to use graphics.h in Code Block. How can I do it? Please help.
Is This A Good Question/Topic? 0
  • +

Replies To: How to use graphics.h in Code Block compiler?

#2 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: How to use graphics.h in Code Block compiler?

Posted 24 February 2010 - 10:51 PM

graphics.h is part of the Borland compiler I believe. Code::Blocks doesn't have graphics.h in its library. If you have a copy of the actual graphics.h file however, you could place it in your program directory and include it.
Was This Post Helpful? 0
  • +
  • -

#3 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 24 February 2010 - 11:09 PM

View Posteker676, on 24 February 2010 - 09:51 PM, said:

graphics.h is part of the Borland compiler I believe. Code::Blocks doesn't have graphics.h in its library. If you have a copy of the actual graphics.h file however, you could place it in your program directory and include it.

Thank you for your reply. I have copied graphics.h file in C:\Program Files\CodeBlocks\MinGW\include. Then if I just state #include <graphics.h> without using its consisting functions, no error. But when I create a new project say T1 whoes code is
#include <iostream>
#include <conio.h>
#include <math.h>
#include <stdlib.h>
#include <graphics.h>

using namespace std;

class DDA
{
	private :
		int X1;
		int Y1;
		int X2;
		int Y2;


	public :
		DDA() { }

		DDA(int X1, int Y1, int X2, int Y2)
		{
			this->X1 = X1;
			this->Y1 = Y1;
			this->X2 = X2;
			this->Y2 = Y2;
		}

	void Initialisation();
	void LineDraw();
	void Close();
};

void DDA:: Initialisation()
{
	int gDriver = DETECT;
	int gMode;
	initgraph(&gDriver, &gMode, "c:\\tc\\bgi");
	int errorcode = graphresult();

	if(errorcode != grOk)
	{
		cout <<"Graphics Error"<< grapherrormsg(errorcode) << "Press any key to halt.";
		getch();
		exit(1);
	}
}

void DDA:: LineDraw()
{
	int Dx;
	int Dy;
	int Steps;
	int X;
	int Y;
	int k;
	int Xinc;
	int Yinc;

	Dx = X2 - X1;
	Dy = Y2 - Y1;

	if(abs(Dx) > abs(Dy))
	{
		Steps = abs(Dx);
	}
	else
	{
		Steps = abs(Dy);
	}

	Xinc = Dx / Steps;
	Yinc = Dy / Steps;
	X = X1;
	Y = Y1;

	putpixel(X, Y, 10);

	for(k = 1; k <= Steps; k++)
	{
		X += Xinc;
		Y += Yinc;

		putpixel(X, Y, 1);
	}
}

void DDA:: Close()
{
	closegraph();
}

int main()
{
	DDA Obj(200, 100, 400, 300);

	Obj.Initialisation();
	Obj.LineDraw();

	getch();

	Obj.Close();

	return 0;
}


I got the following errors :
||=== T1, Debug ===|
obj\Debug\T1.o||In function `_ZN3DDA14InitialisationEv':|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|38|undefined reference to `_initgraph'|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|39|undefined reference to `_graphresult'|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|43|undefined reference to `_grapherrormsg'|
obj\Debug\T1.o||In function `_ZN3DDA8LineDrawEv':|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|77|undefined reference to `_putpixel'|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|84|undefined reference to `_putpixel'|
obj\Debug\T1.o||In function `_ZN3DDA5CloseEv':|
C:\Documents and Settings\Tapas\Desktop\T1\T1.cpp|90|undefined reference to `_closegraph'|
||=== Build finished: 6 errors, 0 warnings ===|

What should I do now?
Was This Post Helpful? 0
  • +
  • -

#4 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: How to use graphics.h in Code Block compiler?

Posted 24 February 2010 - 11:18 PM

You could try #include "graphics.h" but I don't think it will work. I'm sorry but the only surefire way to use the graphics header is to use Borland which is fairly outdated.
Was This Post Helpful? 0
  • +
  • -

#5 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 24 February 2010 - 11:31 PM

#include "graphics.h" did not work. Thank you.
Was This Post Helpful? 0
  • +
  • -

#6 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 12:02 AM

I have downloaded graphics.h from http://www14.brinkst...aditsu/console/. How can I use it?
Was This Post Helpful? 0
  • +
  • -

#7 eker676  Icon User is offline

  • Software Engineer
  • member icon

Reputation: 378
  • View blog
  • Posts: 1,833
  • Joined: 18-April 09

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 12:15 AM

Quote

To use graphics, #include <winbgim.h> or <graphics.h> and link with -lbgi -lgdi32


Include the file and add the switch to your linker.

Quote

Add the object-file to "Build options... -> Linker settings -> Other linker options:"

http://forums.codebl...p?topic=11912.0

This post has been edited by eker676: 25 February 2010 - 12:15 AM

Was This Post Helpful? 1
  • +
  • -

#8 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 12:47 AM

View Posteker676, on 24 February 2010 - 11:15 PM, said:

Quote

To use graphics, #include <winbgim.h> or <graphics.h> and link with -lbgi -lgdi32


Include the file and add the switch to your linker.

Quote

Add the object-file to "Build options... -> Linker settings -> Other linker options:"

http://forums.codebl...p?topic=11912.0

Thank you very much sir. It is a coincidence, I solved the problem and you give me the exact solution what I did. Thank you again.

Should I use initgraph(&gDriver, &gMode, "c:\\tc\\bgi") in Code Block or any other syntax?
Was This Post Helpful? 0
  • +
  • -

#9 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 01:41 AM

They're the same functions. There is no difference in syntax.
Was This Post Helpful? 0
  • +
  • -

#10 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 01:51 AM

I want to mean that since I have turbo c installed in my computer this initgraph(&gDriver, &gMode, "c:\\tc\\bgi") works well with CodeBlock. If I remove turbo c then compiling graphics program in CodeBlock what syntax of initgraph() should I use?
Was This Post Helpful? 0
  • +
  • -

#11 PlasticineGuy  Icon User is offline

  • mov dword[esp+eax],0
  • member icon

Reputation: 281
  • View blog
  • Posts: 1,436
  • Joined: 03-January 10

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 01:53 AM

The same one.

And please get rid of Turbo C.
Was This Post Helpful? 0
  • +
  • -

#12 Tapas Bose  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 23
  • View blog
  • Posts: 472
  • Joined: 09-December 09

Re: How to use graphics.h in Code Block compiler?

Posted 25 February 2010 - 02:11 AM

View PostPlasticineGuy, on 25 February 2010 - 12:53 AM, said:

And please get rid of Turbo C.

Oh sure. I don't like to use Turbo C and I never use it. My favourite compiler is Visual C++ 2008 Express.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1