opengl - Why does using glViewport for some GL_QUADS increase my window space area? -


so i'm doing exercise involves graphing in opengl , coloring each quadrant. i've done it, when color quadrants before graphing function makes bigger defined size. below leave code clarification.

in init declare necessary space of gluortho2d(-10,10, -10,10);

this in main method called glutdisplayfunc(linegraph) if put @ top colors background increase space of window. enter image description here

//1 cuadrante glviewport(125, 375, 250, 250); glcolor3ub(255,255,0); dibujafondocuadrantes(); //2 cuadrante glviewport(0, 375, 250, 250); glcolor3ub(255,0,0); dibujafondocuadrantes();      //3 cuadrante glviewport(125, 250, 250, 250); glcolor3ub(0,255,0); dibujafondocuadrantes();  //4 cuadrante - realmente el 4 glviewport(0, 250, 250, 250); glcolor3ub(0,0,255); dibujafondocuadrantes(); 

which method dibujafondocuadrantes() has:

glbegin(gl_quads);  glvertex2f(-10, 0.0);//esquina izq arriba glvertex2f(-10, -10);//esquina izq abajo glvertex2f(0.0, -10);// esquina derecha abajo glvertex2f(0.0, 0.0);//esquina derecha srriba glend(); 

all code:

#include <glut/glut.h> #include <stdlib.h> #include <stdio.h> #include <math.h> // tamaÒo inicial de la ventana double pi=3.14159265358979; glsizei winwidth =600, winheight =600; glint xraster = 25, yraster = 150; //posicion inicial de rastreo glubyte name[17] = {'g','u','s','t','a','v','o',' ','f','e','r','r','u','f','i','n','o'}; glubyte matricula[9] = {'a','0','0','0','0','0','0','0','0'}; void init(void) { glclearcolor(0.3,0.7,0.8,1.0); glmatrixmode(gl_projection); gluortho2d(-10,10, -10,10); }  void dibujafondocuadrantes(void){  glbegin(gl_quads); //glcolor3f(0.5f, 0.0f, 1.0f); // make vertex purple glvertex2f(-10, 0.0);//esquina izq arriba glvertex2f(-10, -10);//esquina izq abajo glvertex2f(0.0, -10);// esquina derecha abajo glvertex2f(0.0, 0.0);//esquina derecha srriba glend();   }   void linegraph(void) { glint k;  glfloat x, f; glclear(gl_color_buffer_bit| gl_depth_buffer_bit); //2 cuadrante glviewport(0, 375, 250, 250); glcolor3ub(255,0,0); dibujafondocuadrantes();  //1 cuadrante glviewport(125, 375, 250, 250); glcolor3ub(255,255,0); dibujafondocuadrantes();  //3 cuadrante glviewport(125, 250, 250, 250); glcolor3ub(0,255,0); dibujafondocuadrantes();  //4 cuadrante - realmente el 4 glviewport(0, 250, 250, 250); glcolor3ub(0,0,255); dibujafondocuadrantes();        /*  añadir codigo para dibujar eje de cordenadas  */  glcolor3f(0.0,0.0,0.0); gllinewidth(3); glbegin(gl_lines); //eje x glvertex2i(-10,0); glvertex2i(10,0); //eje y glvertex2i(0, -10); glvertex2i(0, 10); glend();   glpointsize(3); //dibuja funcion deseada para actividad 2 glbegin(gl_points); (x=-6.5; x<=6.5; x+=0.005) {     glcolor3ub(155.0*(x*10), 205.0*x*10,255.0*x*10);     f=exp(fabs(-x))*cos(2*pi*x);      glvertex2f(x,f);   } glend();  //nombre glcolor3f(0.0, 0.0, 0.0); x=0.0; (k=0; k<17;k+=1) {     glrasterpos2i(-9+k,8);     glutbitmapcharacter(glut_bitmap_helvetica_12, name[k]); } //display matricula for(k=0;k<9;k+=1){     glrasterpos2i(-9+k,9);     glutbitmapcharacter(glut_bitmap_helvetica_12, matricula[k]); }   glflush();  } int main(int argc, char** argv) { glutinit(&argc, argv); glutinitdisplaymode(glut_single | glut_rgb); glutinitwindowsize(winwidth,winheight); glutinitwindowposition(100, 100); glutcreatewindow("gustavo ferrufino a00812572"); init();  glutdisplayfunc(linegraph); //    glutreshapefunc(winreshapefcn); glutmainloop(); return 0; } 

i think it's calls glviewport.

probably before render function called, glut making glviewport call of glviewport(0,0,winwidth,winheight).

your quadrant rendering code altering glviewport , doesn't restore afterwards, rendering size affected positioning of glviewport calls.


Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -