How to draw connected stripes of lines in OpenGL like this

I want to draw a series of connected lines (GL_LINE_STRIP) as follows.

openGL Strip Lines

I tried to execute the code myself, but did not get the desired result, so I came here, helped me find out where I was wrong. here I give only my draw () function.

glBegin(GL_LINE_STRIP); glVertex2f(-4.00, 0.00); glVertex2f(-3.00, 2.00); glVertex2f(-2.00, 0.00); glVertex2f(-1.00, 2.00); glVertex2f(0.0, 0.00); glVertex2f(1.00, 2.00); glVertex2f(2.00, 0.00); glVertex2f(3.00, 2.00); glVertex2f(4.00, 0.00); glEnd(); 
+8
c ++ c opengl glut glu
source share
1 answer

Work here great:

lines

 #include <GL/glut.h> void display() { glClear( GL_COLOR_BUFFER_BIT ); glMatrixMode( GL_PROJECTION ); glLoadIdentity(); glOrtho( -6, 6, -6, 6, -1, 1); glMatrixMode( GL_MODELVIEW ); glLoadIdentity(); glColor3ub( 255, 255, 255 ); glBegin(GL_LINE_STRIP); glVertex2f(-4.00, 0.00); glVertex2f(-3.00, 2.00); glVertex2f(-2.00, 0.00); glVertex2f(-1.00, 2.00); glVertex2f(0.0, 0.00); glVertex2f(1.00, 2.00); glVertex2f(2.00, 0.00); glVertex2f(3.00, 2.00); glVertex2f(4.00, 0.00); glEnd(); glutSwapBuffers(); } int main( int argc, char **argv ) { glutInit( &argc, argv ); glutInitDisplayMode( GLUT_RGBA | GLUT_DOUBLE ); glutInitWindowSize( 600, 600 ); glutCreateWindow( "GLUT" ); glutDisplayFunc( display ); glutMainLoop(); return 0; } 
+5
source share

All Articles