GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Sunday, February 27, 2011

OpenGL - Linear Equation

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

/**
 * The equation is
 * y = x + 2
 */

void setup(){
    glClearColor(1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(-10.0, 10.0, -10.0, 10.0);  // -x, x, -y, y
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(1.0, 0.0, 1.1);
    glPointSize(3.0);

    // y = x + 2
    float x, y;
    glBegin(GL_POINTS);
        for(x=0.0; x< 35.0; x++){
            y = x + 2.0;
            glVertex2f(x/5, y/5);
        }
    glEnd();

    // create coordinate line
    glBegin(GL_LINES);
        glVertex2f(-10.0, 0.0);
        glVertex2f(10.0, 0.0);
        glVertex2f(0.0, 10.0);
        glVertex2f(0.0, -10.0);
    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