c++ - 纹理绑定(bind)的特殊参数?

标签 c++ c opengl textures

我是否必须以某种方式设置我的 gl 上下文来绑定(bind)纹理。我正在遵循教程。我首先做:

#define checkImageWidth 64
#define checkImageHeight 64
static GLubyte checkImage[checkImageHeight][checkImageWidth][4];

static GLuint texName;

void makeCheckImage(void)
{
    int i, j, c;

    for (i = 0; i < checkImageHeight; i++) {
        for (j = 0; j < checkImageWidth; j++) {
            c = ((((i&0x8)==0)^((j&0x8))==0))*255;
            checkImage[i][j][0] = (GLubyte) c;
            checkImage[i][j][1] = (GLubyte) c;
            checkImage[i][j][2] = (GLubyte) c;
            checkImage[i][j][3] = (GLubyte) 255;
        }
    }
}


void initt(void)
{    
    glClearColor (0.0, 0.0, 0.0, 0.0);


    makeCheckImage();
    glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    glGenTextures(1, &texName);
    glBindTexture(GL_TEXTURE_2D, texName);

    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, GL_RGBA, checkImageWidth, 
        checkImageHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, 
        checkImage);
    engineGL.current.tex = texName;
}

在我的渲染中我这样做:

PolygonTesselator.Begin_Contour();
            glEnable(GL_TEXTURE_2D);
                glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);
                glBindTexture(GL_TEXTURE_2D, current.tex);

        if(layer[currentlayer].Shapes[i].Contour[c].DrawingPoints.size() > 0)
        {
            glColor4f(
                layer[currentlayer].Shapes[i].Color.r,
                layer[currentlayer].Shapes[i].Color.g,
                layer[currentlayer].Shapes[i].Color.b,
                layer[currentlayer].Shapes[i].Color.a);


        }

        for(unsigned int j = 0; j < layer[currentlayer].Shapes[i].Contour[c].DrawingPoints.size(); ++j)
        {
            gluTessVertex(PolygonTesselator.tobj,&layer[currentlayer].Shapes[i].Contour[c].DrawingPoints[j][0],
                &layer[currentlayer].Shapes[i].Contour[c].DrawingPoints[j][0]);
        }

        PolygonTesselator.End_Contour();
            }
            glDisable(GL_TEXTURE_2D);
    }

但是它仍然渲染颜色而不渲染纹理。我至少希望看到黑色或其他东西,但好像绑定(bind)失败了。我错过了什么吗?

谢谢

最佳答案

从该代码看来,您没有设置任何 UV。

编辑:使用 GL_MODULATE 而不是 GL_DECAL 有什么区别吗? (我在这里进行猜测,因为我怀疑问题出在您未提供的代码中,或者在 gluTessVertex 本身中......

关于c++ - 纹理绑定(bind)的特殊参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2984706/

相关文章:

c++ - 确定参数的数量和类型以及作为函数的类型参数的返回类型

c++ - 继承和重载默认构造函数

c - 如何获取存储为字符的字符串的长度

c++ - 使用自定义 "front" vector 更新 "world up" vector 的正确方法是什么?

c - OpenGL 与 SDL,我做错了什么?

c++ - 缓存行对齐(需要在文章中说明)

c - 对于间隔上的翻转和状态查询,什么是好的数据结构

isdigit 可以合法地依赖于 C 语言环境吗

c++ - GLFW 获取屏幕高度/宽度?

C++ 交换成员数组和关联指针