• Advertisement
Sign in to follow this  

Rendering partial texture fails (otherwise known as 'I lost my puppy')

This topic is 1410 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

He was a wonderful puppy, all two dimensions of him.


He came as a sprite map. The image was 512x128 pixels. I had no problem loading and rendering the full texture to the screen.


When I wanted to show a cell, or portion, of the sprite map, he ended up missing.


I understand the texture is (0,0) at the bottom-left, so I tried setting the right texture coordinates and vertex. I must not be understanding something right.


The cell I'm adding:

sprPuppy.addCell(3, 46, 24, 63, 0);  // cell (3,46) by (24,63) pixels with id 0.

Thus, I'm trying to render only a portion of the 512x128 image.


Then on render, I was trying to convert my full texture quad into a sprite quad.

        // draw Sprite
            // bottom left
            glTexCoord2f(0.0f, 0.0f);
            glVertex2f(m_x, m_y);
            // bottom right
            glTexCoord2f(m_currentCell.width / m_width, 0.0f);
            glVertex2f(m_x + m_currentCell.width * m_scale, m_y);

            // top right
            glTexCoord2f(m_currentCell.width / m_width, m_currentCell.height / m_height);
            glVertex2f(m_x + m_currentCell.width * m_scale, m_y + m_currentCell.height * m_scale);

            // top left  
            glTexCoord2f(0.0f, m_currentCell.height / m_height);
            glVertex2f(m_x, m_y + m_currentCell.height * m_scale);


Cell add method:

bool Sprite::addCell(const int x, const int y, const int width,
    const int height, const int id)
    CELL cell;

    cell.x = x;
    cell.y = y;
    cell.width = width;
    cell.height = height;

    cell.id = id;


    return true;

I'm not getting anything on the screen. I'm assuming my math is wrong. Any idea?  I also understand there are FBO's for this work, but I haven't studied on them yet. I plan to in the future, but I'd like to attempt the method above for now.

Edited by shinypixel

Share this post

Link to post
Share on other sites

My solution was with GL_ARB_texture_rectangle. Thank you.

Edited by shinypixel

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement