コード例 #1
0
ファイル: texture.cpp プロジェクト: tsungchh/GLTEST
bool Texture::Load()
{

    if(!img.load(m_fileName.c_str())) {
        printf("Texture path %s ERROR!\n", m_fileName.c_str());
        return false;
    }
    QImage glimg = QGLWidget::convertToGLFormat(img);
    DEBUG_GL();
    glGenTextures(1, &m_textureObj);
    DEBUG_GL();
    glBindTexture(m_textureTarget, m_textureObj);
    DEBUG_GL();
    glTexImage2D(m_textureTarget, 0, GL_RGBA, glimg.size().width(), glimg.size().height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, glimg.bits());
    DEBUG_GL();
    // `設定顯示貼圖被縮小時使用線性內插 `
    glTexParameterf(m_textureTarget, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
    // `設定顯示貼圖被放大時使用線性外插 `
    glTexParameterf(m_textureTarget, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
    // GL_TEXTURE_WRAP_S `設定水平方向解讀模式`
    glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_S, GL_REPEAT);
    // GL_TEXTURE_WRAP_T `設定垂直方向解讀模式`
    glTexParameteri(m_textureTarget, GL_TEXTURE_WRAP_T, GL_REPEAT);

    glBindTexture(m_textureTarget, 0);

    DEBUG_GL();
    return true;
}
コード例 #2
0
ファイル: texture.cpp プロジェクト: tsungchh/GLTEST
void Texture::Bind(GLenum TextureUnit)
{
    DEBUG_GL();
    glActiveTexture(TextureUnit);
    DEBUG_GL();
    glBindTexture(m_textureTarget, m_textureObj);
    DEBUG_GL();
}
コード例 #3
0
ファイル: least.c プロジェクト: meridion/least
/* XXX Error handling :-( */
static void init_busy_texture() {
    unsigned int tex[4] =
        {
            0xffaa8888,
            0xff554444,
            0xff554444,
            0xffaa8888
        };

    glGenTextures(1, &busy_texture);
    printf("Busy texture @ num: %d\n", busy_texture);
    glBindTexture(GL_TEXTURE_2D, busy_texture);
    DEBUG_GL(glBindTexture);

    /* Set the texture's stretching properties */
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
    DEBUG_GL(glTexParameteri);
    glTexParameteri (GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
    DEBUG_GL(glTexParameteri);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
            GL_NEAREST);
    DEBUG_GL(glTexParameteri);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
            GL_NEAREST);
    DEBUG_GL(glTexParameteri);

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2,
        0, GL_RGBA, GL_UNSIGNED_BYTE, tex);
    DEBUG_GL(glTexImage2D);
}
コード例 #4
0
ファイル: least.c プロジェクト: meridion/least
static int pixmap_to_texture(void *pixmap, int width, int height, int format, int type)
{
    unsigned int texname;
    /* int max_texsize; */

    int pow2_width, pow2_height;

    /* Compute POT texture dimensions */
    RPOW2(pow2_width, width);
    RPOW2(pow2_height, height);

    format = 42;
    type = 31337;

    glGenTextures(1, &texname);
    printf("Generated texture: %d\n", texname);
    DEBUG_GL(glGenTextures);

    /* Bind the texture object */
    glBindTexture(GL_TEXTURE_2D, texname);
    DEBUG_GL(glBindTexture);

    /* Set the texture's stretching properties */
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,
            GL_LINEAR);
    DEBUG_GL(glTexParameteri);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,
            GL_LINEAR);
    DEBUG_GL(glTexParameteri);

    /* Edit the texture object's image data using the information SDL_Surface gives us */
    /*
    glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texsize);
    printf("Max tex dimensions: %dx%d\n", max_texsize, max_texsize);
    printf("width: %d, heigth %d\n", width, height);
    */

    /* Special treatment is only needed if the GPU does not support NPOT
     * textures and the current pixmap is not of POT dimensions.
     */
    if (power_of_two && (pow2_width != width || pow2_height != height)) {
        /*printf("pow2_width: %d, pow2_heigth %d\n", pow2_width, pow2_height); */

        /* Allocate undefined POT texture */
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, pow2_width,
                 pow2_height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 NULL);
        DEBUG_GL(glTexImage2D);

        /* Now fill texture */
        glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
            GL_RGBA, GL_UNSIGNED_BYTE, pixmap);
        DEBUG_GL(glTexSubImage2D);

    } else {
        /* NPOT, simply pass pixmap */
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width,
                 height, 0, GL_RGBA, GL_UNSIGNED_BYTE,
                 pixmap);
        DEBUG_GL(glTexImage2D);
    }

    /* XXX: This function currently sets the global page size */
    imw = width;
    imh = height;

    return texname;
}