开发者

Visual Studio 2010 C++ console applications

I am new to C++ and I would like to know what the limitations are in graphics for a console application. For example---Could I create something as compicated as some of the very colorful screensavers that have all kinds of splashes of color?? Could I draw lines of cha开发者_JS百科nging color based on input strings??? I would appreciate any advice someone could give me.

Thanks Doug


If you want to do some serious animation you'll pribably want hardware accelerated graphics (DirectX, OpenGL). If you just want simple images and animations a GUI app would do. As far as the console it's not really intended for more than text output but it can draw lines and change colors if you really want too.

However none of the three are limitations of C++ ... C++ as a language does not care about graphics that would be an OS limitation primarily and you'll find most of your drawing code however you go about it will be somewhat OS or hardware dependent unless you use a cross platform library with GUI or graphics support like QT, wxWidgets, OpenGL, etc.


As others have said, a console application is for text, not graphics! I don't know of any way (or reason) to do graphics in a console.

To do the kinds of things you are interested in (except maybe Windows screensavers) using Visual C++, I would recommend starting off with the SDL library. The Lazy Foo Productions website has an excellent series of game programming tutorials, and the first lesson gives you a step-by-step guide to build an app that displays stuff on the screen. It even has screenshots showing how to configure Visual Studio 2010, which is pretty important if you're new to this kind of thing.

SDL is free, cross-platform, and will let you (within your program's window):

  • draw pixels, lines, and rectangles in any color
  • draw text
  • draw images
  • make animations (by changing/redrawing the screen many times per second)
  • obtain keyboard input (including when keys are released)

It will also let you do 3D graphics with OpenGL, but that's another story.


You could, if you're very desperate- but certainly not platform-independently. From memory, the Windows API is quite good about letting you do a lot of crazy shit to it's console. However, it's probably better advised to get a genuine graphical API for this purpose, such as GDI, DirectX or OpenGL.


C++ does not have any standard facilities for drawing graphics in a console application. Any features (like changing the font color) will depend on your OS. I doubt you will find functions that do much more than changing the text color though. (For example, on Windows you would use system("color xx") to change the foreground and background color.)

Basically, if you want graphics you're going to have to abandon the console application and look for a graphics API.


Could I create something as compicated as some of the very colorful screensavers that have all kinds of splashes of color??

If by "splash" you mean "chunk of text", then yes. Otherwise no.

Could I draw lines of changing color based on input strings???

No, consoles are textual media.

If you want to try to do things to the console you need to use the Windows Console Functions. Standard C++ does not have any way to change console color.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜