0

これが今の様子です(下のテクスチャが見えるように半分だけ描いています)。

d

ズーム (建物は完全にランダムな座標を持っているよう df です )ここに画像の説明を入力

もう一つの例 ここに画像の説明を入力

ここでテクスチャをロードします。

glGenTextures(sceneList.count(), &mTextureID[0]);

for (QList<SceneObject*>::ConstIterator i = sceneList.begin();i!=sceneList.end();++i) {
    Mesh* p = dynamic_cast<Mesh*>(*i);
    if(p){
        if (p->HasTexture()){
            QImage* a =  p->Mat().GetTexture()->GetImage();
            *a= QGLWidget::convertToGLFormat(*a);
            glEnable(GL_TEXTURE_2D);
            glBindTexture(GL_TEXTURE_2D, mTextureID[counter]);
            glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, p->Mat().GetTexture()->ImageSize().width() , p->Mat().GetTexture()->ImageSize().height() , 0, GL_RGBA, GL_UNSIGNED_BYTE, a.bits());
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
            glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
            glDisable(GL_TEXTURE_2D);
        }
    }
    counter++;
}
}

次に、すべてのメッシュに対してこれを行います:

glBindTexture(GL_TEXTURE_2D, mTextureID[counter]);     //where counter=texture for current mesh
...
const QList<Vector3D> vertices=p.Vertices();
QList<Face>& faccie=p.Faces();
int numerofacce=faccie.count();
QList<Vector3D>& normals =p.Normals();
int numerovertici=0
for (int t = 0; t < numerofacce; ++t) {
    glEnable(GL_TEXTURE_2D);
    ...
    switch(f.numVertici) {
    case 1:
        a[1]++;
        face_mode = GL_POINTS;
        glBegin(face_mode);
        if(hasNormals)
            glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
            glVertex3fv(&vertices[lista[0]].pos[0]);
        numerovertici++;
        break;
    case 2:

        face_mode = GL_LINES;
        glBegin(face_mode);
        if(hasNormals){
            glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
            glVertex3fv(&vertices[lista[0]].pos[0]);
            glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
            glVertex3fv(&vertices[lista[1]].pos[0]);
        }
        else{
            glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
            glVertex3fv(&vertices[lista[0]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
            glVertex3fv(&vertices[lista[1]].pos[0]);
        }
        numerovertici+=2;
        break;
    case 3:

        face_mode = GL_TRIANGLES;
        glBegin(face_mode);
        if (numerovertici<p.Vertices().count()-3){
        if(hasNormals){
            glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
            glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
            glVertex3fv(&vertices[lista[0]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
            glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
            glVertex3fv(&vertices[lista[1]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+2).x, p.TextureCoords().at(numerovertici+2).y);
            glNormal3fv(&normals[(f.normalIndex)[2]].pos[0]);
            glVertex3fv(&vertices[lista[2]].pos[0]);
        }
        else{
            glTexCoord2f(p.TextureCoords().at(numerovertici).x, p.TextureCoords().at(numerovertici).y);
            glVertex3fv(&vertices[lista[0]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+1).x, p.TextureCoords().at(numerovertici+1).y);
            glVertex3fv(&vertices[lista[1]].pos[0]);
            glTexCoord2f(p.TextureCoords().at(numerovertici+2).x, p.TextureCoords().at(numerovertici+2).y);
            glVertex3fv(&vertices[lista[2]].pos[0]);
        }
        numerovertici+=3;
        break;
    default: face_mode = GL_POLYGON; break;
    }
    glDisable(GL_TEXTURE_2D);
    ...

PRE:頂点数=テクスチャ座標の数

すべての glTexCoord2f には、 p.TextureCoords().at(numerovertici+2).x のようなものが含まれています。

*p* is the current mesh
*TextureCoords()* is a QList<Vector3D> that contains all the 2D coords
*at(numerovertici)* : takes from TextureCoords List the "numerovertici" element
*.x* taking x coordinate

そのため、「numerovertici」という名前の頂点カウンターを使用して、描画された頂点の数を記憶しています。各頂点を描画する前に、対応するテクスチャ座標を呼び出しています。

これは座標の問題ですか (問題ないと確信しています)、それとも別のことでしょうか?

PS: glvertex の直前に glTexCoord2f を使用してみましたが、違いはありません。

4

0 に答える 0