drawing/moving constantly in a for loop?

Hey all I’m trying to draw a quad and move it by 100 units on the x axis every time I find a .obj file in a folder except it only draws the quad once and doesn’t move another time even tho I’m using a for loop? and the equation seems correct?.

I’m using OpenGL 3.3 / GLSL 3.30 / Boost libary / C++

any ideas to fixing this?

if(StorageToggle == true)
    {

      draw_rectangle(&storage);

      //////////////////////////////
      //Directory Reading Proccess
      /////////////////////////////

      //File Path 
      path p("Storage");

      //String vector container
      std::vector < std::string > list;

      //Iteration Loop
      try
      {  
        for (directory_iterator it(p); it != directory_iterator(); ++it)
        {        
          cout << *it << endl;

          //find the it path names store it in s
          string s = (*it).path().string();

          //then push back list
          list.push_back( s );
        }
      }

      catch (const filesystem_error& ex)
      {
        cout << ex.what() << endl;
      }
 
      for(string_list::iterator it = list.begin(); it != list.end(); it++)
      {
      
        string &str = *it;
    
        if(it->find(".obj") != std::string::npos)
        {

      SDL_Surface *surface2; 
        
      surface2 = IMG_Load("GUI/ObjGraphic.tga");

      glGenTextures(1, &objtextureID);

      glGenBuffers(1, &objvbo);

      glBindBuffer(GL_ARRAY_BUFFER, objvbo);

      glBufferData(GL_ARRAY_BUFFER, sizeof(ObjGraphicVertices), ObjGraphicVertices  , GL_DYNAMIC_DRAW);
    
      glBindTexture(GL_TEXTURE_2D, objtextureID);
 
      glTexImage2D(GL_TEXTURE_2D, 0,GL_RGBA, surface2->w,surface2->h, 0, GL_BGR, GL_UNSIGNED_BYTE, surface2->pixels);

      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
      glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
  
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(0 * sizeof(float)));
     
      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(4 * sizeof(float)));
   
      glEnableVertexAttribArray(0);
    
      glEnableVertexAttribArray(1);

        xvalue + 100.0f;

      static const GLfloat TranslationMatrix[] = {
        
        1.0, 0.0, 0.0, xvalue, 
        0.0, 1.0, 0.0, 0.0, 
        0.0, 0.0, 1.0, 0.0, 
        0.0, 0.0, 0.0, 1.0

      };
  
      glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);

      glDrawArrays(GL_QUADS, 0, 4);
          
        }

      }

    }

Hi, the problem is that the translation matrix actually won’t be modified.

The variable TranslationMatrix is declared as static, meaning that it won’t be initialized everytime the function is entered, but just the first time.

To solve this issue either remove the static keyword or update the 4th matrix element explicitly after the declaration.

static const GLfloat TranslationMatrix[] = {
1.0, 0.0, 0.0, xvalue,
0.0, 1.0, 0.0, 0.0,
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
TranslationMatrix[3] = xvalue;
glUniformMatrix4fv(translation, 1, TRUE, TranslationMatrix);

Okay that just makes the objicon move constantly but I am learning something from this :D.

I think its because when I’m cmd the output of all the iterations,etc its spamming like crazy the same thing over and over that may indicate that its not stopping after the first whole iteration of all the iterations but instead doing it for ever.

and I think I know why because of the if statement the hole thing is in :slight_smile: I need to turn it off after the first time I shall look deeper into this.

EDIT:

turns out that is not the problem it could be the iteration loops,etc