Jump to content
  • Advertisement
Sign in to follow this  
zix99

glBufferDataARB() killing Vertex-Array drawing

This topic is 4532 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 all, Now, upon the title, you may think that the two items are semingly unrelated.. which is my problem exactly. I have two seperate objects, a model of grass (3D, upright, with blending), and a tree. I put the tree in VBO mode, which makes it all get stored in a VBO and deletes the coordinates in RAM. I then put the grass in a Vertex-Array, which is stored in RAM and drawn via glDrawArrays. The problem is, when the tree (loaded before the grass) is put into VBO mode, the grass will not draw, at all. When either the tree is in VA (Vertex array) mode or the grass is in VBO mode it works fine. Code that stores the data from the tree in a VBO:
for (i=0; i<mat_amt; ++i){
			mat_vbo.mat = mat_arr.mat;
			mat_vbo.point_amt = mat_arr.point_amt;

			glGenBuffersARB(1, &mat_vbo.VBO_Verticies);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB, mat_vbo.VBO_Verticies);
			glBufferDataARB(GL_ARRAY_BUFFER_ARB, mat_vbo.point_amt*3*sizeof(float), mat_arr.verticies, GL_STATIC_DRAW_ARB);

			glGenBuffersARB(1, &mat_vbo.VBO_Normals);
			glBindBufferARB(GL_ARRAY_BUFFER_ARB, mat_vbo.VBO_Normals);
			glBufferDataARB(GL_ARRAY_BUFFER_ARB, mat_vbo.point_amt*3*sizeof(float), mat_arr.normals, GL_STATIC_DRAW_ARB);
			
			for (j=0; j<MAX_TEXTURES; ++j)
				mat_vbo.VBO_TexCoord[j] = NULL;
			for (j=0; j<mat_vbo.mat->texlist.size(); ++j){
				glGenBuffersARB(1, &mat_vbo.VBO_TexCoord[j]);
				glBindBufferARB(GL_ARRAY_BUFFER_ARB, mat_vbo.VBO_TexCoord[j]);
			>>>>>>>>glBufferDataARB(GL_ARRAY_BUFFER_ARB, mat_vbo.point_amt*2*sizeof(float), mat_arr.texcoords[j].t, GL_STATIC_DRAW_ARB);
			}
		}




That's the part that matters. The source for drawing the vertex-array of grass
//VERTEX ARRAY
		glEnableClientState(GL_VERTEX_ARRAY);
		glVertexPointer(3, GL_FLOAT, 0, vert);

		glEnableClientState(GL_NORMAL_ARRAY);
		glNormalPointer(GL_FLOAT, 0, norm);

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		mat->texlist[0]->bind();
		glTexCoordPointer(2, GL_FLOAT, 0, tex);

		//draw
		glDrawArrays(GL_TRIANGLES, 0, point_amt);

		//Disable
		glDisableClientState(GL_VERTEX_ARRAY);
		glDisableClientState(GL_NORMAL_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);




Ok, so the part marked (with arrows>>>>) in loading the tree is the problem. If I comment this line out, it all works. To make it more confusing, it works on the first material but not the second (so if I have it call glBufferDataARB only if i==0, then it works fine). It is the texture coordinates being buffered into a VBO (whose ID happens to equal 6). I checked out the data, nothing's corrupted, alls fine. There is plenty of GPU RAM (I have a 128 MB card, Geforce 6600 GT to be exact), and the tree is only 800 verticies tops, with 2 materials... which takes up 56 KB of GPU memory. I'm lost on this one, I have fluidstudio's mmgr in place, and it's not detecting any memory leaks. I have tried to get errors in likely places with glGetError().. and to begin with I don't even see how uploading data to the GPU via glBufferDataARB() and drawing the grass from RAM could began to relate. I would appreciate any help/advice you have to offer ~zix EDIT for clarification: I'd also like to add I'm never actually drawing the tree, just loading it.. and I am calling the procedure to draw the grass, which is the part that doesnt work (But only if i load the tree using the VBO).

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by zix99
Hi all,
Now, upon the title, you may think that the two items are semingly unrelated.. which is my problem exactly. I have two seperate objects, a model of grass (3D, upright, with blending), and a tree. I put the tree in VBO mode, which makes it all get stored in a VBO and deletes the coordinates in RAM. I then put the grass in a Vertex-Array, which is stored in RAM and drawn via glDrawArrays.


I didn't read all of your code, sorry - but to use a standard vertex array after a VBO binding, you just have to glBindBuffer(GL_ARRAY_BUFFER, 0). If you're already doing that, then ignore this.

Share this post


Link to post
Share on other sites
You have no idea how noobish you just made me feel -_-. Oh well, thanks, it worked.. I suppose I can justify it as being an oversight :).

~zix

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!