2013-11-04 4 views
0

창 크기를 조정할 때 원점이 왼쪽 상단에 없습니다. 그리고 2 차원 좌표를 픽셀에없는 좌표 :OpenGL 2d 크기 조정

glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 
rnd::initDraw(); 
glMatrixMode(GL_PROJECTION); 
glPushMatrix(); 
glLoadIdentity(); 
glOrtho(0.0, mainPanelx, mainPanely, 0.0, -1.0, 10.0); 
glMatrixMode(GL_MODELVIEW); 
//glPushMatrix();  ----Not sure if I need this 
glLoadIdentity(); 
glDisable(GL_CULL_FACE); 
glDisable(GL_DEPTH_TEST); 
glClear(GL_DEPTH_BUFFER_BIT); 

glBegin(GL_QUADS); 
    glColor3f(1.0f, 0.0f, 0.0); 
    glVertex2f(0.0, 0.0); 
    glVertex2f(10.0, 0.0); 
    glVertex2f(10.0, 10.0); 
    glVertex2f(0.0, 10.0); 
glEnd(); 
glMatrixMode(GL_PROJECTION); 
glPopMatrix(); 
glMatrixMode(GL_MODELVIEW); 
glutSwapBuffers(); 

크기 조정 기능 : 난 내 윈도우의 왼쪽 상단 모서리에 일정 원점을 얻는 방법 내가 2 차원 좌표를 얻는 방법

void resize(int width, int height) 
{ 
if (height == 0) height = 1; 

glMatrixMode(GL_PROJECTION); 
glLoadIdentity(); 

/* note we divide our width by our height to get the aspect ratio */ 
gluPerspective(45.0, width/height, 1.0, 400.0); 
glMatrixMode(GL_MODELVIEW); 
mainPanelx = width; 
mainPanely = height; 
std::cout<<mainPanelx<<", "<<mainPanely<<"\n"; 
} 

픽셀 좌표로?

+0

무엇이 당신의 질문입니까? – Nobody

+0

크기 조정 함수는 [glViewport (0, 0, width, height)'] (https://www.opengl.org/sdk/docs/man/xhtml/glViewport.xml)을 호출해야합니다. – Nobody

+0

이제 제대로 작동합니다. – float

답변

0

크기 조정 기능에서 glViewport으로 전화하는 걸 잊었습니다.

이것은 OpenGL이 여전히 이전 크기의 뷰포트로 렌더링한다는 것을 의미합니다.