visual c++ - Dumb question.How can I make my objects not deform while using gluPerspective? -
hy.i drawn skybox , few objects inside every thing alright except fact objects deformed use of gluperspective ,which need draw skybox , stuff(for example have cube ,but looks paralelipipedic (long longer box) ).now have read chapter 3 of redbook can`t figure out .i have tried using glfrustrum,glortho ,and can t figure out how make work normal. code :
void display(void) { glclear (gl_color_buffer_bit | gl_depth_buffer_bit); glloadidentity (); /* set projection matrix 100 degree fov */ glfloat w = (glfloat)glutget(glut_window_width),h = (glfloat)glutget(glut_window_height); glmatrixmode(gl_projection); glloadidentity(); gluperspective(100,w/h,0.5,100); /* set modelview matrix camera */ glmatrixmode(gl_modelview); glloadidentity(); glrotatef(cameraphi,1,0,0); glrotatef(cameratheta,0,1,0); /* no need clear color buffer, skybox fills whole screen shiny objects in cube environment mode use depth buffer, need clear 1 */ glclear(gl_depth_buffer_bit); /* draw skybox */ gldisable(gl_lighting); //the way move around space(my camera) glulookat(move_camera.x,move_camera.y,move_camera.z,move_camera.x,move_camera.y,move_camera.z-100,0,1,0); drawskybox2d(treetexture); glenable(gl_lighting); //theese objects chair(obiecte[0]); table(obiecte[1]); bed(obiecte[2]); sleep(5); glutswapbuffers(); }
and skybox draw this:
void drawskybox2d(texture treetexture[]) { /* enable 2d texture mapping */ glenable(gl_texture_2d); /* disable depth buffer when rendering skybox */ gldisable(gl_depth_test); gldepthmask(0); int dim=20,x=1,y=0; /* rear face */ glbindtexture(gl_texture_2d,treetexture[5].texid); glbegin(gl_triangle_fan); gltexcoord2f(x,y); glvertex3f(dim,dim,dim); gltexcoord2f(x,x); glvertex3f(dim,-dim,dim); gltexcoord2f(y,x); glvertex3f(-dim,-dim,dim); gltexcoord2f(y,y); glvertex3f(-dim,dim,dim); glend(); /* front face */ glbindtexture(gl_texture_2d,treetexture[4].texid); glbegin(gl_triangle_fan); gltexcoord2f(x,y); glvertex3f(-dim,dim,-dim); gltexcoord2f(x,x); glvertex3f(-dim,-dim,-dim); gltexcoord2f(y,x); glvertex3f(dim,-dim,-dim); gltexcoord2f(y,y); glvertex3f(dim,dim,-dim); glend(); /* right face */ glbindtexture(gl_texture_2d,treetexture[1].texid); glbegin(gl_triangle_fan); gltexcoord2f(x,y); glvertex3f(dim,dim,-dim); gltexcoord2f(x,x); glvertex3f(dim,-dim,-dim); gltexcoord2f(y,x); glvertex3f(dim,-dim,dim); gltexcoord2f(y,y); glvertex3f(dim,dim,dim); glend(); /* left face */ glbindtexture(gl_texture_2d,treetexture[0].texid); glbegin(gl_triangle_fan); gltexcoord2f(x,y); glvertex3f(-dim,dim,dim); gltexcoord2f(x,x); glvertex3f(-dim,-dim,dim); gltexcoord2f(y,x); glvertex3f(-dim,-dim,-dim); gltexcoord2f(y,y); glvertex3f(-dim,dim,-dim); glend(); /* top face */ glbindtexture(gl_texture_2d,treetexture[3].texid); glbegin(gl_triangle_fan); gltexcoord2f(y,x); glvertex3f(-dim,dim,dim); gltexcoord2f(y,y); glvertex3f(-dim,dim,-dim); gltexcoord2f(x,y); glvertex3f(dim,dim,-dim); gltexcoord2f(x,x); glvertex3f(dim,dim,dim); glend(); /* bottom face */ glbindtexture(gl_texture_2d,treetexture[2].texid); glbegin(gl_triangle_fan); gltexcoord2f(y,x); glvertex3f(-dim,-dim,-dim); gltexcoord2f(y,y); glvertex3f(-dim,-dim,dim); gltexcoord2f(x,y); glvertex3f(dim,-dim,dim); gltexcoord2f(x,x); glvertex3f(dim,-dim,-dim); glend(); /* reactive depth buffer */ glenable(gl_depth_test); gldepthmask(1); }
can please me in way?
try passing 45
instead of 100
first element of gluperspective
. you're getting deformations because angle wide (= unrealistic).
if doesn't help, please attach screenshot.
Comments
Post a Comment