Using buffers

Started by
6 comments, last by V-man 15 years, 3 months ago
I have a problem when I use buffers to cash memory on GPU. The program crash with code: 0xC0000005 mNumIndices is 36 and mNumVertices is 24. Here´s my "bind" code:

	glGenBuffers(1, &mElemBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mElemBuffer );
	glBufferData(GL_ELEMENT_ARRAY_BUFFER, mNumIndices * sizeof(GLuint),
                     mIndices, GL_STATIC_DRAW);

	glGenBuffers(1, &mArrBuffer);
	glBindBuffer(GL_ARRAY_BUFFER, mElemBuffer );
	glBufferData(GL_ARRAY_BUFFER, mNumVertices * sizeof(GLfloat), mVertices,
                     GL_STATIC_DRAW);

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0 );
When I draw my box I use this code:

	glBindBuffer(GL_ARRAY_BUFFER,	      mArrBuffer);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, mElemBuffer);

        ...

	glDrawElements( GL_TRIANGLES, mNumIndices, GL_UNSIGNED_INT, mIndices );

	glBindBuffer(GL_ARRAY_BUFFER, 0);
	glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
If I comment the two glBindBuffer before rendering, it works. But then I dont use the buffers. Hmm .. Please help me. New to OpenGL. Btw, its OpenGLES 2.0. But that doesnt matter I think. [Edited by - SimonS on January 20, 2009 10:59:13 AM]
Advertisement
Quote:
glGenBuffers(1, &mArrBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mElemBuffer );
glBufferData(GL_ARRAY_BUFFER, mNumVertices * sizeof(GLfloat), mVertices, GL_STATIC_DRAW);

Looks like a typo. You didn't bind your mArrBuffer.
Quote:Original post by KulSeran
Quote:
glGenBuffers(1, &mArrBuffer);
glBindBuffer(GL_ARRAY_BUFFER, mElemBuffer );
glBufferData(GL_ARRAY_BUFFER, mNumVertices * sizeof(GLfloat), mVertices, GL_STATIC_DRAW);

Looks like a typo. You didn't bind your mArrBuffer.


Thanks for answering.
I fixed that, but still the same problem :(
Quote:Original post by SimonS
	glDrawElements( GL_TRIANGLES, mNumIndices, GL_UNSIGNED_INT, mIndices );




Unless you choose some particular indices, you shuld pass NULL (or 0) as the last parameter when an index buffer is bound.
Quote:Original post by rozz666
Quote:Original post by SimonS
	glDrawElements( GL_TRIANGLES, mNumIndices, GL_UNSIGNED_INT, mIndices );




Unless you choose some particular indices, you shuld pass NULL (or 0) as the last parameter when an index buffer is bound.


Okej, thanx. But the problem is still. I`ve fixed the two you mentioned.
After you call
glBindBuffer(GL_ARRAY_BUFFER, mArrBuffer);
call glVertexPointer

example:
http://www.opengl.org/wiki/VBO#Sample_Code
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
Quote:Original post by V-man
After you call
glBindBuffer(GL_ARRAY_BUFFER, mArrBuffer);
call glVertexPointer

example:
http://www.opengl.org/wiki/VBO#Sample_Code


That function doesnt exist in OpenGLES 2.0. Cant get it to work.
According to their specification (from khronos.org)

2.8 Vertex Arrays
you would have to use glVertexAtrribPointer
glEnableVertexAttribArray( uint index );
glDisableVertexAttribArray( uint index );

so glVertexPointer and the rest are killed off. Good idea.
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);

This topic is closed to new replies.

Advertisement