GMgKe586q6suSQnyqZLlGCooeWM

Pages

Search

Tuesday, March 1, 2011

OpenGL - 3D

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

void dispay(void);
void setup();

void draw(){
    glColor3f(1.0, 0.0, 0.0);
    glBegin(GL_POLYGON);
        glVertex3f(1.0, 1.0, 1.0);
        glVertex3f(1.0, 5.0, 1.0);
        glVertex3f(5.0, 5.0, 1.0);
        glVertex3f(5.0, 1.0, 1.0);

        glVertex3f(1.0, 1.0, 5.0);
        glVertex3f(1.0, 5.0, 5.0);
        glVertex3f(5.0, 5.0, 5.0);
        glVertex3f(5.0, 1.0, 5.0);
    glEnd();
}

void coord(){
    glColor3f(0.0,1.0,0.0);
    glBegin(GL_LINES);
        // hoz line
        glVertex3f(-1.0, 0.0, 0.0);
        glVertex3f(10.0, 0.0, 0.0);
        // vertical line
        glVertex3f(0.0, -1.0, 0.0);
        glVertex3f(0.0, 10.0, 0.0);
        // z lines
        glVertex3f(0.0, 0.0, -1.0);
        glVertex3f(0.0, 0.0, 10.0);
    glEnd();
}

void setup(){
    glClearColor(1.0, 1.0, 1.0, 1.0);
    gluOrtho2D(-1.0, 10.0, -1.0, 10.0);

}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0, 0.0, 0.0);

    coord();
    draw();
    glFlush();
}


int main(int argc, char *argv[]){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
    glutInitWindowSize(400, 300);
    glutInitWindowPosition(200, 100);
    glutCreateWindow("Hacking openGL");
    glutDisplayFunc(display);

    setup();
    glutMainLoop();

    return 0;
}

Share/Bookmark

No comments:

Post a Comment