Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

FreJa

shouldn't this work?

This topic is 5541 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I''m tying to read info from a text file to create an opengl 3d object (3d model)... each model can have more than one mesh, and thats where the problem is: - I have no problems reading the number of meshes available. - This is my read function:
  
for(int i=0; i<m_iNumMeshes; i++)
	{
		// Read Vertices

		fscanf(file, "    verts %d", &m_pMeshes->m_iNumVerts);
		log.LogWrite("Found vertice\n");
		m_pMeshes->m_pVert = new mdx_vertex_t[m_pMeshes->m_iNumVerts];
		for(int i=0; i<m_pMeshes->m_iNumVerts; i++)
		{
			mdx_vertex_t &v = m_pMeshes->m_pVert[i];
			fscanf(file, "     %f %f %f  %f %f %f  %f %f", &v.position.x, &v.position.y, &v.position.z,
														&v.normal.x, &v.normal.y, &v.normal.z,
														&v.texCoord.x, &v.texCoord.y);
		}

		// Read Faces

		fscanf(file, "    faces %d", &m_pMeshes->m_iNumFaces);
		log.LogWrite("Found face\n");
		m_pMeshes->m_pFace = new mdx_face_t[m_pMeshes->m_iNumFaces];
		for(int j=0; j<m_pMeshes->m_iNumFaces; j++)
		{
			mdx_face_t &f = m_pMeshes->m_pFace[j];
			fscanf(file, "     %d %d %d", &f.vertIndex[0], &f.vertIndex[1], &f.vertIndex[2]);
		}
	}
  
- This is my draw function:
  
for(int w=0; w<m_iNumMeshes; w++)
	{
		glColor3f(1.0, 1.0, 1.0);
		glTranslatef(0.0, 0.0, -5.0);
		glRotatef(xRot, 1.0, 0.0, 0.0);
		glRotatef(yRot, 0.0, 1.0, 0.0);
		glBegin(GL_TRIANGLES);
		for(int i=0; i<m_pMeshes->m_iNumFaces; i++)
		{
			for(int j=0; j<3; j++)
			{
				int vertIndex = m_pMeshes->m_pFace[i].vertIndex[j];
				glNormal3f(m_pMeshes->m_pVert[vertIndex].normal.x, m_pMeshes->m_pVert[vertIndex].normal.y, m_pMeshes->m_pVert[vertIndex].normal.z); 
				glVertex3f(m_pMeshes->m_pVert[vertIndex].position.x, m_pMeshes->m_pVert[vertIndex].position.y, m_pMeshes->m_pVert[vertIndex].position.z); 
			}
		}
		glEnd();
	}
  
and when trying to read something like this:
nummeshes 2
beginnode
  textures 1
   "C:\test.bmp"
    verts 24
     -1.0 -1.0 0.0  0.0 0.0 -1.0  0.0 0.0
     -1.0 1.0 0.0  0.0 0.0 -1.0  0.0 0.0
     1.0 1.0 0.0  0.0 0.0 -1.0  0.0 0.0
     1.0 -1.0 0.0  0.0 0.0 -1.0  0.0 0.0
     -1.0 -1.0 1.0  0.0 0.0 1.0  0.0 0.0
     1.0 -1.0 1.0  0.0 0.0 1.0  0.0 0.0
     1.0 1.0 1.0  0.0 0.0 1.0  0.0 0.0
     -1.0 1.0 1.0  0.0 0.0 1.0  0.0 0.0
     -1.0 -1.0 0.0  0.0 -1.0 0.0  0.0 0.0
     1.0 -1.0 0.0  0.0 -1.0 0.0  0.0 0.0
     1.0 -1.0 1.0  0.0 -1.0 0.0  0.0 0.0
     -1.0 -1.0 1.0  0.0 -1.0 0.0  0.0 0.0
     1.0 -1.0 0.0  1.0 0.0 0.0  0.0 0.0
     1.0 1.0 0.0  1.0 0.0 0.0  0.0 0.0
     1.0 1.0 1.0  1.0 0.0 0.0  0.0 0.0
     1.0 -1.0 1.0  1.0 0.0 0.0  0.0 0.0
     1.0 1.0 0.0  0.0 1.0 0.0  0.0 0.0
     -1.0 1.0 0.0  0.0 1.0 0.0  0.0 0.0
     -1.0 1.0 1.0  0.0 1.0 0.0  0.0 0.0
     1.0 1.0 1.0  0.0 1.0 0.0  0.0 0.0
     -1.0 1.0 0.0  -1.0 0.0 0.0  0.0 0.0
     -1.0 -1.0 0.0  -1.0 0.0 0.0  0.0 0.0
     -1.0 -1.0 1.0  -1.0 0.0 0.0  0.0 0.0
     -1.0 1.0 1.0  -1.0 0.0 0.0  0.0 0.0
    faces 12
     0 1 2
     2 3 0
     4 5 6
     6 7 4
     8 9 10
     10 11 8
     12 13 14
     14 15 12
     16 17 18
     18 19 16
     20 21 22
     22 23 20
endnode
beginnode
  textures 0
    verts 4
     -3.0 -3.0 0.0  0.0 0.0 -1.0  0.0 0.0
     -3.0 3.0 0.0  0.0 0.0 -1.0  0.0 0.0
     0.0 3.0 0.0  0.0 0.0 -1.0  0.0 0.0
     0.0 -3.0 0.0  0.0 0.0 -1.0  0.0 0.0
    faces 2
     0 1 2
     2 3 0
endnode
 
I get a runtime error, and If I debug it, I get an "Object reference not set to an instance of an object" in the glNormal3f line... Whats the prob? Thanks

Share this post


Link to post
Share on other sites
Advertisement

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!