PDA

View Full Version : ARB VBO's working from text file but not on arrays



dudebodacious
03-07-2011, 02:57 AM
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,te x_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,&amp;VBOId);
this->pglBindBufferARB(GL_ARRAY_BUFFER_ARB,VBOId);
this->pglBufferDataARB(GL_ARRAY_BUFFER_ARB,SIZE*(sizeof( Vertex)+sizeof(Normal)+sizeof(TexCoord)),0,GL_DYNA MIC_DRAW_ARB );
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,0,SIZE*siz eof(Vertex),this->vertices);
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,SIZE*sizeo f(Vertex),SIZE*sizeof(Normal),this->normals);
this->pglBufferSubDataARB(GL_ARRAY_BUFFER_ARB,SIZE*(size of(Vertex)+sizeof(Normal)),SIZE*sizeof(TexCoord),t his->tex_coord);
cout << "VBOs Initialized" << endl;
this->useVBOs = true;
}catch(...){
cout << "ERROR: When Loading VBOs" << endl;
contentLoaded = false;
this->useVBOs = false;
}
if(this->vertices &amp;&amp; this->normals &amp;&amp; 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

mbentrup
03-07-2011, 08:52 AM
What is the value of this->verticesLoaded ?

dudebodacious
03-07-2011, 10:44 AM
Wow thank you. It is the small things that kill you somtimes.