I've been looking everywhere but cannot find an answer, is it possible to draw a pixel in C++ without a library, to the console, where I decide where to plot it(x,y).If not, how does a library manage to do this, I read it had something to do with the library gaining access to the drivers on the computer, but even then its still part of the C++ program.By the way I have never had formal programming education so this may seem silly.
Asked
Active
Viewed 2,996 times
-1
-
4C++ doesn't have a notion of a console. Each platform will have its own way of interacting with one. – chris Feb 05 '15 at 17:27
-
I'm guessing you're on Windows? By pixel, do you mean "character in the console", or do you mean an actual pixel in a normal window? – Cameron Feb 05 '15 at 17:29
-
1Actual pixel, and I use both Windows and Linux. – Apprentice Coder Feb 05 '15 at 17:30
-
See [this](http://stackoverflow.com/questions/12378642/c-pixels-in-console-window) question. – Axalo Feb 05 '15 at 17:32
-
I saw that, but it wasnt exactly what I was looking for, do you know of the library to do that on linux? – Apprentice Coder Feb 05 '15 at 17:36
-
It's not really a standard thing to do and is OS dependent (maybe even platform dependent), based on how it implements its graphical interface. The OS probably won't let you change what colours are being displayed on each pixel, that is being controlled at a very low level. An alternative would be to use OpenCV to open a window in which you can display any image you want – texasflood Feb 05 '15 at 17:41
-
1If coding in C++ for both Windows & Linux, you might consider using [Qt](http://project-qt.org/) – Basile Starynkevitch Feb 05 '15 at 17:50
-
Ok I know C++ but have not learned it formally, in reply to the smart alec above, that analogy fails too. I taught myself from tutorials and just messing around building different projects, if I could take serious classes I would, but i'm still in high school, that's not even a rude comment it's just arrogant and non constructive. Why even respond when an answer was given below?lol thanks anyways. – Apprentice Coder Feb 05 '15 at 19:43
1 Answers
3
This is possible, but highly dependendt on your operation system. You will have to use the OS API, because the C++ standard in itself doesn't have any idea of that kinda stuff.
For example, Windows has the SetPixel function that can be used on the console window. You can get the console window by using GetConsoleWindow and its context using GetDC.
That said, it's one of the less orthodox things to do, not portable and hard to predict - redraws of the console window will erase your content. Reconsider your options, and think about whether using a library might not be the better idea.

Daerst
- 954
- 7
- 24
-
If you absolutely need to draw on the console window, you should probably at least use your own window above it. There's no telling how well other windows will react to you drawing on them. – chris Feb 05 '15 at 17:32
-
I wanted to write some functions to draw shapes filled with a color that would work on linux and Windows out of couriosity. – Apprentice Coder Feb 05 '15 at 17:41
-
Use a GUI framework. Most frameworks are portable between Linux and Windows. – Thomas Matthews Feb 05 '15 at 17:52