【问题标题】:How to draw connected strip lines in OpenGL like this如何像这样在OpenGL中绘制连接的带状线
【发布时间】:2013-07-07 10:33:40
【问题描述】:

我想按以下方式绘制一系列连接线(GL_LINE_STRIP)。

我曾尝试自己编写代码,但没有得到想要的结果,所以我来到这里,帮助我找出我错在哪里。这里我只给出我的 draw() 函数。

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();

【问题讨论】:

  • 你现在看到了什么?在绘图前尝试glOrtho(-4.0,+4.0,-4.0,+4.0,-1.0,+1.0)

标签: c++ c opengl glut glu


【解决方案1】:

在这里完美工作:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    • 1970-01-01
    • 1970-01-01
    • 2019-02-24
    相关资源
    最近更新 更多