OpenGL GLUTプロジェクトで、クラスを使用してテクスチャを読み込もうとするときに問題があります。 テクスチャを含むコードがあります:テクスチャが表示されない - GLUT OpenGL
モデルクラスのサブクラスからテクスチャモデルを宣言します。
TextureModel * title = new TextureModel("Box.obj", "title.raw");
TextureModelサブクラスのコンストラクタメソッド:
TextureModel(string fName, string tName) : Model(fName), textureFile(tName)
{
material newMat = {{0.63,0.52,0.1,1.0},{0.63,0.52,0.1,1.0},{0.2,0.2,0.05,0.5},10};
Material = newMat;
// enable texturing
glEnable(GL_TEXTURE_2D);
loadcolTexture(textureFile);
glGenTextures(1, &textureRef);
// specify the filtering method
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
// associate the image read in to the texture to be applied
gluBuild2DMipmaps(GL_TEXTURE_2D, 3, 256, 256, GL_RGB, GL_UNSIGNED_BYTE, image_array);
}
テクスチャロード機能RAWファイル内のデータを読み込むために:三角形を描画する
int loadcolTexture(const string fileName) {
ifstream inFile;
inFile.open(fileName.c_str(), ios::binary);
if (!inFile.good())
{
cerr << "Can't open texture file " << fileName << endl;
return 1;
}
inFile.seekg (0, ios::end);
int size = inFile.tellg();
image_array = new char [size];
inFile.seekg (0, ios::beg);
inFile.read (image_array, size);
inFile.close();
return 0;}
方法:
virtual void drawTriangle(int f1, int f2, int f3, int t1, int t2, int t3, int n1, int n2, int n3)
{
glColor3f(1.0,1.0,1.0);
glBegin(GL_TRIANGLES);
glBindTexture(GL_TEXTURE_2D, textureRef);
glNormal3fv(&normals[n1].x);
glTexCoord2f(textures[t1].u, textures[t1].v);
glVertex3fv(&Model::vertices[f1].x);
glNormal3fv(&normals[n2].x);
glTexCoord2f(textures[t2].u, textures[t2].v);
glVertex3fv(&Model::vertices[f2].x);
glNormal3fv(&normals[n3].x);
glTexCoord2f(textures[t3].u, textures[t3].v);
glVertex3fv(&Model::vertices[f3].x);
glEnd();
}
照明、デプステスト、ダブルバッファリングも有効になっています。
モデルとライティングは正常に機能しますが、テクスチャは表示されません。それがうまくいかない理由は素晴らしいでしょう。コメントを追加するには
少なくとも、TextureModelコンストラクタで 'glBindTexture'の呼び出しがありません。 – user786653