glTexImage2d 不执行任何操作

发布于 2024-11-26 08:09:36 字数 403 浏览 2 评论 0原文

这个问题让我很困惑。我正在测试一些 Haskell 与 OpenGL 的绑定,我创建了一个顶点着色器、一个片段着色器、编译程序,并在变换顶点后在屏幕上绘制一个纹理矩形...除了屏幕是空白的。

当我将矩形渲染为纯白色而不是在片段着色器中使用采样器时,它工作得很好。当我进入 gdebugger 并使用选项将所有纹理替换为存根纹理时,它也可以正常工作。

当我查看 gdebugger 中分配的纹理时,没有纹理对象,只有默认的 2d 纹理。当我在 glTexImage2d 上设置断点时,我看到它正在被调用,但是当我用 gdebugger 查看它时,内存中没有出现纹理对象。

这是怎么回事?我是否忘记设置一些环境变量?我很沮丧。更糟糕的是,我以前也遇到过这个问题,然后我设法解决了它,但我忘记了问题是什么。我讨厌自己>>_>>

This problem baffles me. I am testing some Haskell bindings to OpenGL, I create a vertex shader, a fragment shader, compile the program, and draw a textured rectangle to the screen after transforming the vertices... except the screen is blank.

When I render the rectangle flat white instead of using a sampler in the fragment shader, it works fine. When I go into gdebugger and use the option to replace all textures with a stub texture, it also works fine.

When I look at the allocated textures in gdebugger, there are no texture objects, only the default 2d texture. When I set a breakpoint on glTexImage2d, I see that it is being called, but no texture object appears in memory when I peek at it with gdebugger.

What's going on? Am I forgetting to set some environment variables? I'm quite frustrated. The kicker is that I had this problem before, and I managed to fix it then, but I forgot what the problem was. I hate myself >_>

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

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

发布评论

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

评论(2

你在我安 2024-12-03 08:09:36

我不久前将关于 OpenGL 的教程移植到 Haskell 上。它包含一个非常小的库的链接,除其他外,该库有助于 加载纹理

也许您可以将该代码与您必须的代码进行比较以发现差异。

I ported a tutorial on OpenGL to Haskell some time ago. It includes a link to a very tiny library that, among other things, helps with loading textures.

Perhaps you could compare that code with what you have to spot the differences.

你不是我要的菜∠ 2024-12-03 08:09:36

无论如何,我不是一个 Haskell 人,但尝试做最简单的可能可行的事情,并检查你偏离它的地方:

#include <GL/glut.h>

double aspect_ratio = 0;

GLuint texID = 0;
unsigned int texBuf[] = {
    0x00FFFFFF,
    0x00FF0000,
    0x0000FF00,
    0x000000FF,    
};

void display(void)
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-10*aspect_ratio, 10*aspect_ratio, -10, 10, -10, 10);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glColor3ub(255,255,255);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texID);

    glScalef(8,8,8);
    glTranslatef(-0.5f, -0.5f, 0.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex2f(0,0);
    glTexCoord2f(1,0);
    glVertex2f(1,0);
    glTexCoord2f(1,1);
    glVertex2f(1,1);
    glTexCoord2f(0,1);
    glVertex2f(0,1);
    glEnd();

    glFlush();
    glFinish();
    glutSwapBuffers();
}

void reshape(int w, int h)
{
    aspect_ratio = (double)w / (double)h;
    glViewport(0, 0, w, h);
}

void idle()
{
    glutPostRedisplay();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize(200,200);
    glutCreateWindow("Aspect Ratio");

    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    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_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexImage2D(GL_TEXTURE_2D, 0, 4, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (char*)texBuf);

    glutDisplayFunc(display);
    glutReshapeFunc(reshape);
    glutIdleFunc(idle);
    glutMainLoop();
    return 0;
}

I'm not a Haskell guy by any means, but try doing the simplest thing that could possibly work and check to see where you deviate from it:

#include <GL/glut.h>

double aspect_ratio = 0;

GLuint texID = 0;
unsigned int texBuf[] = {
    0x00FFFFFF,
    0x00FF0000,
    0x0000FF00,
    0x000000FF,    
};

void display(void)
{
    glEnable(GL_DEPTH_TEST);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(-10*aspect_ratio, 10*aspect_ratio, -10, 10, -10, 10);

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glColor3ub(255,255,255);

    glEnable(GL_TEXTURE_2D);
    glBindTexture(GL_TEXTURE_2D, texID);

    glScalef(8,8,8);
    glTranslatef(-0.5f, -0.5f, 0.0f);
    glBegin(GL_QUADS);
    glTexCoord2f(0,0);
    glVertex2f(0,0);
    glTexCoord2f(1,0);
    glVertex2f(1,0);
    glTexCoord2f(1,1);
    glVertex2f(1,1);
    glTexCoord2f(0,1);
    glVertex2f(0,1);
    glEnd();

    glFlush();
    glFinish();
    glutSwapBuffers();
}

void reshape(int w, int h)
{
    aspect_ratio = (double)w / (double)h;
    glViewport(0, 0, w, h);
}

void idle()
{
    glutPostRedisplay();
}

int main(int argc, char **argv)
{
    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGBA | GLUT_DEPTH | GLUT_DOUBLE);

    glutInitWindowSize(200,200);
    glutCreateWindow("Aspect Ratio");

    glGenTextures(1, &texID);
    glBindTexture(GL_TEXTURE_2D, texID);
    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_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 
    glTexImage2D(GL_TEXTURE_2D, 0, 4, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, (char*)texBuf);

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