2

I can draw a circle with the algorithm. However, the boundary looks weird, the pixels look so separate from each other. I want them to be closer. I have tried to bigger the point size. But the result is not that much good. So, I was thinking that maybe it would be better if I can completely fill the pixel.(I suppose it's square shaped.) How do I do that or do you have any better idea? It looks like this now:

http://img690.imageshack.us/i/circlev.jpg/

genpfault
  • 51,148
  • 11
  • 85
  • 139
Sammy
  • 885
  • 3
  • 13
  • 32
  • 1
    Why would you reimplement Bresenham with OpenGL? OpenGL already provides you a line primitive. – datenwolf Feb 28 '11 at 14:27
  • 2
    @datenwolf, this is a classic homework problem in an introductory computer graphics class. – Bob Cross Feb 28 '11 at 14:55
  • I think OpenGL is the wrong tool for this job. But regardless, you need to post the code you want help with in this question (i.e. do not post it to pastebin and link to it). It's likely possible to lobotomize OpenGL enough to get it to do what you want, but that likely requires setting it up in a very specific sort of way. – Omnifarious Feb 28 '11 at 15:05
  • @Bob Cross: I was aware that this is probably homework. Still OpenGL is not the right tool for the job, since rasterization happens towards the end of the pipeline. A good homework exercise would have asked the student to implement Bresenham on a bitmap in memory. – datenwolf Feb 28 '11 at 18:11
  • @datenwolf, well, that's a curriculum problem. I know that it's hard to teach intro courses within multiple frameworks. There's nothing about OpenGL that makes this an intractable problem and, with the proper surrounding code, you can make the rasterization step fairly transparent. – Bob Cross Feb 28 '11 at 23:56
  • @Bob Cross: Pixel exact placing of points (or other stuff) in OpenGL is not as trivial as it might seem at first since OpenGL works with mapped coordinates, not location indices on the pixmap array. Also I doubt that a Bresenham example in OpenGL is as instructive as implementing it on a bitmap array. The whole point is about how to fill the bits on an array efficiently with a scheme that is just incrementing counters, not finding the coordinates to place them - the latter could be done a lot easier with the help of Mr. Pythagoras and vector algebra. – datenwolf Mar 01 '11 at 00:13

3 Answers3

5

Without code, it's hard to diagnose the problem. The actual layout of the pixels looks correct for that algorithm. It appears that you're using a projection matrix that isn't translating world space directly to screen space, though.

Try using an orthographic projection where you can assure that one offset in world coordinates is worth exactly one pixel in screen space.

Bob Cross
  • 22,116
  • 12
  • 58
  • 95
2

Judging by your jpeg, I wonder if what you think is one pixel in world space, actually isn't. Perhaps your projection matrix isn't doing quite what you think it is.

Is GL_POINT_SMOOTH enabled? -- It's possible that this is messing with things. Those pixels look strangely round.

Assuming that using this algorithm is important to you (and you're not interested in methods that may be more efficient), you could draw a quad for each "pixel" instead of using GL_POINTS.

Martin Stone
  • 12,682
  • 2
  • 39
  • 53
0

use sin/cos method, then you can draw lines from one point to another, also it allows you to change the polygon detail too, not to mention its much easier to fill the circle then too (draw triangles from middle to edges).

if you use higher detail, the result will be almost the same as Bresenham.

Rookie
  • 1,242
  • 3
  • 17
  • 22
  • 1
    -1: The OP very likely needs to use Bresenham's algorithm specifically because of a class requirement. So this doesn't really answer the question. – Omnifarious Feb 28 '11 at 15:06