OpenGL、SOIL 库和纹理矩形

发布于 2024-07-17 18:27:08 字数 1448 浏览 13 评论 0原文

我正在尝试使用 SOIL 和 GLUT 在 OpenGL 中制作一个简单的纹理矩形。

这是我的 Display 函数(由 glutDisplayFunc(Display) 在 main 中执行):

void Display ()
{
    GLuint tex_2d;

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    glClear (GL_COLOR_BUFFER_BIT);
    glClearColor (1.0,1.0,1.0,1.0);
    gluLookAt (eyex,eyey,eyez,centerx,centery,centerz,0,1,0);

    glEnable(GL_TEXTURE_2D);
     tex_2d = SOIL_load_OGL_texture
    (
        "img.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
    );
     if( 0 == tex_2d )
    {
        printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
        exit(1);
    }

   glBindTexture(GL_TEXTURE_2D, tex_2d);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); 

    glColor3f (0.0,0.0,0.0);
    glBegin(GL_POLYGON);

                       glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
                       glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
                       glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
                       glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);

     glEnd();   
    glDisable(GL_TEXTURE_2D);
    glFlush ();
    glutSwapBuffers();
}

这样只能看到一个没有任何纹理的黑色矩形。 我正在尝试用这几个小时做点什么。 请帮忙,提前致谢。

I'm trying to make a simple textured rectangular in OpenGL using SOIL and GLUT.

This is my Display function (executed in main by glutDisplayFunc(Display)):

void Display ()
{
    GLuint tex_2d;

    glMatrixMode (GL_MODELVIEW);
    glLoadIdentity ();
    glClear (GL_COLOR_BUFFER_BIT);
    glClearColor (1.0,1.0,1.0,1.0);
    gluLookAt (eyex,eyey,eyez,centerx,centery,centerz,0,1,0);

    glEnable(GL_TEXTURE_2D);
     tex_2d = SOIL_load_OGL_texture
    (
        "img.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
    );
     if( 0 == tex_2d )
    {
        printf( "SOIL loading error: '%s'\n", SOIL_last_result() );
        exit(1);
    }

   glBindTexture(GL_TEXTURE_2D, tex_2d);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR_MIPMAP_LINEAR); 

    glColor3f (0.0,0.0,0.0);
    glBegin(GL_POLYGON);

                       glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
                       glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
                       glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
                       glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);

     glEnd();   
    glDisable(GL_TEXTURE_2D);
    glFlush ();
    glutSwapBuffers();
}

With this is see only a black rectangular without any texture. I'm trying to do something with this for a few hours. Please help, thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风吹雪碎 2024-07-24 18:27:08

难道是在绘制矩形之前将颜色设置为黑色吗? 该行

glColor3f (0.0,0.0,0.0);

尝试白色代替...

glColor3f (1.0,1.0,1.0);

Could it be that you set the color to black just before you draw the rectangle? The line

glColor3f (0.0,0.0,0.0);

Try white instead...

glColor3f (1.0,1.0,1.0);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文