graphics with C++

Started by
6 comments, last by bozkosko 21 years, 4 months ago
HI, i am pretty new to programming. I have been following the book: "teach yourself C++." I understand the basic idea of OOP, i have all the loops under my belt, i am familiar with pointers, references, simple classes - all the beginers stuff. Now i would like to try some simple graphics. I just want to be able to draw a rectangle, a circle, a line in C++ just like it was easy back in 80''s with Basic. Tell where to start please. Is DirectX the answer for me? If so where can i get good understanding of it or if you have some good book, please give me the name of it. I want to see some shapes and pixcels on my screen, not just numbers and characters. Where is the begining of graphics with c++?
Advertisement
You have to obtain a graphics API.

For something simple and DOS-like to use I suggest Allegro.

http://www.talula.demon.co.uk/allegro/

lets say that i already have Microsoft Visual C++ 6.0. Shouldnt i have some graphics API with it? Can you explain to me how to use those APIs?

If you want something simple and easy to use, you DON''T want the things you have with VC++. With VC++ is MFC 4(?) (powerful, but requires quite a bit of understanding of the organization) and DirectX3 (fast, but dirty setup code, no simple primatives). Use Allegro if you want something easy, as suggested.
You can use the windows API, but that is very confusing and you can end up with some ugly code (I''ve been programming with it for over a year and I''m still hacking with it).
-YoshiXGXCX ''99
He said something simple like lines or rectangles using VC++. I would think a sufficiently obvious suggestion would be basic GDI. The simplicity of such tasks is near that of old BASIC code, the caveat being that you must first understand how to setup basic WinMain and WndProc functions, which isn''t particularly hard. Read Petzold or find a tutorial on the web. You can do a few neat graphics tricks with GDI if you''re creative.
if you want the easiest route use mfc
file\new create a new workspace mfc appwizzard(exe) type in the project name "myprogram" click ok ,check the single document and click finish
then your workspace will appear in the dialog on your left click on fileview and click on source files and double click on the file "myprogramView" and locate the function OnDraw()
void myprogramView::OnDraw(CDC* pDC)
{
CmyprogramDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
add this line of code where it states // TODO: add draw code for native data here
Rectangle( 10, 10, 60, 60);
check out all the drawing functions under cdc
then click the button ! which executes the program

since you want the easiest way you might as well learn mfc
as far as books "visual c++ in record time by sybex" for the generalwindows and "programming vc++ 5th or 6th edition by microsoft press" for the indepth coverage.
Same Anon Poster again.

The reason I would suggest you do not use MFC is not that I don''t like it. I do like MFC; it''s just that I have seen beginner programmers use it and get frustrated. Similarlly, beginner programmers get frustraded with Windows programming (because they are the same thing under the hood).

If you do what jstoll said you will run into the following problem:
You can''t have "Frame based" animation, unless each frame involves covering up the window and then selecting it again.
This can be resolved with by constantly faking being covered up by calling a function called "InvalidateRect" (causing flickering) or by using a graphics feature called "Double Buffering", both of which I bet you don''t want to deal with.

So you probably want to get a library that does all the graphics stuff for you so you can practice the logic and learn to code. Later, you can use the Win32 APIs (by then it might be the Win64 API) and see it really isn''t all that bad.

There might be some other easy to use libraries on the web and http://directory.google.com/Top/Computers/Programming/Games/Libraries/?tc=1 appears to be a good starting point.

This topic is closed to new replies.

Advertisement