OpenGL Environment in Linux

Official Website:http://www.opengl.org/

自從顯示問題暫時獲得解決之後,我終於可以在Linux底下建立OpenGL的環境,透過安裝以下的套件就可以開始使用OpenGL撰寫程式:

sudo apt-get install build-essential libgl1-mesa-dev libglu1-mesa-dev libglut3-dev

一個簡易的範例如下:

#include <GL/glut.h>

void init();
void display();

int main(int argc, char* argv[])
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowPosition(0, 0);
    glutInitWindowSize(300, 300);
    
    glutCreateWindow("OpenGL 3D View");
    
    init();
    glutDisplayFunc(display);
    
    glutMainLoop();
    return 0;
}

void init()
{
    glClearColor(0.0, 0.0, 0.0, 0.0);
    glMatrixMode(GL_PROJECTION);
    glOrtho(-5, 5, -5, 5, 5, 15);
    glMatrixMode(GL_MODELVIEW);
    gluLookAt(0, 0, 10, 0, 0, 0, 0, 1, 0);
}

void display()
{
    glClear(GL_COLOR_BUFFER_BIT);
    
    glColor3f(0.5, 1, 0.2);
    glutWireTeapot(3);
    
    glFlush();
}



編譯方式:
gcc -lGL -lGLU -lglut -o example example.c
輸出畫面:


Reference:Howto Install OpenGL Development Environment

No comments:

Post a Comment

Orange - data analysis tool

Installation pip install orange3 Run orange python -m Orange.canvas