c++ - opengl Draw Oval not Circle -


if call function drawfilledcircleo() makes oval , not circle , if put glbegin(gl_line_loop); makes oval

void drawfilledcircle(glfloat x, glfloat y, glfloat radius){     int i;     int triangleamount = 20; //# of triangles used draw circle      //glfloat radius = 0.8f; //radius     glfloat twicepi = 2.0f * pi;      glbegin(gl_triangle_fan);         glvertex2f(x, y); // center of circle         for(i = 0; <= triangleamount;i++) {              glvertex2f(                     x + (radius * cos(i *  twicepi / triangleamount)),                  y + (radius * sin(i * twicepi / triangleamount))             );         }     glend(); } 

i tried different functions drawing circles makes oval .

i placed in :

static void draw(void) {     glclear(gl_color_buffer_bit | gl_depth_buffer_bit);      glviewport(0, 0, widthx, heighty);     glmatrixmode(gl_projection);     glloadidentity();     glmatrixmode(gl_modelview);     glloadidentity();     texture[0] = soil_load_ogl_texture // load image file directly new opengl texture     (         "img.jpg",         soil_load_auto,         soil_create_new_id,          soil_flag_invert_y | soil_flag_compress_to_dxt     ); // allocate texture name     glbindtexture(gl_texture_2d, texture[0]);     glbegin(gl_polygon);      gltexcoord2f(0.0f, 0.0f); glvertex3f(-1.0f, -1.0f,  0.0f);     gltexcoord2f(1.0f, 0.0f); glvertex3f( 1.0f, -1.0f,  0.0f);     gltexcoord2f(1.0f, 1.0f); glvertex3f( 1.0f,  1.0f,  0.0f);     gltexcoord2f(0.0f, 1.0f); glvertex3f(-1.0f,  1.0f,  0.0f);      glend();      drawfilledcircle(0.5f,0.5f,0.1f);      glutswapbuffers(); } 

update :

glutinitdisplaymode(glut_double | glut_rgb);     glutinit(&argc, argv);     glutinitwindowsize(widthx, heighty);     glutcreatewindow("earthquake");     glutreshapefunc(resize);     glutdisplayfunc(draw);     glutkeyboardfunc(keypressed);     glutkeyboardupfunc(keyup);     /////////////////////////////////////     glenable(gl_texture_2d);    // glshademodel(gl_smooth);     glclearcolor(0.0f, 0.0f, 0.0f, 0.5f);     //glcleardepth(1.0f);     //glenable(gl_depth_test);    // gldepthfunc(gl_lequal);    glenable(gl_point_smooth); glhint(gl_point_smooth_hint, gl_nicest);     glhint(gl_perspective_correction_hint, gl_nicest);     glutmainloop(); 

widthx = 800; heighty = 400;

most have misaligned viewport , window size ratios.

following answer might helpful: https://stackoverflow.com/a/15725280/3301533

edit:

thanks code:

glmatrixmode(gl_projection); glloadidentity(); glmatrixmode(gl_modelview); glloadidentity(); 

you have oval. try changing to:

glmatrixmode(gl_projection); glloadidentity(); glortho(-widthx/2, width/x2, -heighty/2, heighty/2, -1, 1); 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -