3

I'm trying to draw a 2d grid in opengl which contains dashed lines. I'm using glEnble(GL_LINE_STIPPLE) / glLineStipple(...) to do so. The problem is when I'm trying to drag the scene, dashes begin to move along the line and that is rather annoying, especialy if I'm drawing a circle or an arc - it looks like hypnosis! Does anyone know how to get out of this effect?

Mikhail Zimka
  • 694
  • 1
  • 9
  • 20
  • 3
    Line stipple is deprecated and removed from modern OpenGL anyway. Nowadays, one uses fragment shaders for that. the effect might also be achieved by textures. – derhass Nov 30 '14 at 13:47
  • Yes I know, but I have to deal with an old piece of code unfortunately – Mikhail Zimka Nov 30 '14 at 14:29
  • 1
    I believe if you use constant texture coordinates and an appropriate texture, you can more or less achieve the same effect without the undesired behavior when you move the line. All you need is a 1D checkerboard-like texture, and that sort of thing is supported even by implementations that don't use shaders. This is pure 2D right? Perspective projection can throw in another source of "hypnosis" if you try to do it the way I described, but that'll be a non-issue if everything has the same Z coordinate. – Andon M. Coleman Nov 30 '14 at 14:33
  • @AndonM.Coleman Please, can you give me an example how to do it? – Mikhail Zimka Nov 30 '14 at 14:48
  • @MikhailZimka: This is not done much since shaders were added around the same time line stippling became deprecated (though you might find a few examples in OpenGL ES 1.x). I found a really simple example for OpenGL [here](https://www.opengl.org/discussion_boards/archive/index.php/t-132759.html) (see Bob's answer). – Andon M. Coleman Nov 30 '14 at 14:55
  • @MikhailZimka: If you get it working, make sure to write an answer to your question. Other people may run into this problem in the future and the archived OpenGL thread post may no longer exist. – Andon M. Coleman Nov 30 '14 at 15:25
  • 1
    @MikhailZimka if you have no performance issues and want complete control of the style then look here http://stackoverflow.com/a/18643561/2521214 just rewrite the `int` to `GLfloat` or whatever you use and instead od drawline use 2x `glVertex` ... inside `glBegin(GL_LINES); ... glEnd();` do not forget to change the lengths and for step to your values ... (from pixels to world coordinate units) – Spektre Dec 01 '14 at 09:32
  • @Spektre, thanks for your comment, but I have already found the solution using 1d texture. – Mikhail Zimka Dec 01 '14 at 09:50
  • @AndonM.Coleman, 1d texture method works for me fine, but is it correct to post an answer for my own question? As it was you who gave me an example, I'd like you to do it for me and I'll accept your answer. – Mikhail Zimka Dec 01 '14 at 09:54

0 Answers0