2008-08-18 5 views

답변

4

comp.graphics.api.opengl의 게시물에서, 대부분의 초보자들은 첫 번째 OpenGL 프로그램에서 손을 태운 것처럼 보입니다. 대부분의 경우, OpenGL 함수가 유효한 OpenGL 컨텍스트를 만들기 전에 호출되기 때문에 오류가 발생합니다. OpenGL은 상태 시스템입니다. 기계가 시동되고 준비 상태로 윙윙 거릴 때만 작업을 시작할 수 있습니다. 여기

가 유효한 OpenGL을 컨텍스트를 만들 수있는 간단한 코드입니다

#include <stdlib.h> 
#include <GL/glut.h> 

// Window attributes 
static const unsigned int WIN_POS_X = 30; 
static const unsigned int WIN_POS_Y = WIN_POS_X; 
static const unsigned int WIN_WIDTH = 512; 
static const unsigned int WIN_HEIGHT = WIN_WIDTH; 

void glInit(int, char **); 

int main(int argc, char * argv[]) 
{ 
    // Initialize OpenGL 
    glInit(argc, argv); 

    // A valid OpenGL context has been created. 
    // You can call OpenGL functions from here on. 

    glutMainLoop(); 

    return 0; 
} 

void glInit(int argc, char ** argv) 
{ 
    // Initialize GLUT 
    glutInit(&argc, argv); 
    glutInitDisplayMode(GLUT_DOUBLE); 
    glutInitWindowPosition(WIN_POS_X, WIN_POS_Y); 
    glutInitWindowSize(WIN_WIDTH, WIN_HEIGHT); 
    glutCreateWindow("Hello OpenGL!"); 

    return; 
} 

참고 :

  • 관심의 통화가 여기 glutCreateWindow()입니다. 그것은 윈도우를 생성 할뿐만 아니라 OpenGL 컨텍스트를 생성합니다.
  • glutCreateWindow()으로 만든 창은 glutMainLoop()이 호출 될 때까지 보이지 않습니다.
관련 문제