Problem texturing with opengl

Posted by Killrazor on Game Development See other posts from Game Development or by Killrazor
Published on 2011-01-14T21:53:36Z Indexed on 2011/01/14 21:59 UTC
Read the original article Hit count: 192

Filed under:
|
|

Hello!

I'm having problems making a simple sprite rendering. I load 2 different textures. Then, I bind these textures and draw 2 squares, one with each texture. But only the texture of the first rendered object is drawn in both squares. Its like if I'd only use a texture or as if glBindTexture don't work properly. I know that GL is a state machine, but I think that you only need to change active texture with glBindTexture.

I load texture with this method:

 bool CTexture::generate( utils::CImageBuff* img )
 { 
  assert(img);
  m_image = img;
  CHECKGL(glGenTextures(1,&m_textureID));

  CHECKGL(glBindTexture(GL_TEXTURE_2D,m_textureID));
  CHECKGL(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR));
  CHECKGL(glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR));
  //CHECKGL(glTexImage2D(GL_TEXTURE_2D,0,img->getBpp(),img->getWitdh(),img->getHeight(),0,img->getFormat(),GL_UNSIGNED_BYTE,img->getImgData()));
  CHECKGL(glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img->getWitdh(), img->getHeight(),
   0, GL_RGBA, GL_UNSIGNED_BYTE, img->getImgData()));

  return true;
 }

And I bind textures with this function:

void CTexture::bind()
 {
  CHECKGL(glBindTexture(GL_TEXTURE_2D,m_textureID));
 }

Also, I draw sprites with this method

void CSprite2D::render()
 {
  CHECKGL(glLoadIdentity());
  CHECKGL(glEnable(GL_TEXTURE_2D));
  CHECKGL(glEnable(GL_BLEND));

  CHECKGL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
  m_texture->bind();

  CHECKGL(glPushMatrix());

  CHECKGL(glBegin(GL_QUADS));
  CHECKGL(glTexCoord2f(m_textureAreaStart.s,m_textureAreaStart.t)); // 0,0 by default
  CHECKGL(glVertex3i(m_position.x,m_position.y,0));

  CHECKGL(glTexCoord2f(m_textureAreaEnd.s,m_textureAreaStart.t)); // 1,0 by default
  CHECKGL(glVertex3i( m_position.x + m_dimensions.x, m_position.y, 0)); 

  CHECKGL(glTexCoord2f(m_textureAreaEnd.s, m_textureAreaEnd.t)); // 1,1 by default
  CHECKGL(glVertex3i( m_position.x + m_dimensions.x, m_position.y + m_dimensions.y, 0));  

  CHECKGL(glTexCoord2f(m_textureAreaStart.s, m_textureAreaEnd.t));  // 0,1 by default
  CHECKGL(glVertex3i( m_position.x, m_position.y + m_dimensions.y,0));

  CHECKGL(glPopMatrix());

  CHECKGL(glDisable(GL_BLEND));
 }

Could you help me? All help is welcome.

Thanks!!

© Game Development or respective owner

Related posts about c++

Related posts about opengl