c++ - Drawing Multiple shapes in openGL/GLUT -


i have code , trying draw 2 hexagons 1 show up. first time using opengl although i've used c++ time now. first hexagon shows second 1 seen. sorry comments in there trying draw 121 of hexagons in loop.

#include <iostream> #include <gl/glut.h> #include <stdlib.h> #include <string> #define _use_math_defines #include <math.h>  void displaycall(){     int x = 0;      int y = 0;     glclearcolor(1, 1, 1, 1);     glclear(gl_color_buffer_bit | gl_depth_buffer_bit);     glenable(gl_depth_test);     glmatrixmode(gl_projection);     glloadidentity();     glortho(-2.0, 2.0, -2.0, 2.0, -2.0, 500.0);     glmatrixmode(gl_modelview);     glloadidentity();     glscalef(.005, .005, .005);  // enable polygon offsets, , offset filled polygons forward 2.5 glenable(gl_polygon_offset_fill); glpolygonoffset(-2.5f, -2.5f); // set render mode line rendering thick line width glpolygonmode(gl_front_and_back, gl_line); gllinewidth(3.0f); // set colour white //glcolor3f(1.0f, 1.0f, 1.0f);  //outline color glcolor3f(0, 0, 0); //for (int = 0; < 11; i++){ //  (int j = 0; j < 11; j++){         gltranslatef(-300 + x, 300 - y, 0);         glbegin(gl_polygon);         (int = 0; < 6; ++i) {             glvertex2d(50 * sin(i / 6.0 * 2 * m_pi),                 50 * cos(i / 6.0 * 2 * m_pi));         }         glend();         gltranslatef(-200 + x, 300 - y, 0);         glbegin(gl_polygon);         (int = 0; < 6; ++i) {             glvertex2d(50 * sin(i / 6.0 * 2 * m_pi),                 50 * cos(i / 6.0 * 2 * m_pi));         }         glend();     //  x += 50; //  }     //y += 50;     //x = 0; //  }   glutswapbuffers(); }  int main(int argc, char **argv){ std::cout << "test" << std::endl;  char* buf = 0; size_t sz = 0; if (_dupenv_s(&buf, &sz, "display")){     std::string display(("display"));     std::cout << display << std::endl; } else{     std::cout << "empty" << std::endl; } glutinit(&argc, argv); glutinitdisplaymode(glut_double | glut_rgb | glut_depth); glutinitwindowsize(600, 600); glutcreatewindow("red"); glutdisplayfunc(displaycall); glutmainloop(); return 0; } 

you not resetting transformation matrix.

try

   glpushmatrix();    gltranslatef(-300 + x, 300 - y, 0);    glbegin(gl_polygon);    (int = 0; < 6; ++i) {         glvertex2d(50 * sin(i / 6.0 * 2 * m_pi),             50 * cos(i / 6.0 * 2 * m_pi));     }     glend();     glpopmatrix();     glpushmatrix();     gltranslatef(-200 + x, 300 - y, 0);     glbegin(gl_polygon);     (int = 0; < 6; ++i) {         glvertex2d(50 * sin(i / 6.0 * 2 * m_pi),             50 * cos(i / 6.0 * 2 * m_pi));     }     glend();     glpopmatrix(); 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -