纹理绑定的特殊参数?

时间:2010-06-06 15:16:39

标签: c++ c opengl textures

我是否必须以某种方式设置我的gl上下文来绑定纹理。我正在关注一个教程。我开始做:

#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);
    }

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

由于

1 个答案:

答案 0 :(得分:0)

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

编辑:使用GL_MODULATE而不是GL_DECAL会有什么不同吗? (我在这里猜测,因为我怀疑问题在于你没有提供的代码,或者在gluTessVertex本身......