Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


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


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 shinypixel   Members   -  Reputation: 226

Like
0Likes
Like

Posted 10 May 2014 - 05:52 PM

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
        glBegin(GL_QUADS);
        
            // 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);

        glEnd();

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;

    m_cells.push_back(cell);

    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, 10 May 2014 - 09:33 PM.


Sponsor:

#2 shinypixel   Members   -  Reputation: 226

Like
0Likes
Like

Posted 10 May 2014 - 08:14 PM

My solution was with GL_ARB_texture_rectangle. Thank you.


Edited by shinypixel, 10 May 2014 - 08:59 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS