View Full Version : bresenham's line algorithm

12-29-2003, 07:36 PM
How to do the coding for bresenham's line algorithm using the openGL?? i'm new to programming

12-29-2003, 11:30 PM
Bresenham's algorithm is lower level than OpenGL. OpenGL draws lines for you using internal hidden algorithms, these algorithms are not mandated by the OpenGL spec, only the results so the algorithms vary from one implementation to another and from one graphics card to another.

If you wanted to implement Bresenham's line drawing algorithm, you'd draw a line in memory and use a glDrawPixels call to display the resulting memory image in the framebuffer of OpenGL.

It's just not appropriate or fast way to do things with OpenGL, but it could be useful for learning.

12-30-2003, 08:16 AM
You can also use Bresenham's algorithm to draw to data to be used for a texture, and then draw a textured quad with your lines.

I started a small library for my own use that loads TGAs/BMPs, etc. I have also started to implement various 2D algorithms into it like drawing lines, Perlin noise, etc. Things that could be useful for creating procedural textures.