Drawing problem

I want to display only a inner rectangle region from an image.I tryed this code, but it doesn’t do the trick.

GLubyte *pData;
GLint pwidth;
GLint pheight;
GLubyte *pData;
GLint pwidth;
GLint pheight;
GLenum format;
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
pData=LoadTGA(“Baner3.tga”,&pwidth,&pheight,&format);
glClear(GL_COLOR_BUFFER_BIT);
glRasterPos2i(0,0);
glPixelStorei(GL_UNPACK_SKIP_ROWS,32);
glPixelStorei(GL_UNPACK_SKIP_PIXELS,32);
glDrawPixels(pwidth/2,pheight/2,format,GL_UNSIGNED_BYTE,pData);
glutSwapBuffers();

You can’t do this with glDrawPixels. Read the its documention:
http://www.opengl.org/sdk/docs/man/xhtml/glDrawPixels.xml

This function read in your case (pwidth/2)x(pheight/2) pixels at the system memory location stored in pData.

pwidth and pheight are the size of the rectangle drawn in the current DRAW_BUFFER.

IMO, the best way to do it is simply load your entire image in a texture then draw a portion of this one playing with texture coordinates. In addition it would be much more efficient. :slight_smile:

Yes.That works fine.Thank you for the help.