# Cannot Get The Texture Showed Up Correctly glDrawElements

I still have this problem almost 1 month. Tried to search on Google but did not find any solution to this. I have loaded all the data correctly but don't know why the texture came up like this.

struct SVertex
{
public:
float X, Y, Z;
};

struct STexture
{
public:
float U, V;
};

struct SFace
{
public:
int X, Y, Z;
};

class CBMap
{
public:
struct SMesh
{
SVertex *Vertex;
SVertex *Normal;
STexture *TexCoord;
SFace *Face;
SFace *FaceNormal;

char Texture[32];
int TextureID;
int TotalVertice;
int TotalNormal;
int TotalFace;
};

SMesh* Mesh;

CBMap();
~CBMap();

int TotalMesh;

int Get_TotalMesh(FILE* pFile);
int GetData(FILE* pFile);
};


CPP

int CBMap::Load(char* szFile)
{
FILE* pFile = fopen(szFile, "r");

if (!pFile) return 0;

if (!iBMap)
{
printf("BMAP file is not valid\n");
return 0;
}

TotalMesh   = Get_TotalMesh(pFile);
Mesh        = new SMesh[TotalMesh];
GetData(pFile);

int iMesh = 0;

char* pJunk;

while (!feof(pFile))
{

{
fscanf(pFile, "%s", Mesh[iMesh].Texture);
}

{
fscanf(pFile, "%d", &pJunk);
Mesh[iMesh].Vertex = (SVertex*)malloc(sizeof (SVertex) * Mesh[iMesh].TotalVertice);

for (int i = 0; i < Mesh[iMesh].TotalVertice; ++i)
{
fscanf(pFile, "%f %f %f", &Mesh[iMesh].Vertex[i].X, &Mesh[iMesh].Vertex[i].Y, &Mesh[iMesh].Vertex[i].Z);
}
}

{
fscanf(pFile, "%d", &pJunk);
Mesh[iMesh].TexCoord = (STexture*)malloc(sizeof (STexture) * Mesh[iMesh].TotalVertice);

for (int i = 0; i < Mesh[iMesh].TotalVertice; ++i)
{
fscanf(pFile, "%f %f", &Mesh[iMesh].TexCoord[i].U, &Mesh[iMesh].TexCoord[i].V);
}
}

{
fscanf(pFile, "%d", &pJunk);
Mesh[iMesh].Normal = (SVertex*)malloc(sizeof (SVertex) * Mesh[iMesh].TotalNormal);

for (int i = 0; i < Mesh[iMesh].TotalNormal; ++i)
{
fscanf(pFile, "%f %f %f", &Mesh[iMesh].Normal[i].X, &Mesh[iMesh].Normal[i].Y, &Mesh[iMesh].Normal[i].Z);
}
}

{
fscanf(pFile, "%d", &pJunk);
Mesh[iMesh].Face = (SFace*)malloc(sizeof (SFace) * Mesh[iMesh].TotalFace * 3);
Mesh[iMesh].FaceNormal = (SFace*)malloc(sizeof (SFace) * Mesh[iMesh].TotalFace * 3);

for (int i = 0; i < Mesh[iMesh].TotalFace; ++i)
{
fscanf(pFile, "%d %d %d %d %d %d",  &Mesh[iMesh].Face[i].X, &Mesh[iMesh].Face[i].Y, &Mesh[iMesh].Face[i].Z,
&Mesh[iMesh].FaceNormal[i].X, &Mesh[iMesh].FaceNormal[i].Y, &Mesh[iMesh].FaceNormal[i].Z);
}
}

{
if (iMesh < TotalMesh) iMesh ++;
}
}

fclose(pFile);
return 1;
}


First picture is reality and second picture expectation

• We can barely see the picture. It's too dark. Is this the problem? If not, what do you mean by "the texture came up like this"? Please provide more context and also describe or better show a desired result. – Ivan Aksamentov - Drop Jun 13 '15 at 14:48
• I needed to set the v components to v = 1 - loadedV. this is because opengl uses a different origin for the texture coordinate system than directx – Tobias B Jun 14 '15 at 7:34
• Thanks Tobias but I don't really understand what you explain. Any example? – DavidJr Jun 14 '15 at 8:43
• Tobias, thank you very much, that makes my code works. How to flag your comment as an answer? – DavidJr Jun 15 '15 at 6:14
• I postet it as answer. When I wrote the comment I wasn't sure about it and didn't have the time to research. – Tobias B Jun 15 '15 at 8:12