• Advertisement
Sign in to follow this  

Rendering Multiple models problem

This topic is 1773 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

Hi,

 

I think this problem might be related to the one I had the other day. But after an exhaustive search I am still not sure what I am doing wrong. Or if I am trying to render correctly.

 

I was able to get a model to render properly. So my next step was to try to make an stl::vector of different models and try to render them in the same way. When I do this I get some strange effects. I have attached an image of what is going on. I basically arranged a bunch of cubes into a square. It renders the cubes for the most part. (it seems to have messed up the color of one of them though) And then it also draws some extra stuff. I am guessing I am not addressing my models correctly but I am unsure how to do it.

 

I am also wondering if I am even using the right method to draw my models. The code below is when I am using to loop through my vector list of models and try to draw them:

 

        glEnableClientState(GL_VERTEX_ARRAY);
	glEnableClientState(GL_COLOR_ARRAY);
	glEnableClientState(GL_NORMAL_ARRAY);
	
	for(int i=0; i < this->cubes.size(); i++){
		glColorPointer(4, GL_FLOAT, 0, &this->cubes[i]->colors[0]);
		glVertexPointer(3, GL_FLOAT, 0, &this->cubes[i]->vertices[0]);
		glNormalPointer(GL_FLOAT, 0, &this->cubes[i]->normals[0]);

		glDrawArrays(GL_QUADS, 0, this->cubes[i]->vertices.size());
	}

	

	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_COLOR_ARRAY);
	glDisableClientState(GL_NORMAL_ARRAY);

 

 

Any help would be greatly appreciated!

 

 

Share this post


Link to post
Share on other sites
Advertisement

Looks like I have found the solution to my problem after messing around a bit.

 

The following line:

 

glDrawArrays(GL_QUADS, 0, this->cubes[i]->vertices.size());

 

should have been:

 

glDrawArrays(GL_QUADS, 0, this->cubes[i]->vertices.size()/3);

 

Everything seems to be rendering fine right now. For some reason it looked like it was rendering properly  using a single model. But after a few test cases I was able to determine that it in fact was suffering from the same problem as the multiple model drawing!

Share this post


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

  • Advertisement