How to draw connected strip lines in OpenGL like this

*爱你&永不变心* 提交于 2019-12-22 04:34:26

问题


I want to draw a series of connected lines (GL_LINE_STRIP) in following way.

I had tried to code by my own, but not get desired result, so i come here, help me to find out where i was wrong. here i am giving 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();

回答1:


Workin' perfectly here:

#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;
}


来源:https://stackoverflow.com/questions/17554669/how-to-draw-connected-strip-lines-in-opengl-like-this

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!