Im using VBO for fast rendering, now I have an issue I cant solve:
glGenBuffer is behaving idiotic when assigning IDs for the vector<MyClass> objects. I get always the same values for normalsID, verticesID and the colorsID. To see clear what Im talking about :
/////////////////////////////////////////////////
//---------MyClass------------
class MyClass{
Gluint verticesID,normalsID,colorsID;
vector <GLfloat> vertices_vbo,colors_vbo,normals_vbo; // holding vertice,color components…
public:
void Init(…);
.
.
void CreateVBO();
void Draw();
.
.
};
void MyClass::CreateVBO(){
.
.
// here I was pushing vertices into vertices_vbo before,etc its ok till this point…
glGenBuffersARB(1, &verticesID);
glBindBufferARB( GL_ARRAY_BUFFER_ARB, verticesID);
glBufferDataARB( GL_ARRAY_BUFFER_ARB, vertices_vbo.size()*sizeof(GL_FLOAT), &vertices_vbo[0], GL_STATIC_DRAW_ARB);
//— and the same for colors and normals
.
.
}
// ----- In the main ! —
void main(…){
.
.
// Creating openGL context
.
.
g_fVBOSupported = IsExtensionSupported( “GL_ARB_vertex_buffer_object” );
//g_fVBOSupported =FALSE;
if( g_fVBOSupported )
{
// Get Pointers To The GL Functions
glGenBuffersARB = (PFNGLGENBUFFERSARBPROC) wglGetProcAddress(“glGenBuffersARB”);
glBindBufferARB = (PFNGLBINDBUFFERARBPROC) wglGetProcAddress(“glBindBufferARB”);
glBufferDataARB = (PFNGLBUFFERDATAARBPROC) wglGetProcAddress(“glBufferDataARB”);
glDeleteBuffersARB = (PFNGLDELETEBUFFERSARBPROC) wglGetProcAddress(“glDeleteBuffersARB”);
// Load Vertex Data Into The Graphics Card Memory
}
.
.
vector<MyClass> pipelines;
for (int i=0;i<10;i++){
pipelines.pushback(MyClass());
pipelines[i].Init(…);
pipelines[i].CreateVBO();
}
}// end main
//////////////////////////////////////////
What you expect is having 10 pipelines objects in VBO ready to
render. But what you get is 10 pipelines objects all the same color , vertices, normals. I checked with the Visual 2008 debugger,surprisingly I had different valid IDs for colorsID,verticesID,normalsID and this was ok, but in each object they were the same IDs. So the 10 pipelines drawn were actually only one: the last created VBO.
Before you ask:
I think the call routins are mapped correctly:
#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_STATIC_DRAW_ARB 0x88E4
typedef void (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef void (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef void (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef void (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
// VBO Extension Function Pointers
PFNGLGENBUFFERSARBPROC glGenBuffersARB = NULL; // VBO Name Generation Procedure
PFNGLBINDBUFFERARBPROC glBindBufferARB = NULL; // VBO Bind Procedure
PFNGLBUFFERDATAARBPROC glBufferDataARB = NULL; // VBO Data Loading Procedure
PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = NULL; // VBO Deletion Procedure
BOOL g_fVBOSupported = FALSE;
When I push my objects into the vector the OpenGL context is ready to use.I have no access violations or so. I tried to run the program on different very modern computers all supporting OpenGL over 3,.0 like Intel Graphics HD, NVidia . The drivers are all updated, this cant be the problem. The platform is win7 64bit.
Im very unhappy with this and have to solve this in a few days, I would appreciate if you could give me some hints.
Thanks! K.T