Hello all,
I have run into a peculiar problem, I have walked through my code many times. In this first post I will only post the portions of the code that are close to my issue. I believe I have isolated my problem down to two functions but I can’t seem to bridge the gap.
First I am on Window7 64bit using GLEW 1.5.8 and OpenGL 3.1.0.
I have VBOs Shaders and Textures all wraped into one class, and this class has a conditional draw function depending on what you want drawn. Now when I read my data from a file (vertices, normals, tex_coordinates) my images appears just fine. However when I pass in arrays of data and try to load them into the VBO I get a black screen. Lets start with the problem so here is my definition of the data:
float vertices[18] = {
-2.1, 0, 2.1,
-2.1, 0, -2.1,
2.1, 0, 2.1,
-2.1, 0, -2.1,
2.1, 0, -2.1,
2.1, 0, 2.1
};
float normals[18] = {
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0,
0.0, 0.0, 1.0
};
float tex_coord[12] = {
0.0, 0.0,
1.0, 0.0,
0.0, 1.0,
1.0, 0.0,
1.0, 1.0,
0.0, 1.0
};
Now I call my member function side my class like this
eelse if(!(vbo_shader.loadClientData(vertices,normals,tex_coord,6))){
cout << “ERROR: Could Load Your Clients Content” << endl;
exit(0);
}
The member functions is this:
bool VBOShaderLibrary::loadClientData(float* V, float* N, float* T, int number_of_vertices) {
bool contentLoaded = true;
try {
this->vertices = new Vertex[number_of_vertices];
this->normals = new Normal[number_of_vertices];
this->tex_coord = new TexCoord[number_of_vertices];
cout << "Vertices Data " << endl;
int vert_index = 0;
for(int x = 0; x < number_of_vertices*3; x+=3) {
Vertex v(V[x],V[x+1],V[x+2]);
this->vertices[vert_index] = v;
cout << "<" << this->vertices[vert_index].coordX << ", "
<< this->vertices[vert_index].coordY << ", "
<< this->vertices[vert_index].coordZ
<< ">" << endl;
vert_index++;
}
cout << "Normal Data" << endl;
int norm_index = 0;
for(int y = 0; y < number_of_vertices*3; y+=3) {
Normal n(N[y],N[y+1],N[y+2]);
this->normals[norm_index] = n;
cout << "<" << this->normals[norm_index].compoX << ", "
<< this->normals[norm_index].compoY << ", "
<< this->normals[norm_index].compoZ
<< ">" << endl;
norm_index++;
}
cout << "TexCoord Data " << endl;
int tex_coord_index = 0;
for(int z = 0; z < number_of_vertices*2; z+=2) {
TexCoord t(T[z],T[z+1]);
this->tex_coord[tex_coord_index] = t;
cout << "<" << tex_coord[tex_coord_index].texcoordS << ", "
<< this->tex_coord[tex_coord_index].texcoordT
<< ">" << endl;
tex_coord_index++;
}
cout << endl;
int SIZE=this->verticesLoaded;
this->pglGenBuffersARB(1,&VBOId);
this->pglBindBufferARB(GL_ARRAY_BUFFER_ARB,VBOId);
this->pglBufferDataARB(GL_ARRAY_BUFFER_ARB,SIZE*(sizeof(Vertex)+sizeof(Normal)+sizeof(TexCoord)),0,GL_DYNAMIC_DRAW_ARB );
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,0,SIZE*sizeof(Vertex),this->vertices);
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,SIZE*sizeof(Vertex),SIZE*sizeof(Normal),this->normals);
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,SIZE*(sizeof(Vertex)+sizeof(Normal)),SIZE*sizeof(TexCoord),this->tex_coord);
cout << "VBOs Initialized" << endl;
this->useVBOs = true;
}catch(...){
cout << "ERROR: When Loading VBOs" << endl;
contentLoaded = false;
this->useVBOs = false;
}
if(this->vertices && this->normals && this->tex_coord) {
delete this->vertices;
delete this->normals;
delete this->tex_coord;
}
return contentLoaded;
}
As stated before I have everthing else working if the data I pass in come from a file, I parse the file and then load it into the VBO. I would like to post some more code but I want to see what response I get first
Thank you, Matthew Hoggan