Drawing pixels with C++

D.V.D

Make a wish
Reaction score
73
I've seen many functions in tutorials such as putpixel(...) but they do not specify which library in C++ gives you this function. I looked around at the Cplusplus.com library's and couldn't find a library that provides the user the ability to draw a pixel. I do not want to import a whole library with 3d capabilities and what not like OpenGL as I wanna try to make images and stuff like that from scratch. Any help?
 

Vestras

Retired
Reaction score
248
I've seen many functions in tutorials such as putpixel(...) but they do not specify which library in C++ gives you this function. I looked around at the Cplusplus.com library's and couldn't find a library that provides the user the ability to draw a pixel. I do not want to import a whole library with 3d capabilities and what not like OpenGL as I wanna try to make images and stuff like that from scratch. Any help?

I'm pretty sure putpixel is a part of allegro.
 

D.V.D

Make a wish
Reaction score
73

Intresting, but does that only support windows or does it work on linux/mac?

And would it be quicker to use Direct X instead of that windows library?

EDIT: I just saw a few video's showing how OpenGL is better than Direct X, only problem is I don't want to import a huge library filled with hundreds of functions when all I need is a SetPixel function, getpixel, and clear pixel.
 

Vestras

Retired
Reaction score
248
Intresting, but does that only support windows or does it work on linux/mac?

And would it be quicker to use Direct X instead of that windows library?

EDIT: I just saw a few video's showing how OpenGL is better than Direct X, only problem is I don't want to import a huge library filled with hundreds of functions when all I need is a SetPixel function, getpixel, and clear pixel.

SetPixel is Windows only, yes, but if you want it to be cross-platform, say you want to support Mac and Linux too, you can just make a wrapper for the pixel functions and then inside the wrapper funcs, based on the current platform, call the current platform's equivalent.

Also, many would argue that OpenGL isn't better than Direct X.
 

D.V.D

Make a wish
Reaction score
73
Would I need to know assembly or something for that? And are the only possibilities for me to use pixel functions are to use huge graphic library's like direct x and opengl? Cause ive been looking all over the internet but the only pixel functions available are from huge graphic and math library's.

Direct X seems to have advantages over OpenGl and OpenGl has its own performance advantages. The biggest difference however is that OpenGL is cross platform which is a huge advantage over Direct X which will only support windows.
 

Vestras

Retired
Reaction score
248
Would I need to know assembly or something for that? And are the only possibilities for me to use pixel functions are to use huge graphic library's like direct x and opengl? Cause ive been looking all over the internet but the only pixel functions available are from huge graphic and math library's.

Direct X seems to have advantages over OpenGl and OpenGl has its own performance advantages. The biggest difference however is that OpenGL is cross platform which is a huge advantage over Direct X which will only support windows.

No, not at all. You code just do something like: (pseoducode)
Code:
void draw_pixel(int x, int y, PIXEL pixel) {
#if WINDOWS
    SetPixel(...); // Windows pixel drawing function call
#elseif MAC
    draw_pixel(...); // Mac pixel drawing function call (not sure about the name)
// and so on...
#endif
}
 

D.V.D

Make a wish
Reaction score
73
Yeah but what would be the widows/mac draw pixel function calls if they don't exist in C++?
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
To elaborate on what Vestras wrote:

Code:
#ifdef _WIN32 // note the underscore: without it, it's not msdn official!
#include <Windows.h>
#elif __APPLE__  // Mac OS
#include <MacGraphics>
#endif

void PlaceAPixel ( int x, int y ){

#ifdef _WIN32
    SetPixel( x, y, blah );
#elif _APPLE__
    SetMacPixel( x, y, blah );
#endif

}

So you use preprocessor definitions to include the right libraries and write a wrapper for easier use.

Just remember that this is conditional compilation!
The program, if compiled on a Windows machine, will only work on Windows.
You need to compile it on a Mac in order to create a build that works on Macs.

The conditional definitions can only be used so you don't have to actually change anything in the source code when compiling it on a different machine.
 

D.V.D

Make a wish
Reaction score
73
If I understood correctly, by having conditions that tell the computer what library's to load, you will have to reinstall the program if you switch from mac to windows on the same computer?

And if I did use such a function, would I have to create my own C++ library that has the above code? Or is this done in another language? (pseudocode thing?)
 

s3rius

Linux is only free if your time is worthless.
Reaction score
130
If I understood correctly, by having conditions that tell the computer what library's to load, you will have to reinstall the program if you switch from mac to windows on the same computer?

And if I did use such a function, would I have to create my own C++ library that has the above code? Or is this done in another language? (pseudocode thing?)

About the first:
Reinstalling isn't exactly right. When you compile and build your exe with your IDE (say Visual Studio or GCC) you get a exe file which is built to be able to run on your type of system only. So if you compile on a Windows machine your program will import Windows.h and use Window's functions.
If you let someone compile your project on a Mac he'll get a exe (or whatever file they use lolz) that'll be made specifically for Mac.

That's why you can choose between downloading a Mac or Windows version of many programs in the internet.
When a user installs the program he just needs to make sure to get the right version of it. A Mac version won't work on a Windows PC.

And no, you don't have to write your own library. The Windows.h and MacGraphics library and standard libraries for Windows/Mac systems (I guessed the Mac name, I have no clue of Mac-specific programming). So they're existent from the start.
You just make a condition so the right libraries will be included during compilation.

That's quite a bit of organizational work actually. Since you probably don't have a Mac and a Windows at home to test both of the conditional branches.
And there's probably much more to it. If you're not using a library you need to use native commands to create a window to draw in (or you need to get the handle of the desktop if you want to draw onto there directly). These commands are most probably not the same for the two systems. So you'll probably have to rewrite quite a bit of code to have it work for different systems (that's why people generally use wrappers for that, so they don't have to rewrite all the stuff inside their main functions).
 

D.V.D

Make a wish
Reaction score
73
Hmm I see. Ill focus on PC right now as thats all I have now. I wanna learn how to get programs to work on both systems incase it comes handy in the future. Thanks for the help S3rius and Vestras :D +rep.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • The Helper The Helper:
    So what it really is me trying to implement some kind of better site navigation not change the whole theme of the site
  • Varine Varine:
    How can you tell the difference between real traffic and indexing or AI generation bots?
  • The Helper The Helper:
    The bots will show up as users online in the forum software but they do not show up in my stats tracking. I am sure there are bots in the stats but the way alot of the bots treat the site do not show up on the stats
  • Varine Varine:
    I want to build a filtration system for my 3d printer, and that shit is so much more complicated than I thought it would be
  • Varine Varine:
    Apparently ABS emits styrene particulates which can be like .2 micrometers, which idk if the VOC detectors I have can even catch that
  • Varine Varine:
    Anyway I need to get some of those sensors and two air pressure sensors installed before an after the filters, which I need to figure out how to calculate the necessary pressure for and I have yet to find anything that tells me how to actually do that, just the cfm ratings
  • Varine Varine:
    And then I have to set up an arduino board to read those sensors, which I also don't know very much about but I have a whole bunch of crash course things for that
  • Varine Varine:
    These sensors are also a lot more than I thought they would be. Like 5 to 10 each, idk why but I assumed they would be like 2 dollars
  • Varine Varine:
    Another issue I'm learning is that a lot of the air quality sensors don't work at very high ambient temperatures. I'm planning on heating this enclosure to like 60C or so, and that's the upper limit of their functionality
  • Varine Varine:
    Although I don't know if I need to actually actively heat it or just let the plate and hotend bring the ambient temp to whatever it will, but even then I need to figure out an exfiltration for hot air. I think I kind of know what to do but it's still fucking confusing
  • The Helper The Helper:
    Maybe you could find some of that information from AC tech - like how they detect freon and such
  • Varine Varine:
    That's mostly what I've been looking at
  • Varine Varine:
    I don't think I'm dealing with quite the same pressures though, at the very least its a significantly smaller system. For the time being I'm just going to put together a quick scrubby box though and hope it works good enough to not make my house toxic
  • Varine Varine:
    I mean I don't use this enough to pose any significant danger I don't think, but I would still rather not be throwing styrene all over the air
  • The Helper The Helper:
    New dessert added to recipes Southern Pecan Praline Cake https://www.thehelper.net/threads/recipe-southern-pecan-praline-cake.193555/
  • The Helper The Helper:
    Another bot invasion 493 members online most of them bots that do not show up on stats
  • Varine Varine:
    I'm looking at a solid 378 guests, but 3 members. Of which two are me and VSNES. The third is unlisted, which makes me think its a ghost.
    +1
  • The Helper The Helper:
    Some members choose invisibility mode
    +1
  • The Helper The Helper:
    I bitch about Xenforo sometimes but it really is full featured you just have to really know what you are doing to get the most out of it.
  • The Helper The Helper:
    It is just not easy to fix styles and customize but it definitely can be done
  • The Helper The Helper:
    I do know this - xenforo dropped the ball by not keeping the vbulletin reputation comments as a feature. The loss of the Reputation comments data when we switched to Xenforo really was the death knell for the site when it came to all the users that left. I know I missed it so much and I got way less interested in the site when that feature was gone and I run the site.
  • Blackveiled Blackveiled:
    People love rep, lol
    +1
  • The Helper The Helper:
    The recipe today is Sloppy Joe Casserole - one of my faves LOL https://www.thehelper.net/threads/sloppy-joe-casserole-with-manwich.193585/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top