vertex_begin 함수 설명 및 활용 예제
함수 설명
vertex_begin
함수는 사용자 정의 프리미티브의 정의를 시작하는 함수입니다. 이 함수를 사용하여 프리미티브를 작성할 버텍스 버퍼와 사용할 버텍스 포맷을 지정합니다. 버텍스 포맷은 이전에 vertex format
관련 함수를 사용하여 정의해야 합니다. 이후, 프리미티브의 각 버텍스에 필요한 점들을 정의한 후 vertex_end
함수를 호출하여 프리미티브 생성을 완료합니다.
문법
vertex_begin(buffer, format);
인수 설명
인수 | 유형 | 설명 |
---|---|---|
buffer | Vertex Buffer | 작성할 버텍스 버퍼 |
format | Vertex Format | 사용할 버텍스 포맷 |
반환값
N/A
예제 코드
vertex_format_begin();
vertex_format_add_position();
vertex_format_add_colour();
vertex_format_add_texcoord();
v_format = vertex_format_end();
v_buff = vertex_create_buffer();
vertex_begin(v_buff, v_format);
위 코드는 새로운 버텍스 포맷을 정의하고, 새로운 버퍼를 생성한 후 새로운 프리미티브의 정의 과정을 시작합니다.
활용 및 응용 예제
예제 1: 기본 삼각형 그리기
vertex_begin(v_buff, v_format);
vertex_position(0, 0);
vertex_colour(255, 0, 0);
vertex_texcoord(0, 0);
vertex_position(100, 0);
vertex_colour(0, 255, 0);
vertex_texcoord(1, 0);
vertex_position(50, 100);
vertex_colour(0, 0, 255);
vertex_texcoord(0.5, 1);
vertex_end();
예제 2: 사각형 그리기
vertex_begin(v_buff, v_format);
vertex_position(0, 0);
vertex_colour(255, 255, 0);
vertex_texcoord(0, 0);
vertex_position(100, 0);
vertex_colour(255, 0, 255);
vertex_texcoord(1, 0);
vertex_position(100, 100);
vertex_colour(0, 255, 255);
vertex_texcoord(1, 1);
vertex_position(0, 100);
vertex_colour(255, 255, 255);
vertex_texcoord(0, 1);
vertex_end();
예제 3: 다각형 그리기
vertex_begin(v_buff, v_format);
vertex_position(50, 0);
vertex_colour(255, 0, 0);
vertex_texcoord(0.5, 0);
vertex_position(100, 100);
vertex_colour(0, 255, 0);
vertex_texcoord(1, 1);
vertex_position(0, 100);
vertex_colour(0, 0, 255);
vertex_texcoord(0, 1);
vertex_position(50, 50);
vertex_colour(255, 255, 0);
vertex_texcoord(0.5, 0.5);
vertex_end();
이러한 예제들은 vertex_begin
함수를 사용하여 다양한 형태의 그래픽을 그리는 방법을 보여줍니다.