Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to draw lines with C++?

Status
Not open for further replies.

asic1984

Full Member level 5
Full Member level 5
Joined
Nov 15, 2003
Messages
257
Helped
4
Reputation
8
Reaction score
1
Trophy points
1,298
Activity points
2,340
hi all

i need to know if there are any functions in c++ language that enable me to draw lines and sepcific points on a draw

if any one know how or what are the header file used and the functions
or any link that enable me to learn about that please tell me

thanks for your help
 

Hi,

There are instant libraries to draw 2D shapes but the most important point, which compiler do you use? On which platform do you develop application?

Analyzer.
 

Re: how to draw with c++

thanks first for your help

the program i use is visual studio 6
 

Re: how to draw with c++

i have c++ 5 builder (borland )
what is the header file i can use ????
 

Re: how to draw with c++

If you are want to develop for Microsoft Windows then look at the GDI and GDI+ and their associated API functions.

Informaiton on these is available on MSDN, but you can also download the Platform SDK which includes all documentation of the Win32 API which covers GDI and GDI+.

- Jayson
 

Re: how to draw with c++

And a link for the lazy ppl

hxxp://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/wingdistart_9ezp.asp

change hxxp to http after pasting in adres field of browser!

Antharax
 

Hi,
I'm not experienced on vc++6.0 but the logic is always same.You choose a canvas of an object and use Line, LineTo etc. functions.I also recommend you to use OpenGL.I'm using BC++Builder 4.0 and i can give you an example (@FireBird : This is for you too) :
Copy-Paste this codes to OnMouseDown event of your main form and run :

Canvas->MoveTo(0, 0);
Canvas->LineTo(X, Y);

Should look like this :

void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,

TShiftState Shift, int X, int Y)
{
Canvas->MoveTo(0, 0);
Canvas->LineTo(X, Y);
}

When you click on form, the code will draw a line from point 0,0 to clicked point.I hope this helps.

Analyzer.
 

for console application!

hi all

first thanks for your help

but i wanna point some things about what i wanna do

i wanna make a console application(it may appear foolish thing)but this is what required in a collage quiz

all what i wanna know is the header file used in drawing ....and the functions related for it ....asumming that the console application able to do that and if this impossible tell me please

but i ask about that because i know that some people done that before but how that is what i donnot know

so if any one know the header file and the related drawing functions for it please tell me

thanks for the help

speciall thanks for analyzer
 

Dear asic1984,

There are a lot of compiler around so please give name of your compiler.I used to code in TC++ 3.0 for console application.If you use the same compiler i have a *LOT* of source code what you desire.So lets start at the beginning and name your compiler ;)
Nothing is impossible.

Analyzer.
 

Re: how to draw with c++

First of all, if you are making a console application (i.e. not relying on anything with MS Windows) then:

There is no generic header file for what you want to do, typically most compilers (the ones for DOS) came with their own set of libraries, etc for graphics. Windows graphics programming on the other hand is much simpler by comparison as you do not have to worry about implementing the following:

1. you must first set your video mode
2. draw into the memory space.

To do this you could try DJGPP (which I think comes with graphics capabilities), or like Analyzer pointed out TC++ 3.0 which used the Borland Graphical Interface (BGI), all required drivers were supplied.

Or you could use Assembly programming for the low-level stuff, like set video mode, put pixel/get pixel and then use C++ to further abstract that.

- Jayson
 

Re: how to draw with c++

first thanks for help

i am using viusal c++6 as a compiler for console application

and i wanna know how to start dealing with graphics in consloe applications

thanks all for help

thanks analyzer and jayson
 

Re: how to draw with c++

Microsoft does not supply any header files or libraries whatsoever for making DOS based graphics from Visual Studio, I am not aware of any third party ones. You could however try using DirectX because it supports non-standard modes like 320x240, 640x400, etc, it would at least give the effect.

You can however make a Windows program that fills the entire screen, including the start menu.

Also, you aren't really making a console application, its still a Windows program.

If your program is to run without Windows running in the background, then you cannot use the Microsoft Visual C++ compiler because every compiled EXE must run under Windows, even the console programs compiled with the compiler.

You could always switch compilers, try openwatcom.org. WatCOM was the compiler ID Software used for games like DOOM. OpenWATCOM can compile 16-bit DOS programs which can access the BIOS, my understanding is that it also comes with all the original DOS based graphics libraries. Anyway it is a free download, give it a try.

- Jayson
 

Re: how to draw with c++

Look at hxxp://www.codeproject.com for sample code.
 

Re: how to draw with c++

hi all
firts thank for the help

i found a code which contains the desired solution of my problem but this code suppose to work with turpo c++ ....the problem is that he give an error message that the file....EGAVGA.BGI.....is missing

i need to know what is the solution for that i am using turpo c version 1

and this is the code

#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>

int main(void)
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;
char msg[80];

/* initialize graphics and local variables */
initgraph(&gdriver, &gmode, "");

/* read result of initialization */
errorcode = graphresult();
if (errorcode != grOk)
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1);
}
//PLACE YOUR PROGRAM HERE!!
//IF IT DOESN"T WORK TRY THIS
//OPTIONS=> Linker=> libraries, then make sure
//Graphics library is checked


/* move the C.P. to location (20, 30) */
moveto(20, 30);

/* create and output a
message at (20, 30) */
sprintf(msg, " (%d, %d)", getx(), gety());
outtextxy(20, 30, msg);

/* draw a line to (100, 100) */
lineto(100, 100);

/* create and output a message at C.P. */
sprintf(msg, " (%d, %d)", getx(), gety());
outtext(msg);

/* clean up */
getch();
closegraph();
return 0;
}



if any one found that the code work with any other version of turbo c and know a link for free download of it please send it

also now u may undertand what i mean about the header file and functions of it .....so i wanan ask if visual c++ 6 make a header file like graphics in turbo c

thanks for help
 

Re: how to draw with c++

A header file like graphics.h and associated functions are not and never will be available for the Microsoft C/C++ compiler that comes with Vistual Studio 6, you can however use the Visual Studio IDE for use with another compiler out there.

I suggest you look at OpenWATCOM or DJGPP, they are both free and source code is available for doing what you want or try to get Borland C++ 5.0 it was the last version to support DOS based graphics.

Have a look at: **broken link removed** especially tutorials 01 to 05.

- Jayson
 

Hi,

Have a look at this :
fxp://ftp.frontfree.net/Pub/DevTools/tcpp3.zip
I didnt download it but it seems to be fine.I used to write programs with tc++3.0 and now it is easier to write windows applications with borland c++ builder.By the way i would like to give an example on how to use graphich capabilities of tc++3.0 You can find how to init graph mode, draw 2d shapes and animate them.I downloaded this code from a web site but i can't remember the author.I'm sorry to write credits. I hope this will solve ur problems :

#include <stdlib.h>
#include <conio.h>
#include <graphics.h>
#include <dos.h>
#include <time.h>

// Macro to get a random integer within a specified range
#define getrandom(min, max) ((rand() % (int)(((max)+1) - (min))) + (min))
#define numflakes 300

void main(void)
{
unsigned int r;
unsigned int snow [numflakes+1] [2];
int gd=DETECT,gm;

initgraph(&gd,&gm,"");

setcolor(5);
outtextxy(120,200,"This is a demo for a snow-fall effect in TC30");

cleardevice;
setcolor(5);
moveto(10,300);
lineto(30,330);
moveto(10,301);
lineto(30,331);
moveto(35,340);
lineto(15,370);
moveto(35,341);
lineto(15,371);

setcolor(1);
//ellipse(_GBORDER, 175, 301, 225, 327);
circle(520, 275, 20);

setcolor(12);
rectangle(350, 250, 240, 300);
rectangle(351, 251, 241, 301);

setcolor(13);
moveto(450,310);
lineto(480,350);
lineto(420,350);
lineto(450,310);
moveto(419,350);
lineto(449,310);

/* Seed the random number generator with current time. */
srand((unsigned)time(NULL));
for (r=1; r<numflakes; r++) {
snow[r] [1] = getrandom(1, 639); // newone x
snow[r] [2] = getrandom(1, 479); // newone y
}

do {
for (r=1; r<numflakes; r++) {
(snow [r] [2])++;
if (getpixel(snow [r] [1], snow [r] [2]) != 0) {
if ((getpixel(snow [r] [1] + 1, snow [r] [2]) == 0) && (snow [r] [1] < 640)) {
(snow [r] [1])++;
setcolor(0);
putpixel(snow [r] [1] - 1, snow [r] [2] - 1,BLACK);
setcolor(15);
putpixel(snow [r] [1], snow [r] [2],WHITE);
goto nextloop;
} else
if ((getpixel(snow [r] [1] - 1, snow [r] [2]) == 0) && (snow [r] [1] > 0)) {
(snow [r] [1])--;
setcolor(0);
putpixel(snow [r] [1] + 1, snow [r] [2] - 1,BLACK);
setcolor(15);
putpixel(snow [r] [1], snow [r] [2],WHITE);
goto nextloop;
}
snow [r] [2] = getrandom(1, 10);
snow [r] [1] = getrandom(1, 639); // newone x
goto nextloop;
}
if (snow [r] [2] > 479) {
snow [r] [2] = getrandom(1, 10);
snow [r] [1] = getrandom(1, 639); // newone x
} else {
// setcolor(0);
putpixel(snow [r] [1], snow [r] [2] - 1,BLACK);
// setcolor(15);
putpixel(snow [r] [1], snow [r] [2],WHITE);
}
nextloop:;
}
delay(10);
} while (!(kbhit()));

closegraph();
exit(0);
}
 

Hi

I hae used both MS VisualC++ and turbo C++ . for console app graphics .. its best to use TurboC++ . you can use the header file graphics.h which provides number of function for graphic using BGI(borland graphical interface).

Regards
Asterix
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top