Aspect Ratio Stretching in OpenGL -
i having trouble full screen mode. can set window 800x600, when full screen resolution, stretches. assume because of change in aspect ratio. how can fix this?
edit #1
here's screen shot of see happening.
left: 800x600
right: 1366x768
edit #2
my initgraphics function gets called every time re-size window (wm_size).
void initgraphics(int width, int height) { float aspect = (float)width / (float)height; glviewport(0, 0, width, height); glenable(gl_texture_2d); glenable(gl_blend); //enable alpha blending glblendfunc(gl_src_alpha, gl_one_minus_src_alpha); glclearcolor(0.0, 0.0, 0.0, 1.0); glmatrixmode(gl_projection); glloadidentity(); gluortho2d(0.0, width, height * aspect, 0.0); glmatrixmode(gl_modelview); }
solution: real problem ended being misusing gluortho2d function. instead of using this:
gluortho2d(0.0, width, height * aspect, 0.0); you needed switch correct form this:
gluortho2d(0.0, width, 0.0, height); the latter creates 2d orthographic projection, fills entire width , height of viewport, no stretching occurs.
original answer:
you need modify projection in order account new aspect ratio.
make sure first of set glviewport new window size. after viewport set need switch matrix mode projection call glmatrixmode , calculate new aspect ratio width / height , pass new aspect ratio gluperspective. can use straight glfrustum instead of gluperspective can find source gluperspective achieve same effect glfrustum.
something this:
float aspectratio = width / height; glmatrixmode(gl_projection_matrix); glloadidentity(); gluperspective(fov, aspectratio, near, far); 
Comments
Post a Comment