'Development/Open GL'에 해당되는 글 1건

제목 날짜

openGL이란 

OpenGL(Open Graphics Library, 오픈지엘)은 1992년 실리콘 그래픽스사에서 만든 2차원 및 3차원 그래픽스 표준 API 규격으로, 프로그래밍 언어 간 플랫폼 간의 교차 응용 프로그래밍을 지원한다. 이 API는 약 250여개 가량의 함수 호출을 이용하여 단순한 기하도형에서부터 복잡한 삼차원 장면을 생성할 수 있다. OpenGL은 현재 CAD가상현실정보시각화, 비행 시뮬레이션 등의 분야에서 활용되고 있다. 또한 컴퓨터 게임 분야에서도 널리 활용되고 있으며, 마이크로소프트사의 Direct3D와 함께 컴퓨터 그래픽 세계를 양분하고 있다. Direct3D와는 달리, 표준안이 여러 관련 업체의 토론과 제안으로 이루어지기에 버전 업데이트는 느린 편이다. OpenGL을 사용하여 개발된 대표적인 게임은 이드 소프트웨어의 퀘이크둠3 시리즈이다. 현재 비영리 기술 컨소시엄인 크로노스 그룹에 의하여 관리되고 있다.


출처 https://ko.wikipedia.org/wiki/OpenGL


우분투에서 open GL 설치는 매우 간단 합니다.


터미널을 열고 


sudo apt-get install freeglut3-dev libglu1-mesa-dev mesa-common-dev


로 간단히 설치가 가능 합니다.



/usr/include/GL 에 위 사진 처럼 파일이 있는지 확인 합니다.


파일이 정상적으로 있으면 정상적으로 설치가 완료 된것입니다.


이제 이클립스에서 c/c++ 프로젝트를 만들어 주세요


간단히 소스 파일까지 만들고 정상적으로 빌드가 된다면 openGL 소스를 작성 합니다.


#include <GL/glut.h>

#define window_width  640

#define window_height 480

// Main loop

void main_loop_function() {

    // Z angle

    static float angle;

    // Clear color (screen)

    // And depth (used internally to block obstructed objects)

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    // Load identity matrix

    glLoadIdentity();

    // Multiply in translation matrix

    glTranslatef(0, 0, -10);

    // Multiply in rotation matrix

    glRotatef(angle, 0, 0, 1);

    // Render colored quad

    glBegin(GL_QUADS);

    glColor3ub(255, 000, 000);

    glVertex2f(-1, 1);

    glColor3ub(000, 255, 000);

    glVertex2f(1, 1);

    glColor3ub(000, 000, 255);

    glVertex2f(1, -1);

    glColor3ub(255, 255, 000);

    glVertex2f(-1, -1);

    glEnd();

    // Swap buffers (color buffers, makes previous render visible)

    glutSwapBuffers();

    // Increase angle to rotate

    angle += 0.25;

}

// Initialze OpenGL perspective matrix

void GL_Setup(int width, int height) {

    glViewport(0, 0, width, height);

    glMatrixMode(GL_PROJECTION);

    glEnable(GL_DEPTH_TEST);

    gluPerspective(45, (float) width / height, .1, 100);

    glMatrixMode(GL_MODELVIEW);

}

// Initialize GLUT and start main loop

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

    glutInit(&argc, argv);

    glutInitWindowSize(window_width, window_height);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);

    glutCreateWindow("GLUT Example!!!");

    glutIdleFunc(main_loop_function);

    GL_Setup(window_width, window_height);

    glutMainLoop();

}


작성후 빌드를 하면 정상적으로 해더는 추가가 되지만 빌드는 오류가 남니다.

프로젝트에서 오른쪽 클릭으로 properties -> c/c++ build -> Settings -> tool settings -> GCC c Linker or GCC C++ Linker -> libaries 에서 옵션을 추가  해줌니다.



apply 후 나오시고 재빌드 하신뒤 실행을 하시면 정상적으로 컴파일이 되면서 실행이 됨니다.



Posted by 준P