PDA

View Full Version : Vertexarrays problem



Vlasko
11-13-2004, 10:20 AM
I've an object(loaded from md2)everything is loaded fine(i think :-)).When i show it classically(glBegin(GL_TRIANGLES) .... normals textures vertices glEnd()) it is shown correctly but i want to use vertex arrays(and VBO's later)i've loaded everything into arrays but there's the problem it chrashes by calling glDrawArrays,glArrayElement(even with first field!) and aslo by calling glDrawElements.What could be the problem?
float *tevectorarray,*tenormalarray,*tetexcoordarray;
FILE *file;
tevectorarray=new float[numTriangles*9];
tenormalarray=new float[numTriangles*9];
tetexcoordarray=new float[numTriangles*6];
for(i=0;i<numTriangles;i++)
{ //for testing only
tevectorarray[9*i]=KeyFrames[FrameNumber].VertexArray[3*i].vertex[0];
tevectorarray[9*i+1]=KeyFrames[FrameNumber].VertexArray[3*i].vertex[1];
tevectorarray[9*i+2]=KeyFrames[FrameNumber].VertexArray[3*i].vertex[2];
tevectorarray[9*i+3]=KeyFrames[FrameNumber].VertexArray[3*i+1].vertex[0];
tevectorarray[9*i+4]=KeyFrames[FrameNumber].VertexArray[3*i+1].vertex[1];
tevectorarray[9*i+5]=KeyFrames[FrameNumber].VertexArray[3*i+1].vertex[2];
tevectorarray[9*i+6]=KeyFrames[FrameNumber].VertexArray[3*i+2].vertex[0];
tevectorarray[9*i+7]=KeyFrames[FrameNumber].VertexArray[3*i+2].vertex[1];
tevectorarray[9*i+8]=KeyFrames[FrameNumber].VertexArray[3*i+2].vertex[2];
tenormalarray[9*i+0]=KeyFrames[FrameNumber].NormalArray[3*i].vertex[0];
tenormalarray[9*i+1]=KeyFrames[FrameNumber].NormalArray[3*i].vertex[1];
tenormalarray[9*i+2]=KeyFrames[FrameNumber].NormalArray[3*i].vertex[2];
tenormalarray[9*i+3]=KeyFrames[FrameNumber].NormalArray[3*i+1].vertex[0];
tenormalarray[9*i+4]=KeyFrames[FrameNumber].NormalArray[3*i+1].vertex[1];
tenormalarray[9*i+5]=KeyFrames[FrameNumber].NormalArray[3*i+1].vertex[2];
tenormalarray[9*i+6]=KeyFrames[FrameNumber].NormalArray[3*i+2].vertex[0];
tenormalarray[9*i+7]=KeyFrames[FrameNumber].NormalArray[3*i+2].vertex[1];
tenormalarray[9*i+8]=KeyFrames[FrameNumber].NormalArray[3*i+2].vertex[2];
tetexcoordarray[6*i]=TexCoordArray[3*i].x;
tetexcoordarray[6*i+1]=TexCoordArray[3*i].y;
tetexcoordarray[6*i+2]=TexCoordArray[3*i+1].x;
tetexcoordarray[6*i+3]=TexCoordArray[3*i+1].y;
tetexcoordarray[6*i+4]=TexCoordArray[3*i+2].x;
tetexcoordarray[6*i+5]=TexCoordArray[3*i+2].y;
}
file=fopen("vertex.log","w");
for(i=0;i<numTriangles*3;i++)
{
fprintf(file,"%d %f %f %f \n",i,tevectorarray[3*i],tevectorarray[3*i+1],tevectorarray[3*i+2]);
}
fclose(file);
file=fopen("normals.log","w");
for(i=0;i<numTriangles*3;i++)
{
fprintf(file,"%d %f %f %f \n",i,tenormalarray[3*i],tenormalarray[3*i+1],tenormalarray[3*i+2]);
}
fclose(file);
file=fopen("texture.log","w");
for(i=0;i<numTriangles*3;i++)
{
fprintf(file,"%d %f %f \n",i,tetexcoordarray[2*i],tetexcoordarray[2*i+1]);
}
fclose(file);
glEnableClientState(GL_NORMAL_ARRAY);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glEnableClientState(GL_VERTEX_ARRAY);
glEnable(GL_COLOR_MATERIAL);
glFrontFace(GL_CW);
glColor3f(1.0f,1.0f,1.0f);
if(oglv.ActiveTexture!=0xFFFF)
{
glEnable(GL_TEXTURE_2D);
glBindTexture(GL_TEXTURE_2D,oglv.texture_id[oglv.ActiveTexture]);
}
if(oglv.Vertex_VBO_id==0)
{
glTexCoordPointer(2,GL_FLOAT,0,&amp;tetexcoordarray);
if(FrameNumber==0xFFFF)
{
glVertexPointer(3,GL_FLOAT,0,deltaFrame.VertexArra y);
glNormalPointer(GL_FLOAT,0,deltaFrame.NormalArray) ;
}
else
{
glVertexPointer(3,GL_FLOAT,0,tevectorarray); //changed for testing
glNormalPointer(GL_FLOAT,0,tenormalarray);
}
glDrawArrays(GL_TRIANGLES,0,numTriangles);

Bob
11-13-2004, 02:25 PM
Originally posted by Vlasko:

float *tevectorarray,*tenormalarray,*tetexcoordarray;
...
glTexCoordPointer(2,GL_FLOAT,0,&amp;tetexcoordarray);Y ou're passing the address of the pointer when you should pass the value of it.

Vlasko
11-14-2004, 02:53 AM
changed that but it doesn't solve the problem

Aeluned
11-15-2004, 07:44 AM
Are you by any chance using a 3DLabs realizm board?

Vlasko
11-15-2004, 12:38 PM
no I'm not :-) I've updated drivers it helped a bit.I've used glGetPointerv to see if my arrays are bound and it seems that they are not.


GLfloat *p;
glTexCoordPointer(2,GL_FLOAT,0,tetexcoordarray);
glVertexPointer(3,GL_FLOAT,0,tevectorarray);
glNormalPointer(GL_FLOAT,0,tenormalarray);
glGetPointerv(GL_NORMAL_ARRAY,(GLvoid **)&amp;p);
glGetPointerv(GL_VERTEX_ARRAY,(GLvoid **)&amp;p);
glGetPointerv(GL_TEXTURE_COORD_ARRAY,(GLvoid **)&amp;p)
with the debugger I've checked that p doesn't change!