Archived

This topic is now archived and is closed to further replies.

Graphics in C++

This topic is 5615 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am quite new to C++ and have learned the basics (objects, inheritence, pointers etc.). I am however having problems implementing any "graphics" at all. All I can do is write text. Is there an iostream class member I should use or something else obvious which I have missed. I would be grateful if you could help.

Share this post


Link to post
Share on other sites
Nothing of the kind. Assuming you''re working under Windows, the first thing you would have to do is switch from making console applications to Windows applications. Among other things, that means that you can''t use the normal IO streams for displaying text. If you''re using Microsoft VC, when creating a new Win32 app (or MFC, if you would prefer) tell it to create a simple "Hello world" application. That should show you a little bit about creating Windows applications.

For graphics, there are several options:
- the Windows GDI, easy but slow
- DirectX (DirectDraw for 2D stuff, Direct3D for 3D stuff)
- OpenGL
- other libraries, such as SDL, Allegro and what have you.

There''s a lot of information in the resources section.

Share this post


Link to post
Share on other sites
C++ is a programming language. It doesn''t define any graphics output by itself, in fact it doesn''t even define text output in the language itself (iostream is nothing but a convenience lib function set, it is not defined in the C++ core specifications).

To do graphics, you''ll need a graphics API. That''s simply a collection of functions or objects that let you access the graphics subsystem. Several such APIs are available. Some are multiplatform (they work on multiple OS''s and even non-x86 systems: SDL, OpenGL, etc), some are OS-specific (Windows: GDI, DirectDraw, D3D, etc).

So, your first step is to make a choice: Windows only, or platform independent ? The next choice is 2D or 3D. Since you are starting, 2D would be more appropriate. Assuming you use Windows, I''d suggest starting with simple GDI (or GDI+). There are lots of tutorials available on the net, the resource section of GDNet has some very good links/articles as well.

After you know the basics, you can move on to DirectDraw/SDL/Allegro, those are faster than GDI (a lot) but more complex. Once you feel ready (and have the required mathematical background knowledge), you can go 3D with OpenGL or Direct3D.

BTW: I''m moving this to the beginner forum.

/ Yann

Share this post


Link to post
Share on other sites
Well it really isn''t graphics, but with it you can do small ascii graphics, if windows is a little hard to understand right now, you can always try the windows console functions. I have made small games like Tetris with them. It really is not hard to understand, and I like them because they are like PreWindows. It gives you a nice little understanding how an API works, without to much to learn. If you are interested in these functions and structures Ill print them out for you here.

Jeff D

Share this post


Link to post
Share on other sites
I''ve said it before, and I''ll say it again, IMHO Allegro is the only way to go for an inexperienced programmer. You are ready to draw on the screen in about 5 function calls. Its really a no brainer. In second place would be SDL but I haven''t used it yet so I can''t say for sure.

Share this post


Link to post
Share on other sites