OpenGL ES - Dashed Lines

Started by
2 comments, last by alireza.pir 7 years, 9 months ago

im Using OpenGlEs10 for My Android Game Development, I Want to Draw Dashed-lines Now Im Using This Code to Draw My Line:


gl.glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
// gl.glBlendFunc(GL10.GL_SRC_ALPHA, GL10.GL_ONE_MINUS_SRC_ALPHA);
gl.glLineWidth(4.0f);
gl.glVertexPointer(2, GL10.GL_FLOAT, 0, mBufDestVertices);
gl.glDrawArrays(GL10.GL_LINE_LOOP, 0, mDesPoly.getNumPoints());

How Should I Change It? Does I have to Texture The line? And if so, How?

Advertisement

http://perso.esiee.fr/~perrotol/TheRedBook-1.0/chapter02.html

search for:

Stippled Lines

and sample code:


glPushAttrib(GL_ENABLE_BIT); 
# glPushAttrib is done to return everything to normal after drawing

glLineStipple(1, 0xAAAA);  # [1]
glEnable(GL_LINE_STIPPLE);
glBegin(GL_LINES);
glVertex3f(-.5,.5,-.5);
glVertex3f(.5,.5,-.5);
glEnd();

glPopAttrib();

thus i dont know what it draws

search for:
Stippled Lines

There's no stippled lines in OpenGL ES.

Does I have to Texture The line? And if so, How?

Yes, you should texture it.

Make small 1D texture (4-8 pixels wide), large enough to hold desired dash pattern.

Add texture coordinates to your line vertices. Line's first vertex S coord can be at texture's 0, and second vertex S coord should be set depending on line's length, and how dense you want dash pattern. Enable texture wrapping, so pattern will be repeated along line.

Draw with blending or alpha test, depending on your needs.

search for:
Stippled Lines

There's no stippled lines in OpenGL ES.

Does I have to Texture The line? And if so, How?

Yes, you should texture it.

Make small 1D texture (4-8 pixels wide), large enough to hold desired dash pattern.

Add texture coordinates to your line vertices. Line's first vertex S coord can be at texture's 0, and second vertex S coord should be set depending on line's length, and how dense you want dash pattern. Enable texture wrapping, so pattern will be repeated along line.

Draw with blending or alpha test, depending on your needs.

Thanks, Is There Any Tutorial Or Link for How to Do this? or Could You give me a simple code?

This topic is closed to new replies.

Advertisement