사용자 도구

사이트 도구


kb:glut

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

kb:glut [2014/11/07 19:26] (현재)
줄 1: 줄 1:
 +====== GLUT ======
 +OpenGL Utility Toolkit
 +
 +
 +====== 가장 기본적인 렌더링 ======
 +[[http://​www.lighthouse3d.com/​opengl/​glut/​]] 에서 가져와서 정리한 것.
 +<code cpp>
 +#include <​glut.h> ​
 +
 +#pragma comment(lib,​ "​glut32.lib"​)
 +
 +float angle=0.0f;
 +
 +void OnIdle(void) ​
 +{
 +    // notice that we're now clearing the depth buffer ​
 +    // as well this is required, otherwise the depth buffer ​
 +    // gets filled and nothing gets rendered. ​
 +    // Try it out, remove the depth buffer part.
 +    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);​
 +    ​
 +    // save the previous settings, in this case save 
 +    // we're refering to the camera settings.
 +    glPushMatrix();​
 +    ​
 +    // Perform a rotation around the y axis (0,​1,​0) ​
 +    // by the amount of degrees defined in the variable angle
 +    glRotatef(angle,​0.0,​1.0,​0.0);​
 +    glBegin(GL_TRIANGLES);​
 +        glVertex3f(-0.5,​-0.5,​0.0);​
 +        glVertex3f(0.5,​0.0,​0.0);​
 +        glVertex3f(0.0,​0.5,​0.0);​
 +    glEnd();
 +    ​
 +    // discard the modelling transformations
 +    // after this the matrix will have only the camera settings.
 +    glPopMatrix();​
 +    ​
 +    // swapping the buffers causes the rendering above to be 
 +    // shown
 +    glutSwapBuffers();​
 +    ​
 +    // finally increase the angle for the next frame
 +    angle += 1.0f;
 +}
 +
 +void OnResize(int w, int h) 
 +{
 +    // Prevent a divide by zero, when window is too short
 +    // (you cant make a window of zero width).
 +    if(h == 0)
 +        h = 1;
 +
 +    float ratio = 1.0* w / h;
 +
 +    // Reset the coordinate system before modifying
 +    glMatrixMode(GL_PROJECTION);​
 +    glLoadIdentity();​
 +    ​
 +    // Set the viewport to be the entire window
 +    glViewport(0,​ 0, w, h);
 +
 +    // Set the correct perspective.
 +    gluPerspective(45,​ ratio, 1, 1000);
 +    glMatrixMode(GL_MODELVIEW);​
 +    glLoadIdentity();​
 +    gluLookAt(0.0,​0.0,​5.0, ​
 +              0.0,​0.0,​-1.0,​
 +              0.0f,​1.0f,​0.0f);​
 +}
 +
 +int main(int argc, char** argv)
 +{
 +    glutInit(&​argc,​ argv);
 +    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
 +    glutInitWindowPosition(100,​ 100);
 +    glutInitWindowSize(320,​ 320);
 +    glutCreateWindow("​3D Tech- GLUT Tutorial"​);​
 +    glutIdleFunc(OnIdle);​
 +    glutDisplayFunc(OnIdle);​
 +    glutReshapeFunc(OnResize);​
 +    glEnable(GL_DEPTH_TEST);​
 +    glutMainLoop();​
 +    return 0;
 +}
 +</​code>​
 +
 +
 +====== 링크 ======
 +  * [[http://​www.xmission.com/​~nate/​glut.html]] \\ GLUT for Win32
 +  * [[http://​www.lighthouse3d.com/​opengl/​glut/​ | GLUT Tutorial]]
 +
 +----
 +  * see also [[OpenGL]]
  
kb/glut.txt · 마지막으로 수정됨: 2014/11/07 19:26 (바깥 편집)