2006년 1월 11일 수요일

OpenGL Feedback buffer parsing

. Mouse로 click해서 그 도형의 정보를 얻어냄.

. glRectf(), glBegin(GL_POLYGON)은 도형의 내부를 찍어도 pick됨
. glBegin(GL_LINE_LOOP)는 도형의 boundary를 찍을 때만 pick됨

. feedback buff에 들어가는 값
. glRectf()로 그린 경우
GL_PASS_THROUGH_TOKEN
User-defined value user가 gl 함수로 넘긴값
GL_LINE_RESET_TOKEN

GL_LINE_TOKEN

GL_LINE_TOKEN

GL_LINE_TOKEN

. glBegin(LINE_LOOP)로 그린 경우
GL_PASS_THROUGH_TOKEN
User-defined value user가 gl 함수로 넘긴값
GL_LINE_RESET_TOKEN, 값
GL_LINE_TOKEN, 값 => 여러개 반복
. POLYGON인 경우
GL_PASS_THROUGH_TOKEN
User-defined value user가 gl 함수로 넘긴값
Number of vertices
x cordinate of first vertex
y cordinate of first vertex (2D일때는 y까지 밖에 없다.)
z cordinate of first vertex (3D일때)
x cordinate of first vertex
.
.
.
.
vectex n개가 될때까지 반복

// feedback buffer를 parsingg하는 코드
// feedBackBuff
// size : feedBackbuff의 크기
// nChoice : user가 고른 도형의 user defined value
// vertex가 2차원이면 2개를 얻어오고 3차원이면 3개를 얻어오자.
// 예제는 2차원의 경우임.

size = glRenderMode(GL_RENDER);
i = 0;
while(i < size)
{
// Search for appropriate token
if(feedBackBuff[i] == GL_PASS_THROUGH_TOKEN)
{
std::cout << "feedBackBuff[" << i + 1 << "] (user defined value) : " << feedBackBuff[i+1] << std::endl;
if(feedBackBuff[i+1] == (GLfloat)nChoice)
{
i+= 2;
// Loop until next token is reached
while(i < size && feedBackBuff[i] != GL_PASS_THROUGH_TOKEN)
{
if(feedBackBuff[i] == GL_POLYGON_TOKEN)
{
std::cout << "GL_POLYGON_TOKEN";

// Get all the values for this polygon
count = (int)feedBackBuff[++i]; // How many vertices
i++;

for(j = 0; j < count; j++) // Loop for each vertex
{
// Min and Max X
if(feedBackBuff[i] > boundingRect.right)
boundingRect.right = feedBackBuff[i];

if(feedBackBuff[i] < boundingRect.left)
boundingRect.left = feedBackBuff[i];
i++;

// Min and Max Y
if(feedBackBuff[i] > boundingRect.bottom)
boundingRect.bottom = feedBackBuff[i];

if(feedBackBuff[i] < boundingRect.top)
boundingRect.top = feedBackBuff[i];
i++;
}
} else if(feedBackBuff[i] == GL_POINT_TOKEN) {
std::cout << "GL_POINT_TOKEN ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << std::endl;
} else if(feedBackBuff[i] == GL_LINE_TOKEN) {
std::cout << "GL_LINE_TOKEN ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << std::endl;
} else if(feedBackBuff[i] == GL_LINE_RESET_TOKEN) {
std::cout << "GL_LINE_RESET_TOKEN ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << std::endl;
} else if (feedBackBuff[i] == GL_DRAW_PIXEL_TOKEN) {
std::cout << "GL_DRAW_PIXEL_TOKEN ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << std::endl;
} else if (feedBackBuff[i] == GL_COPY_PIXEL_TOKEN) {
std::cout << "GL_COPY_PIXEL_TOKEN ";
i++;
std::cout << feedBackBuff[i] << " ";
i++;
std::cout << feedBackBuff[i] << std::endl;
}
else
i++; // Get next index and keep looking
}
break;
}
}
i++;
}

참고)
OpenGL Superbible chapter 12. Interactive Graphics (SELECT라는 프로그램)

댓글 없음:

댓글 쓰기