I want to write a program, which needs two points, and draws a line between these two points. The problem I'm facing now, is how to draw a single pixel?
I know that there are several functions to draw a line, but i can't use them, because my job is to make a program, which demonstrates the drawing method. So i want to ask two points from the user, and then i want to draw the line between the two coordinates from pixel to pixel. I have 7 days to finish this and send to my teacher.
So I just want to know, how to draw a single pixel easily.
The other question, that which library is the easiest, to draw a pixel?
I was about to use OpenGL, but couldn't figure out, how to use it.
I just want to know, how to draw a pixel in any graphics library.
As soon as I can draw a single pixel, i can draw a line, right? This is what I think.
@Rayy, Drawing a single pixel is different than drawing text, or drawing a line, because a line can be diagonal. Unless you want to develop your graphic engine from scratch, you should use some graphic library like Irrlicht, SDL, or plain OpenGL (See here for nice tutorials (Outdated, take care) : http://nehe.gamedev.net/tutorial/lessons_01__05/22004/
or plain DirectX. Just letting you know, if you make a line only of plain dots, it's using more CPU than making a line from premade functions. Why?
Because let's say you make a horizontal line like this:
1 2 3 4 5
void line(Position begin, Position end)
{
for(int x = begin.x; x < end.x; x++)
DrawPixel(x,begin.y);
}
Your CPU will handle your DrawPixel many times.
If you draw a plain Line with Hardware Accelerated Graphics, your GPU will handle that, and your CPU will handle a DrawLine only once.
@EssGeEich, Thanks for the advice, I know, that you're right, but I don't have to care about the speed of the program.
@Vins3Xtreme, Thanks foe the SetPixel(), it works great.
Another question: i want to get datas from the user, but not in the console window. I can write into my window with the TextOut() function. How can I get datas from the keyboard?