GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, February 27, 2011

OpenGL - Lines

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

void setup(){
    glClearColor(1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(-10.0, 10.0, -10.0, 10.0);
}
void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 1.1);
    glPointSize(5.0);

    // create lines
    glBegin(GL_LINES);
        glVertex2f(-10.0, 0.0);  // left - x negative
        glVertex2f(10.0, 0.0);   // right - x positive
        glVertex2f(0.0, 10.0);   // top - y positive
        glVertex2f(0.0, -10.0);  // bottom - y negative
    glEnd();

    glFlush();
}

int main(int argc, char *argv[]){
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowPosition(200, 100);
    glutInitWindowSize(400, 300);
    glutCreateWindow("Hello World");
    glutDisplayFunc(display);

    setup();
    glutMainLoop();

    return 0;

}


Share/Bookmark

No comments:

Post a Comment