简体   繁体   中英

OpenGL Application crashes when accessing Assimp Texture Coordinate Data

I am trying to access the Texture Coordinate of a Cube model made in blender.

for (int i = 0; i < mMesh->mNumVertices; i++) {
    std::cout << mMesh->mTextureCoords[i][0].x << " " << mMesh->mTextureCoords[i][0].y << std::endl;
}

Why is this happening.
The application window launches but the red color background doesnt display.
And the first coords also get printed
0 1
How do i solve this.
Removing this code doesn't lead to a crash.

This should be:

for (int i = 0; i < mMesh->mNumVertices; i++)
{
    std::cout << mMesh->mTextureCoords[0][i].x << " " << mMesh->mTextureCoords[0][i].y << std::endl;
}

Looks like you messed up the first and second array arguments. Also, it is good practice to check if the mesh has texture coordinates or not. Then the code becomes

if (mMesh->HasTextureCoords(0)) //HasTextureCoords is an assimp function
{
    for (int i = 0; i < mMesh->mNumVertices; i++)
    {
        std::cout << mMesh->mTextureCoords[0][i].x << " " << mMesh- >mTextureCoords[0][i].y << std::endl;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM