문제

i have a "normal" opengl scene, and want to overlay this scene with a simple quad.

gl.glMatrixMode(GL_PROJECTION);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glMatrixMode(GL_MODELVIEW);
gl.glPushMatrix();
gl.glLoadIdentity();
gl.glTranslatef(-0.8f, 0.0f, 0.0f);
// draw background
gl.glBegin(GL_QUADS); // of the color cube
gl.glColor3f(1.0f, 0.5f, 0.5f);
gl.glVertex3f(0, 0, 1.0f);
gl.glVertex3f(0.5f, 0, 1.0f);
gl.glVertex3f(0.5f, 0.5f, 1.0f);
gl.glVertex3f(0, 0.5f, 1.0f);
gl.glEnd();
gl.glMatrixMode(GL_PROJECTION);
gl.glPopMatrix();
gl.glMatrixMode(GL_MODELVIEW);
gl.glPopMatrix();

as u can see on the screenshot, the new matrix is distorted. the colored lines are the axes.

Now the question: How can i set an aspect ratio (like in gluPerspective) for my matrix to render a correct squad?

도움이 되었습니까?

해결책

You need to account for the size and shape of the viewport. Transformations are done in "normalized coordinates". This means that the bottom left corner of the viewport is (0,0) and the top right corner of the viewport is (1,1). Your projection matrix needs to account for the shape of the viewport to compensate and make your quad square.

The ratio of the height and width of a viewport is known as the "aspect ratio".

See this page, the important section for your problem is The field of view and Image Aspect Ratio. There's too much content to post a usable excerpt here. You should have no trouble finding resources on projection matrix aspect ratios, and how to compute a correct projection matrix.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top