1

My question is that, how Can I draw one single pixel on the screen using C++ native libraries and functions? I mean not to use external functions or libraries. How is it possible?

Something Like this:

int rgb = {255,150,113};

nativeLibrary.drawPixel(0,1, rgb);

A fancy example just it is.

Mostafa Talebi
  • 8,825
  • 16
  • 61
  • 105

3 Answers3

4

You can't. C++ does not (yet) have any native graphics or GUI libraries.

user3553031
  • 5,990
  • 1
  • 20
  • 40
  • 1
    @MostafaTalebi that depends on what you want to achieve for some purposes is GDI better for other GL,DX for other even higher layers like SDL or some engines ... all comes to target platform, fps, 2D/3D/N-D and graphics type (bitmap,vector,volumetric....) – Spektre Aug 17 '14 at 07:37
  • I would add "does not have it, yet." It's coming. Stroustrup has wanted that for decades. – Max Lybbert Aug 17 '14 at 08:53
3

C++ may eventually add graphics into the standard (they were considering it), but for right now, the C++ standard does not include graphics.

You can take advantage of other standards in order to write a pixel to the screen, though. If you're on Linux, there is already an answer up.

If you're using VGA, you can actually write directly to the VGA buffer (WARNING: WAY OUTDATED Like "meant for DOS" outdated). You would probably use C++'s inline assembly to set the render mode instead of whatever that page uses, then use a regular unsigned char* instead of a "far" pointer to access it. Although you probably aren't using VGA and probably don't want to use assembly (especially inline assembly).

So what do you do outside of that? Nothing, really. You need to use an external library specifically to render, so probably OpenGL or DirectX or some library making use of either.

Community
  • 1
  • 1
Cave Dweller
  • 502
  • 2
  • 4
  • 17
1

Like the previous answer, there no native library to deal with images. However, if you are working in Windows API and particularly MFC, you may use CBitmap class.

Samer
  • 1,923
  • 3
  • 34
  • 54