By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

Graphics in C++ using Borland

P: n/a
Pmb
At the moment I'm using Borland's C++
(http://www.borland.com/products/down...cbuilder.html#)

I want to be able to take an array of points and plot them on the screen. Is
there a way to do this? E.g. I want to be able to graph a function. At this
point I'm not up to a level in C++ where I want to start learning Visual C++
so I don't want to go that route.

Thanks

Pmb
Jul 22 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Pmb <so*****@somewhere.com> spoke thus:
I want to be able to take an array of points and plot them on the screen. Is
there a way to do this? E.g. I want to be able to graph a function. At this
point I'm not up to a level in C++ where I want to start learning Visual C++
so I don't want to go that route.


(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++. Please visit

http://www.slack.net/~shiva/welcome.txt
http://www.parashift.com/c++-faq-lite/

for posting guidelines and frequently asked questions. Thank you.

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Jul 22 '05 #2

P: n/a
Hi Pmb ( Pete ),

You mentioned,
" I want to be able to take an array of points
and plot them on the screen. "

You need to create a window and then get
the device constant, HDC, of that window.
You also need a pen, HPEN.

Note, this is a Win32 project, not a console project.

Below are a few code snippets that might help you.

long __stdcall
WinProc ( HWND Wnd, uint WM, uint wp, long lp ) {
return DefWindowProc( Wnd, WM, wp,lp ); }

int __stdcall WinMain ( HINSTANCE inst,
HINSTANCE PID, LPSTR CmdLn, int x1 ) {

HPEN Pen = CreatePen( PS_SOLID, 0, RGB( 255, 0, 0 ) );
HBRUSH Black = CreateSolidBrush ( RGB( 0, 0, 0 ) );
{ WNDCLASS Class = {
0, WinProc, 0, 0, PID, 0, 0, Black, 0, "WinProc" };
RegisterClass( & Class ); }

int Left_Scr, Top_Scr, W_Me, H_Me, Right_Scr, Bot_Scr ;
{ long R[ 4 ];
SystemParametersInfo(
SPI_GETWORKAREA, 0, ( RECT * ) R, 0 );
Right_Scr = R [ 2 ]; Bot_Scr = R [ 3 ];
R [ 2 ] -= R [ 0 ]; R[ 3 ] -= R [ 1 ];
Left_Scr = R [ 0 ]; Top_Scr = R [ 1 ];
W_Me = R [ 2 ]; H_Me = R [ 3 ]; }

HWND Win = CreateWindow "WinProc", "Some Title",
WS_VISIBLE, Left_Scr, Top_Scr,
W_Me, H_Me, 0, 0, PID, 0 );

HDC DC = GetDC( Win );

int x, y ;
MoveToEx ( DC , x = 100, y = 200, 0 );
LineTo ( DC, x = 200, y = 300 );
ReleaseDC( Win, DC);

MSG Msg;
while ( GetMessage( & Msg, 0,0,0) {
TranslateMessage( & Msg ); DispatchMessage( & Msg );

unsigned int M = Msg.message, C = Msg.wParam ;
if ( M == WM_KEYDOWN && C == 27) return 1;
}

}
Jul 22 '05 #3

P: n/a
Pmb

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:c9**********@chessie.cirr.com...
Pmb <so*****@somewhere.com> spoke thus:
I want to be able to take an array of points and plot them on the screen. Is there a way to do this? E.g. I want to be able to graph a function. At this point I'm not up to a level in C++ where I want to start learning Visual C++ so I don't want to go that route.


(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++.


It's not off topic since I want to learn how to do this in C++.

<snip unhelpful comments>

Pmb
Jul 22 '05 #4

P: n/a
Pmb wrote:

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:c9**********@chessie.cirr.com...
Pmb <so*****@somewhere.com> spoke thus:
I want to be able to take an array of points and plot them on the screen. Is there a way to do this? E.g. I want to be able to graph a function. At this point I'm not up to a level in C++ where I want to start learning Visual C++ so I don't want to go that route.


(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++.


It's not off topic since I want to learn how to do this in C++.


Hmm. I checked the C++ standard and there is nothing mentioned
about graphics.

The fact that you used C++ is completely unimportant in your case.
Your problem is not about C++ but about doing graphics. C++ in
this case is just the tool to do something. Using the same
logic I could argue that Einsteins theory of relativity is on
topic, since I use C++ to implement some equations from that
theory.

Not everything with C++ in it is on topic in this group.

Please check:
http://ma.rtij.nl/acllc-c++.FAQ.html#q1.6
comp.lang.c++ follows the same rules as alt.comp.lang.learn.c-c++
with respect to this.

--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #5

P: n/a
Pmb

"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Pmb wrote:

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message news:c9**********@chessie.cirr.com...
Pmb <so*****@somewhere.com> spoke thus:

> I want to be able to take an array of points and plot them on the screen. Is
> there a way to do this? E.g. I want to be able to graph a function.
At this
> point I'm not up to a level in C++ where I want to start learning
Visual C++
> so I don't want to go that route.

(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++.


It's not off topic since I want to learn how to do this in C++.


Hmm. I checked the C++ standard and there is nothing mentioned
about graphics.

The fact that you used C++ is completely unimportant in your case.


I disagree.
Your problem is not about C++ but about doing graphics.


That is incorrect. A topic on doing graphics is a topic on the algorithms
and techniques of graphics. I don't want to know that. I want to know the
nuts and bolts of function calls and how to use C++ to get the system to do
graphics

<snip incorrect analogy>

I have a text called "Numerical Methods in C" which shows how to do this. I
can't follow the code. I want to find a place/material in which something
similar is done and explained in term of C++.

And I understand what is and is not on topic. Sometimes people disagree
about what is or is not on topic. I do not post messages which I consider to
be off topic.

If you consider this off topic then please do not respond. I do not consider
this off topic.

Pmb
Jul 22 '05 #6

P: n/a

"Pmb" <so*****@somewhere.com> wrote in message
news:cb********************@comcast.com...

"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in message
news:c9**********@chessie.cirr.com...
Pmb <so*****@somewhere.com> spoke thus:
I want to be able to take an array of points and plot them on the screen. Is there a way to do this? E.g. I want to be able to graph a function.
At
this point I'm not up to a level in C++ where I want to start learning
Visual
C++ so I don't want to go that route.


(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++.


It's not off topic since I want to learn how to do this in C++.


If you'd just click on those links and read the welcome message and faq,
then you'd know that your question *is* off-topic here. This group
discusses the C++ language as defined by the standard, not how to use C++ to
accomplish platform-specific tasks.

Using just functions and classes available in standard C++, there is no way
to accomplish what you've asked. There simply are no graphics functions in
C++. There *are* such functions in various implementations (such as VC++),
as add-ons and third-party API's, but those are specific to the
implementation, and to the platform.

You need to ask in a newsgroup devoted to the compiler (e.g., on the
newsgroups.borland.com server) or the platform (e.g., on the
news.microsoft.com server) to find out how to do things specific to their
software.

-Howard
Jul 22 '05 #7

P: n/a
Pmb wrote:

The fact that you used C++ is completely unimportant in your case.
I disagree.


It is.
Your problem is not about C++ but about doing graphics.
That is incorrect. A topic on doing graphics is a topic on the algorithms
and techniques of graphics. I don't want to know that. I want to know the
nuts and bolts of function calls and how to use C++ to get the system to do
graphics


Then the answer is: there is no such thing. At least not in the context
of this group.

<snip incorrect analogy>

I have a text called "Numerical Methods in C" which shows how to do this. I
can't follow the code. I want to find a place/material in which something
similar is done and explained in term of C++.

And I understand what is and is not on topic.
Obviously not.
Sometimes people disagree
about what is or is not on topic. I do not post messages which I consider to
be off topic.

If you consider this off topic then please do not respond. I do not consider
this off topic.


Talking about topicality is always on topic per definition.
--
Karl Heinz Buchegger
kb******@gascad.at
Jul 22 '05 #8

P: n/a
Hi Pmb ( Pete ),

Because Direct Draw 7 can do VRAM to VRAM blts,
I always use it when I need to do graphics.

DD 7 is a C++ API ( Framework ).

But unlike OpenGL, it comes preloaded on almost all PC's.
( Google: define:OpenGL . Also: "Direct Draw 7" )

However, the API doesn't really teach a lot of C++ stuff,
it doesn't seem all that different from plain C.

The following will give you
a small taste of what it looks like:

#define _SurT LPDIRECTDRAWSURFACE7

LPDIRECTDRAW7 Direct_Draw;
LPDIRECTDRAW _Direct_Draw;
DDSURFACEDESC2 Z;
_SurT Sur_Scr, Sur_Draw, Sur_Cur, Sur_Font;
BITMAP BMH; DDBLTFX ErBlack, ErSel, ErOdd;
DDCOLORKEY BlueKey;

DirectDrawCreate( 0, & _Direct_Draw, 0 );
_Direct_Draw->QueryInterface(
IID_IDirectDraw7, (VOID**) & Direct_Draw );
if ( ! _Direct_Draw ) Fatal( "No Direct Draw 7");
Direct_Draw->SetCooperativeLevel( Win, DDSCL_NORMAL );
memset( & Z, 0,sizeof( Z )); Z.dwSize = sizeof Z;
Z.dwFlags = DDSD_CAPS;
Z.ddsCaps.dwCaps= DDSCAPS_PRIMARYSURFACE;
Direct_Draw->CreateSurface( & Z, & Sur_Scr, 0 );
ErBlack.dwSize =
ErSel.dwSize = ErOdd.dwSize = sizeof ErBlack;
ErSel.dwFillColor = Get_Color( Sur_Scr, RGB( 0, 66, 0 ) );
ErOdd.dwFillColor =
Get_Color( Sur_Scr, RGB( 0, 128, 128 ) );
Z.dwFlags |= DDSD_HEIGHT | DDSD_WIDTH;
Z.ddsCaps.dwCaps = DDSCAPS_VIDEOMEMORY;
Z.dwWidth = W_Me; Z.dwHeight = H_Me;
Direct_Draw->CreateSurface( & Z, & Sur_Draw, 0 );
if ( ! Sur_Draw ) {
DDCAPS Caps; Caps.dwSize = sizeof Caps;
Direct_Draw->GetCaps( & Caps, 0 );
Fatal( "No VRAM for back buffer\n"
"Needed: %3.1f MegaBytes\nNot: %3.1f MegaBytes\n",
W_Me * H_Me * 4 / A_Meg,
Caps.dwVidMemFree / A_Meg ); }
Z.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
Z.ddsCaps.dwCaps2= DDSCAPS2_TEXTUREMANAGE;
int K = Get_Color(Sur_Scr,_Blue); DDCOLORKEY KK = { K, K }; BlueKey = KK;

And on and on ...
Jul 22 '05 #9

P: n/a
Pmb wrote:
"Karl Heinz Buchegger" <kb******@gascad.at> wrote in message
news:40***************@gascad.at...
Pmb wrote:
"Christopher Benson-Manica" <at***@nospam.cyberspace.org> wrote in
message
news:c9**********@chessie.cirr.com...

Pmb <so*****@somewhere.com> spoke thus:
>I want to be able to take an array of points and plot them on the

screen. Is

>there a way to do this? E.g. I want to be able to graph a function.
At
this

>point I'm not up to a level in C++ where I want to start learning
Visual
C++

>so I don't want to go that route.

(newsgroups.borland.com would be glad to help.)

Your post is off-topic for comp.lang.c++.

It's not off topic since I want to learn how to do this in C++.


Hmm. I checked the C++ standard and there is nothing mentioned
about graphics.

The fact that you used C++ is completely unimportant in your case.

I disagree.

Your problem is not about C++ but about doing graphics.

That is incorrect. A topic on doing graphics is a topic on the algorithms
and techniques of graphics. I don't want to know that. I want to know the
nuts and bolts of function calls and how to use C++ to get the system to do
graphics

<snip incorrect analogy>

I have a text called "Numerical Methods in C" which shows how to do this. I
can't follow the code. I want to find a place/material in which something
similar is done and explained in term of C++.

And I understand what is and is not on topic. Sometimes people disagree
about what is or is not on topic. I do not post messages which I consider to
be off topic.

If you consider this off topic then please do not respond. I do not consider
this off topic.

Pmb


The usage of the language, such as which containers to use for graphics
is topical. How to actually draw the pixels isn't.

Perhaps it is time for another one of my graphics rants. You can search
this newsgroup and news:comp.lang.c for my rants on why graphics, color
and displays are not topic. I'll be brief this time.

First off, C++ does not assume nor demand any platform to support
graphics. One can use C++ to program a vending machine, which has
no display. One can also use C++ to program video games or image
processing. However, anything beyond the actual language is off-topic
for this newsgroup. There are newsgroups that love to discuss graphic
algorithms and platform specific groups that discuss how to draw a
a pixel.

Back to the rant. Secondly, there is no standard for graphics. There
was a Graphics Kernel System, but that is more along theory than
implementation. Let us take a small sample, say the Microsoft Windows
PCs. There is no standard as to pixel organization. The operating
system has many different file formats to support this. Here are some
issues:
1. Colors per pixel (assuming a platform can support colors).
Some systems support one (Black / white), others have 3 or more.
2. Values per color. How many values per color? 24 bit? 8 bit?
3. Color mapping / scheme, which one:
RGB, CMYK, HSB?
4. Vector graphics?
5. Layers or planes. There is no standard for multiple planes,
nonetheless, drawing operations on planes (i.e. translucent,
opaque, blend, etc.).

Let's say that Microsoft has a standard. Can I take a simple program
that draws a toroid in purple and run that on Windows 95, 98, 2000,
ME, XP, and CE and have it display the same?
Can I take the same program, compile and run it on a Linux system?
Can I take the same program, compile and run it on a VAX system?
Can I take the same program, compile and run it on a Ninetendo Game
Cube?

However, I can take a conforming C++ program, compile it on a
supporting (hosted) platform and have it produce the same results.
This is what standardization provides.
--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.raos.demon.uk/acllc-c++/faq.html
Other sites:
http://www.josuttis.com -- C++ STL Library book

Jul 22 '05 #10

P: n/a
This group is about Standard C++. Both the language and the standard
library have no concept of "graphics". Therefore, it is off-topic.

!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Jul 22 '05 #11

P: n/a
> Hi Pmb ( Pete ),

You mentioned,
" I want to be able to take an array of points
and plot them on the screen. "

You need to create a window and then get
the device constant, HDC, of that window.
You also need a pen, HPEN.

Note, this is a Win32 project, not a console project.

Below are a few code snippets that might help you.

<code snippets snipped>

In the code snippets, you have used a lot of names that you haven't
declared and aren't part of the Standard Library. BTW, : "Names
beginning with an underscore and a capital letter or two underscores
are reserved for use by the implementation and shall not be used
otherwise." (This isn't an exact quote from the standard, but it says
something along those lines). So, you should avoid using names like
__stdcall beginning with 2 underscores. Anyway, the declaration:

long __stdcall
WinProc ( HWND Wnd, uint WM, uint wp, long lp ) {
return DefWindowProc( Wnd, WM, wp,lp ); }

(apart from the undeclared identifiers), certainly seems like a syntax
error, unless some clever macros are invloved.

BTW, this group is about Standard C++ and there are no graphics in
Stdandard C++.
Jul 22 '05 #12

P: n/a
Hi Prateek R Karandikar,

I showed:
long __stdcall
WinProc ( HWND Wnd, uint WM, uint wp, long lp ) {
return DefWindowProc( Wnd, WM, wp,lp ); }

And you commented,
" ( apart from the undeclared identifiers ),
[ that ] certainly seems like a syntax error,
unless some clever macros are involved. "

What undeclared identifiers ?

uint is an unsigned int ... is that what you meant ?

Wnd, WM, wp,lp are all declared in the parameter list.

__stdcall and DefWindowProc() are from Windows.H.
Jul 22 '05 #13

P: n/a
Jeff Relf wrote:
__stdcall and DefWindowProc() are from Windows.H.


When I #include <windows.h>, I get an error indicating that that include
file wasn't found.

Perhaps you might discuss this on a VC newsgroup instead of a group
dedicated to Standard C++?
Jul 22 '05 #14

P: n/a
> Hi Prateek R Karandikar,

I showed:
long __stdcall
WinProc ( HWND Wnd, uint WM, uint wp, long lp ) {
return DefWindowProc( Wnd, WM, wp,lp ); }

And you commented,
" ( apart from the undeclared identifiers ),
[ that ] certainly seems like a syntax error,
unless some clever macros are involved. "

What undeclared identifiers ?

uint is an unsigned int ... is that what you meant ?

Wnd, WM, wp,lp are all declared in the parameter list.

__stdcall and DefWindowProc() are from Windows.H.


There is no standard typedef uint for unsigned int. There is no
standard header Windows.H
Jul 22 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.