Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 5 of 5

Thread: Vertexarrays problem

  1. #1
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Vertexarrays problem

    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?
    Code :
    	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.VertexArray); 
    			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);

  2. #2
    Senior Member OpenGL Guru
    Join Date
    Feb 2000
    Location
    Sweden
    Posts
    3,115

    Re: Vertexarrays problem

    Originally posted by Vlasko:
    Code :
    float *tevectorarray,*tenormalarray,*tetexcoordarray;
    ...
    glTexCoordPointer(2,GL_FLOAT,0,&amp;tetexcoordarray);
    You're passing the address of the pointer when you should pass the value of it.

  3. #3
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Re: Vertexarrays problem

    changed that but it doesn't solve the problem

  4. #4
    Advanced Member Frequent Contributor
    Join Date
    Feb 2004
    Location
    Long Island, New York
    Posts
    586

    Re: Vertexarrays problem

    Are you by any chance using a 3DLabs realizm board?

  5. #5
    Intern Contributor
    Join Date
    Mar 2003
    Location
    Slovakia
    Posts
    78

    Re: Vertexarrays problem

    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.
    Code :
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •