Jump to content
  • Advertisement
Sign in to follow this  

OpenGL 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

This topic is 2752 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello I'm trying to figure out how to draw a quad constantly till the end of the for loop.

I'm using Boost/C++/OpenGL 3.3/GLSL 330

I'm doing that in this code almost but for some reason its not actually drawing the quad constantly but only once. I don't really know why since I'm using a for loop and constantly creating/drawing the quad I know it may not be the most efficiently way but I just want it to work.

any ideas?

path p(" Storage");

std::vector < std::string > list;

for (directory_iterator it(p); it != directory_iterator(); ++it)

cout << *it << endl;

string s = (*it).path().string();

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)

cout << "Found .Obj" << endl;

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

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


static const GLfloat TranslationMatrix[] = {

1.0, 0.0, 0.0, 600.0,
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);



Share this post

Link to post
Share on other sites
Not sure if I understand your question completely, but I will give it a try:
Seems like you are always drawing it on the same position, which means all your quads are basically above each other - results in looking like one quad. Use glTranslatef to (for example) move each quad a bit more to the right.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!