Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/wpf/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 使用openGL的图像加载,SOIL_Image_Opengl_Textures_Glut_Soil - Fatal编程技术网

Image 使用openGL的图像加载,SOIL

Image 使用openGL的图像加载,SOIL,image,opengl,textures,glut,soil,Image,Opengl,Textures,Glut,Soil,我尝试了许多使用SOIL在openGL中加载和显示图像的示例。 运行下面的源代码时,它只显示一个没有图像的wite quad。 我试图打开一个名为:foto的图像。 我将图像文件放在程序的文件夹中 bool* keyStates = new bool[256]; GLuint texture[0]; void resize(int height, int width) { const float ar = (float) width / (float) height; glVi

我尝试了许多使用SOIL在openGL中加载和显示图像的示例。 运行下面的源代码时,它只显示一个没有图像的wite quad。 我试图打开一个名为:foto的图像。 我将图像文件放在程序的文件夹中

bool* keyStates = new bool[256];
GLuint texture[0];

void resize(int height, int width) {
    const float ar = (float) width / (float) height;
    glViewport(0, 10, width, height);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glFrustum(-ar, ar, -1.0, 1.0, 2.0, 90.0);
    //gluLookAt(0, 2, 0, -1, 1, -3, 0, 1, 0);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity() ;
}
void keyOperations (void) {
    if (!keyStates['a']) {}
}
static void Draw(void)
{
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glLoadIdentity();
    glTranslatef(0.0f,0.0f,-5.0f);
    texture[0] = SOIL_load_OGL_texture // load an image file directly as a new OpenGL texture
    (
        "foto.png",
        SOIL_LOAD_AUTO,
        SOIL_CREATE_NEW_ID,
        SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT
    );
// allocate a texture name

    glBindTexture(GL_TEXTURE_2D, texture[0]);
    glBegin(GL_QUADS);
    glTexCoord2f(0.0f, 0.0f); glVertex3f(-1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 0.0f); glVertex3f( 1.0f, -1.0f,  1.0f);
    glTexCoord2f(1.0f, 1.0f); glVertex3f( 1.0f,  1.0f,  1.0f);
    glTexCoord2f(0.0f, 1.0f); glVertex3f(-1.0f,  1.0f,  1.0f);
    glEnd();
    glutSwapBuffers();
}
void keyPressed (unsigned char key, int x, int y) {
    keyStates[key] = false;
}
void keyUp (unsigned char key, int x, int y) {
    keyStates[key] = true;
}
int main(int argc, char **argv)
{
    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
    glutInit(&argc, argv);
    glutInitWindowSize(600, 600);
    glutCreateWindow("ugh fml");
    glutReshapeFunc(resize);
    glutDisplayFunc(Draw);
    glutKeyboardFunc(keyPressed);
    glutKeyboardUpFunc(keyUp);
    /////////////////////////////////////
    glEnable(GL_TEXTURE_2D);
    glShadeModel(GL_SMOOTH);
    glClearColor(0.0f, 0.0f, 0.0f, 0.5f);
    glClearDepth(1.0f);
    glEnable(GL_DEPTH_TEST);
    glDepthFunc(GL_LEQUAL);
    glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
    glutMainLoop();
}

您正在使用相对路径访问
foto.png

确保你的工作在你期望的地方


一些IDE喜欢将工作目录更改为可执行文件所在位置以外的其他位置。

调用
SOIL\u load\u OGL\u texture()
后是
texture[0]
非零?如果是0,什么是C++?SoLyLaSTyRultRESUTE()/CUT>返回?当我输入:CUTE还注意到,<代码>纹理> /COD>数组的长度为0。除了普通C++数组之外,纹理数组的长度是否长短?谢谢,我四处寻找,对于那些正确设置目录的函数,您需要一个特殊的库吗?请查看
chdir()
,尽管修复IDE配置会更容易。