私はCodeBlocksでGlutプロジェクトを実行していますが、私はビットマップ画像で球体をテクスチャリングするためのクラス "imageloader"を持っています。このような画像の場所を指定するとうまく動作しますloadTexture(loadBMP("C:\\Users\\Ndumiso\\Desktop\\Project1\\images\\earth.bmp"));
"images"という名前のフォルダを作成し、そのフォルダに画像をコピーしました。 .exe実行ファイル(つまり、ビン\デバッグ\ earth.bmp)C++ OpenGLテクスチャ画像が見つかりません
あるよう Here's how it looks when you run it
は、あなたの心は、私はまた同じ場所内の同じイメージを持っているが、私はこのloadTexture(loadBMP("earth.bmp"));
のようにそれを行う際に失敗しました画像が見つかりません。
長い絶対パスは、プロジェクトが別のコンピュータに移動するたびに発生します。プロジェクトを実行する前に毎回パスを変更する必要があります。そうしないと、エラーが発生します。だから私はこのような私のプロジェクトを提出することはできません。
はここに私のmain.cppに中のコードだけスニペット(あなたはより多くのコードが必要な場合は私に知らせて)です:コメントで述べたように
//Makes the image into a texture, and returns the id of the texture
GLuint loadTexture(Image* image) {
GLuint textureId;
glGenTextures(1, &textureId); //Make room for our texture
glBindTexture(GL_TEXTURE_2D, textureId); //Tell OpenGL which texture to edit
//Map the image to the texture
glTexImage2D(GL_TEXTURE_2D, //Always GL_TEXTURE_2D
0, //0 for now
GL_RGB, //Format OpenGL uses for image
image->width, image->height, //Width and height
0, //The border of the image
GL_RGB, //GL_RGB, because pixels are stored in RGB format
GL_UNSIGNED_BYTE, //GL_UNSIGNED_BYTE, because pixels are stored
//as unsigned numbers
image->pixels); //The actual pixel data
return textureId; //Returns the id of the texture
}
GLuint _textureId2;
void initRendering() {
glEnable(GL_DEPTH_TEST);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT0);
glEnable(GL_NORMALIZE);
glEnable(GL_COLOR_MATERIAL);
quad = gluNewQuadric();
_textureId2 = loadTexture(loadBMP("C:\\Users\\Ndumiso\\Desktop\\TestClasses\\images\\earth.bmp"));
}
、現在の作業ディレクトリは、IDEによって変更される可能性があります。作業ディレクトリを変更する方法については、IDEのドキュメントを参照してください。 Visual Studioを使用する場合は、デバッガ設定のプロジェクトプロパティで実行できます。既定では$(ProjectDir)です(.vcxprojファイルのあるフォルダ)。 – Drop