3
내 코드에서 생성 된 유효한 OpenGL 컨텍스트는 어떻게 그리고 어느 단계에 있습니까? 간단한 OpenGL 코드에서도 오류가 발생합니다.유효한 OpenGL 컨텍스트
내 코드에서 생성 된 유효한 OpenGL 컨텍스트는 어떻게 그리고 어느 단계에 있습니까? 간단한 OpenGL 코드에서도 오류가 발생합니다.유효한 OpenGL 컨텍스트
comp.graphics.api.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()
이 호출 될 때까지 보이지 않습니다.