これは、テクスチャ マッピングを機能させるための最初の試みです。
これは私の実装です:
グローバル フィールド:
GLuint texture[big]; // Storage for some Textures
int globalcounter;
メッシュ描画:
ApplyMaterial(mesh->Materials()); //set material properties,works fine
DrawSingleObject(*mesh);
描画方法:
DrawSingleObject(Mesh& p){
QList<Face>& faces=p.Faces();
int NumberOfFaces=faces.count();
QList<Vector3D>& normals =p.Normals();
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
glGenTextures(1, &texture[globalcounter]); // Create The Texture
glBindTexture(GL_TEXTURE_2D, texture[globalcounter]);
glTexImage2D(GL_TEXTURE_2D, 0, 3, 256 , 256 , 0, GL_RGB, GL_UNSIGNED_BYTE, p.Mat().GetTexture()->Data() );
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
for (int t = 0; t < NumberOfFaces; ++t) {
Face& f = faces[t];
GLenum face_mode;
int* lista=f.arrayVertici;
const QList<Vector3D> vertices=p.Vertices();
int* listaNorm=f.normalIndex;
switch(f.VertexNumber) {
case 1:
face_mode = GL_POINTS;
glBegin(face_mode);
if(hasNormals)
glNormal3fv(&((normals[listaNorm[0]]).pos[0]));
glTexCoord2f(?);
glVertex3fv(&vertices[lista[0]].pos[0]);
break;
case 2:
face_mode = GL_LINES;
glBegin(face_mode);
if(hasNormals){
glNormal3fv(&((normals[(f.normalIndex)[0]]).pos[0]));
glTexCoord2f(?);
glVertex3fv(&vertices[lista[0]].pos[0]);
glNormal3fv(&((normals[(f.normalIndex)[1]]).pos[0]));
glTexCoord2f(?);
glVertex3fv(&vertices[lista[1]].pos[0]);
}
else{
glVertex3fv(&vertices[lista[0]].pos[0]);
glVertex3fv(&vertices[lista[1]].pos[0]);
}
break;
case 3:
face_mode = GL_TRIANGLES;
glBegin(face_mode);
if(hasNormals){
glNormal3fv(&normals[(f.normalIndex)[0]].pos[0]);
glTexCoord2f(?);
glVertex3fv(&vertices[lista[0]].pos[0]);
glNormal3fv(&normals[(f.normalIndex)[1]].pos[0]);
glTexCoord2f(?);
glVertex3fv(&vertices[lista[1]].pos[0]);
glNormal3fv(&normals[(f.normalIndex)[2]].pos[0]);
glTexCoord2f(?);
glVertex3fv(&vertices[lista[2]].pos[0]);
}
else{
glVertex3fv(&vertices[lista[0]].pos[0]);
glVertex3fv(&vertices[lista[1]].pos[0]);
glVertex3fv(&vertices[lista[2]].pos[0]);
}
break;
default: face_mode = GL_POLYGON; break;
}
glEnd();
}
glDisable(GL_TEXTURE_2D);
}
メッシュには次のフィールドがあります。
QList<Vector3D> mTextureCoords; //contains Textures coordinates
Material mMat;
マテリアルには次のフィールドがあります。
Texture* mTexture;
テクスチャには次のフィールドがあります。
QImage* mImage;
a dedicated pointer to mImage->bits()
テクスチャが mImage に正しく読み込まれるようになりました。
質問:
- バインディング: 頂点描画の前にテクスチャをバインドするのは正しいですか?これは正しい実装ですか?
- Vector3D テクスチャ座標を使用して特定のメッシュにテクスチャをロードする方法を説明していただけますか?私の主な問題は、テクスチャの頂点リストが一般的 (面ではなくメッシュにバインド) であるのに対し、面を繰り返しレンダリングすることだと思います。