2013-07-09 14 views
8

Chcę narysować serię połączonych linii (GL_LINE_STRIP) w następujący sposób.Jak narysować połączone linie paska w OpenGL w ten sposób

openGL Strip Lines

Próbowałem kodu przez własną rękę, ale nie dać pożądanego rezultatu, więc i tu, pomóż mi, aby dowiedzieć się, gdzie się myliłem. tutaj podaję tylko moją funkcję 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(); 
+0

Co widzisz teraz? Wypróbuj 'glOtho (-4,0, + 4,0, -4,0, + 4,0, -1,0, + 1,0)' przed rysowaniem. –

Odpowiedz

5

Workin' doskonale tutaj:

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; 
} 
+0

dziękuję, myślę, że byłem chybienie glorso (-6, 6, -6, 6, -1, 1); – user437641

Powiązane problemy