소프트웨어/openGL

openGL | install opengl & sample example

개발자_이훈규 2014. 1. 9. 17:03

    환경 : ubuntu 13.10 64bit


install


$ sudo apt-get install mesa-common-dev

$ sudo apt-get install freeglut3-dev






compile

g++ <file name>.cpp -lGL -lGLU -lglut -o a



sample code

#include <gl/freeglut.h>

#include <gl/gl.h>


void renderfunction() {

        glclearcolor(0.0, 0.0, 0.0, 0.0);

        glclear(gl_color_buffer_bit);

        glcolor3f(1.0, 1.0, 1.0);

        glortho(-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);

        glbegin(gl_polygon);

                glvertex2f(-0.5, -0.5);

                glvertex2f(-0.5, 0.5);

                glvertex2f(0.5, 0.5);

                glvertex2f(0.5, -0.5);

        glend();

        glflush();

}


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

        glutinit(&argc, argv);

        glutinitdisplaymode(glut_single);

        glutinitwindowsize(500, 500);

        glutinitwindowposition(100, 100);

        glutcreatewindow("opengl - first window demo");

        glutdisplayfunc(renderfunction);

        glutmainloop();

        return 0;

}




결과 화면