How to repeat code using this for loop?

Hey all I'm trying to draw a quad every time I find a .obj file in a folder except it only draws the quad once ?? even tho I'm using a for loop and the equation seems correct?.

any ideas to fixing this??


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
  if(BoxStorageToggle == true)
    {

      draw_rectangle(&boxstorage);

      //////////////////////////////
      //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)
        {

          //Output it contents to CMD window
          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;
      }

      //Go through string list and iterator through it till list ends
      for(string_list::iterator it = list.begin(); it != list.end(); it++)
      {

        //convert it to a string at its 32bit address
        string &str = *it;

        //for every occurence of .obj check if its not equal the string non value 
        if(it->find(".obj") != std::string::npos)
        {

          //then output to cmd that its found obj
          cout << "Found .Obj" << endl;

          

             // ///////////////////////////////////////////////////////////////////////////////  //
        // !MAY NEED TO FIX UP THIS CODE IN THE FUTURE IT WILL REPEAT THIS OVER AND OVER ! //
        // DEFENTLY NEED TO FIX THIS!!!
        // ////////////////////////////////////////////////////////////////////////////// //

      /////////////////////////////////////////////////////
      //Object Graphic <Vertex Attributes/Bindings/Drawing>
      /////////////////////////////////////////////////////


      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);

      // "Bind" the newly created texture : all future texture functions will modify this texture
      glBindTexture(GL_TEXTURE_2D, objtextureID);

      // Give the image to OpenGL
      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);

      //MenuContext Vertices cordinates
      glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(0 * sizeof(float)));

      //MenuContext Texture cordinates
      glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 6 * sizeof(float),reinterpret_cast<const GLvoid *>(4 * sizeof(float)));

      //Enable Attribute for "index 1"
      glEnableVertexAttribArray(0);

      //Enable Attribute for "index 1"
      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);
         
   
        }

      }




    }

Last edited on
Assuming that the gl functions you used are right (I'm not too familiar) your problem is line 101. Should be +=.
no luck yet that just moved the quad by 100 not create a new one and move it by 100 :l
I suggest you take lines 68-120 and put them in a function void drawQuad(int xvalue); then test it separately. See what happens with different values of xvalue and what happens if you invoke the function twice with different argument.
Topic archived. No new replies allowed.