OpenGL - glutSolidSphere 上的纹理不显示

发布于 2024-12-25 09:40:39 字数 1078 浏览 1 评论 0原文

我已经设法加载纹理,

// Load texture
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);



    pBytes = gltLoadTGA("../earth.tga", &iWidth, &iHeight, &iComponents, &eFormat);     
    glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
    free(pBytes);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

当我像这样对球体进行纹理处理时,

glDisable(GL_LIGHTING);

    glEnable(GL_TEXTURE_2D);
    glutSolidSphere(35.0f, 30, 17); 
    glDisable(GL_TEXTURE_2D);

    glEnable(GL_LIGHTING);

它不会显示(图像256x256 32位),但我有一艘由金字塔形状制成的船,同样的技术适用于它,

glEnable(GL_TEXTURE_2D);
    ship(); 
    glDisable(GL_TEXTURE_2D);

任何人都知道为什么会发生这种情况,请... (请不要标记我,我在这里很努力)

i have managed to load texture

// Load texture
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);



    pBytes = gltLoadTGA("../earth.tga", &iWidth, &iHeight, &iComponents, &eFormat);     
    glTexImage2D(GL_TEXTURE_2D, 0, iComponents, iWidth, iHeight, 0, eFormat, GL_UNSIGNED_BYTE, pBytes);
    free(pBytes);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);

glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

when i texture the sphere like this it does not show (image 256x256 32bit)

glDisable(GL_LIGHTING);

    glEnable(GL_TEXTURE_2D);
    glutSolidSphere(35.0f, 30, 17); 
    glDisable(GL_TEXTURE_2D);

    glEnable(GL_LIGHTING);

but i have a ship made out of a pyramid shape the same technique works on it

glEnable(GL_TEXTURE_2D);
    ship(); 
    glDisable(GL_TEXTURE_2D);

anyone any idea why this is happening please...(please don't mark me down i'm working hard here)

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

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

发布评论

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

评论(1

四叶草在未来唯美盛开 2025-01-01 09:40:39

您可能已经加载了纹理图像。但您还需要提供纹理坐标。你的船可能会这样做。然而 glutSolidSphere 却没有,您对此无能为力。所以不要使用 glutSolidSphere。

You may have loaded the texture image. But you also need to supply texture coordinates. Your ship may do this. glutSolidSphere however does not, and there's nothing you can do about it. So don't use glutSolidSphere.

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