[osg-users] Texturing w/ osg::Image

Shawn Cook sfncook at hotmail.com
Tue Oct 23 17:14:16 PDT 2007


I'm trying to use OSG's osg::Image class to load image files and apply them to OpenGL manually.  I know OSG can do this for me, but I'm wanting to do it myself - call it a learning exercise.  This is the code I have so far but I'm still getting no texture (blank, white quad).  Can anyone see anything wrong with what I'm doing?
 
*** global ****
GLuint texture[1];
osg::ref_ptr<osg::Image> nodeImage;
 
*** in initialize function ***
  osgDB::FilePathList pathList = osgDB::getDataFilePathList();
  pathList.push_back("../../../..");
  osgDB::setDataFilePathList(pathList);
  nodeImage = osgDB::readImageFile("leaf_1.tiff");
  if(!nodeImage.get())
  printf("texture nodeImage not found.\n");
  else
  printf("texture nodeImage loaded.\n");
  ...
  glGenTextures(1, &texture[0]);
  glBindTexture(GL_TEXTURE_RECTANGLE, texture[0]);
  unsigned char* data = (unsigned char*)nodeImage->data();
  glTexImage2D(
  GL_TEXTURE_RECTANGLE, 
  0, 
  nodeImage->getInternalTextureFormat(), 
  nodeImage->s(),
  nodeImage->t(), 
  0, 
  (GLenum)nodeImage->getPixelFormat(),
  (GLenum)nodeImage->getDataType(), 
  data);
  glTexParameteri( GL_TEXTURE_RECTANGLE, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
  glTexParameteri( GL_TEXTURE_RECTANGLE, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
 
 
*** in draw function ***
  glPushMatrix();

  glLoadIdentity();
  glColor4f( 1.0, 1.0, 1.0, 1.0 );
  glEnable(GL_TEXTURE_2D); // Enable Texture Mapping ( NEW )
  //glShadeModel(GL_SMOOTH);
  glDisable( GL_LIGHTING );
  glBindTexture(GL_TEXTURE_2D, texture[0]);

  glBegin( GL_QUADS );
  glTexCoord2f( 0.0, 0.0 );
  glVertex3f( 0.0, 0.0, 0.0 ); 
  glTexCoord2f( 1.0, 0.0 );
  glVertex3f( 10.0, 0.0, 0.0 ); 
  glTexCoord2f( 1.0, 1.0 );
  glVertex3f( 10.0, 10.0, 0.0 ); 
  glTexCoord2f( 0.0, 1.0 );
  glVertex3f( 0.0, 10.0, 0.0 ); 
  glEnd();

  glPopMatrix();
 
_________________________________________________________________
Boo! Scare away worms, viruses and so much more! Try Windows Live OneCare!
http://onecare.live.com/standard/en-us/purchase/trial.aspx?s_cid=wl_hotmailnews
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20071024/c2134ac1/attachment-0002.htm>


More information about the osg-users mailing list