Rendering Multiple models problem

Started by
0 comments, last by Wrathnut 11 years, 1 month ago

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->colors[0]);
		glVertexPointer(3, GL_FLOAT, 0, &this->cubes->vertices[0]);
		glNormalPointer(GL_FLOAT, 0, &this->cubes->normals[0]);

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

	

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

Any help would be greatly appreciated!

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->vertices.size());

should have been:


glDrawArrays(GL_QUADS, 0, this->cubes->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!

This topic is closed to new replies.

Advertisement