PDA

View Full Version : problem with vertex buffer objects



ash1122
06-11-2008, 02:32 AM
Hi,
can somebody plz help me out with vbo(vertex buffer objects). I have a program that creates 30837 polygons (four vertices per polygon, one normal and a color attribute per polygon). Initially the program was implemented using display lists, but im trying to use vbos. i have successfully used vertex arrays, but problem with vbos. At compile time there's no error but at runtime it crashes right at the line where im creating vbo's. Here is the function from the code that creates polygons:


void make_poly(unsigned char **cimage
,float thetamin, float thetamax,
float phimin, float phimax,
int img_height, int img_width,
int *npolygon)
{
int i,j;
float xx,yy,zz;
float xx1,yy1,zz1;
float xx2,yy2,zz2;
float xx3,yy3,zz3;
float xx4,yy4,zz4;
float gnormx,gnormy,gnormz;

float r,rnew,theta,phi, dr,dtheta,dphi;
float dx1,dy1,dz1,dx2,dy2,dz2,dlen;
int bb,gg,rr,ii,jj,iii,jjj;
int bb1,gg1,rr1;
float tmp_dth,tmp_dphi;

r = 1.05;
dtheta = (thetamax - thetamin)/(img_height-1.0) ;
dphi = (phimax - phimin )/(img_width-1.0) ;

int k=0,c=0,d=0,e=0;


// for(j=20;j<img_height-50; j++)
for(j=10;j<img_height-50; j++)
{
// for(i=20;i<img_width-20; i++)
for(i=10;i<img_width-10; i++)
{
phi = phimin + i*dphi;
theta = thetamin +j*dtheta;
bb = cimage[img_height-j][3*i] ;
gg = cimage[img_height-j][3*i+1];
rr = cimage[img_height-j][3*i+2];


if ( (abs(bb-gg)<1) &amp;&amp; (abs(rr-bb)<1) &amp;&amp; (bb>100) )
{
glColor3f(rr/255.0,gg/255.0,bb/255.0);
//printf("%d - HIHIHI\n",c);
//c++;

rnew = r + 0.02;
xx = rnew*sin(theta)*cos(phi);
yy = rnew*sin(theta)*sin(phi);
zz = rnew*cos(theta);

tmp_dth = dtheta;
tmp_dphi = dphi;
ii = i; jj = j;
bb1 = bb ;
gg1 = gg;
rr1 = rr;

while( (bb1==gg1) &amp;&amp; (gg1==rr1) &amp;&amp; (abs(bb1-bb) < CLOUD_DIFF) )
{
cimage[img_height-jj][3*ii] = 0 ;
cimage[img_height-jj][3*ii+1] = 0 ;
cimage[img_height-jj][3*ii+2] = 0 ;
jj++ ;
bb1 = cimage[img_height-jj][3*ii] ;
gg1 = cimage[img_height-jj][3*ii+1];
rr1 = cimage[img_height-jj][3*ii+2];
}

tmp_dth = (jj-j)*dtheta;
jj-- ;

ii = i;
bb1 = bb ;
gg1 = gg;
rr1 = rr;
while( (bb1==gg1) &amp;&amp; (gg1==rr1) &amp;&amp; (abs(bb1-bb)< CLOUD_DIFF) )
{
cimage[img_height-j][3*ii] = 0 ;
cimage[img_height-j][3*ii+1] = 0 ;
cimage[img_height-j][3*ii+2] = 0 ;
ii++ ;
bb1 = cimage[img_height-j][3*ii] ;
gg1 = cimage[img_height-j][3*ii+1];
rr1 = cimage[img_height-j][3*ii+2];
}
tmp_dphi = (ii-i)*dphi;
ii-- ;

for(iii = i; iii <= ii; iii++ )
for(jjj = j; jjj <= jj; jjj++ )
{
cimage[img_height-jjj][3*iii] = 0 ;
cimage[img_height-jjj][3*iii+1] = 0 ;
cimage[img_height-jjj][3*iii+2] = 0 ;
}

xx1 = rnew*sin(theta+tmp_dth)*cos(phi);
yy1 = rnew*sin(theta+tmp_dth)*sin(phi);
zz1 = rnew*cos(theta+tmp_dth);

xx2 = rnew*sin(theta+tmp_dth)*cos(phi+tmp_dphi);
yy2 = rnew*sin(theta+tmp_dth)*sin(phi+tmp_dphi);
zz2 = rnew*cos(theta+tmp_dth);

xx3 = rnew*sin(theta)*cos(phi+tmp_dphi);
yy3 = rnew*sin(theta)*sin(phi+tmp_dphi);
zz3 = rnew*cos(theta);

dx1 = xx1 - xx ;
dy1 = yy1 - yy ;
dz1 = zz1 - zz ;
dx2 = xx3 - xx ;
dy2 = yy3 - yy ;
dz2 = zz3 - zz ;
gnormx = dy1*dz2 - dz1*dy2 ;
gnormy = dz1*dx2 - dx1*dz2 ;
gnormz = dx1*dy2 - dy1*dx2 ;

dy1 = sqrt(gnormx*gnormx+gnormy*gnormy+gnormz*gnormz);
gnormx /= dy1 ;
gnormy /= dy1 ;
gnormz /= dy1 ;

(*npolygon)++;

//glColor3f(rr/255.0,gg/255.0,bb/255.0);
vPolycol[e] = (rr/255.0);
vPolycol[e+1] = (gg/255.0);
vPolycol[e+2] = (bb/255.0);
vPolycol[e+3] = (rr/255.0);
vPolycol[e+4] = (gg/255.0);
vPolycol[e+5] = (bb/255.0);
vPolycol[e+6] = (rr/255.0);
vPolycol[e+7] = (gg/255.0);
vPolycol[e+8] = (bb/255.0);
vPolycol[e+9] = (rr/255.0);
vPolycol[e+10] = (gg/255.0);
vPolycol[e+11] = (bb/255.0);
e = e+12;


vPolynor[d] = gnormx;
vPolynor[d+1] = gnormy;
vPolynor[d+2] = gnormz;
vPolynor[d+3] = gnormx;
vPolynor[d+4] = gnormy;
vPolynor[d+5] = gnormz;
vPolynor[d+6] = gnormx;
vPolynor[d+7] = gnormy;
vPolynor[d+8] = gnormz;
vPolynor[d+9] = gnormx;
vPolynor[d+10] = gnormy;
vPolynor[d+11] = gnormz;
d = d+12;


vPoly[k] = xx;
vPoly[k+1] = yy;
vPoly[k+2] = zz;
vPoly[k+3] = xx1;
vPoly[k+4] = yy1;
vPoly[k+5] = zz1;
vPoly[k+6] = xx2;
vPoly[k+7] = yy2;
vPoly[k+8] = zz2;
vPoly[k+9] = xx3;
vPoly[k+10] = yy3;
vPoly[k+11] = zz3;
k = k+12;

//Render_poly();



}
}
}
Render_poly();
return;
}

void Render_poly(void)
{
printf("vbo = %d\n",vbo1);
printf("size of vPoly = %d\n",(sizeof(float)*LIMIT1));
printf("size of vPoly = %d\n",sizeof(vPoly));
glGenBuffers(1, &amp;vbo1);
printf("HIHIHIH");
glBindBuffer( GL_ARRAY_BUFFER, vbo1);
glBufferData( GL_ARRAY_BUFFER, sizeof(vPoly), vPoly, GL_STATIC_DRAW);

glGenBuffers(1, &amp;vbo2);
glBindBuffer( GL_ARRAY_BUFFER, vbo2);
glBufferData( GL_ARRAY_BUFFER, sizeof(vPolynor), vPolynor, GL_STATIC_DRAW);


glGenBuffers(1, &amp;vbo3);
glBindBuffer( GL_ARRAY_BUFFER, vbo3);
glBufferData( GL_ARRAY_BUFFER, sizeof(vPolycol), vPolycol, GL_STATIC_DRAW);




glEnableClientState(GL_VERTEX_ARRAY);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_COLOR_ARRAY);


glBindBuffer( GL_ARRAY_BUFFER, vbo1);
glVertexPointer(3,GL_FLOAT,0,0);

glBindBuffer( GL_ARRAY_BUFFER, vbo2);
glNormalPointer(GL_FLOAT,0,0);


glBindBuffer( GL_ARRAY_BUFFER, vbo3);
glColorPointer(3,GL_FLOAT,0,0);



glDrawArrays(GL_QUADS,0,123344);

glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
glDisableClientState(GL_NORMAL_ARRAY);


glDeleteBuffers( 1, &amp;vbo1);
glDeleteBuffers( 1, &amp;vbo2);
glDeleteBuffers( 1, &amp;vbo3);



return;

}

djedge
06-12-2008, 11:31 AM
It sounds like unitialized openGL extension.

Do you run glewInit() or something similar before generate buffer ?

ash1122
06-16-2008, 10:26 PM
Thank you very much buddy, program is working now... i gotta take it forward, now there is no crashing problem. Thanks a lot.....