简体   繁体   English

访问 Assimp 纹理坐标数据时 OpenGL 应用程序崩溃

[英]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;
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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