PDA

View Full Version : subimages with gldrawPixels performance advince needed



IDK
02-08-2007, 09:20 AM
This is my code:


void drawBox(unsigned int num, float x, float y){
// SCREEN_WIDTH, SCREEN_HEIGHT
glPixelStorei(GL_UNPACK_SKIP_PIXELS, (num&0x3)*16);
glPixelStorei(GL_UNPACK_SKIP_ROWS, (num>>2)*16);

glRasterPos2f(-1.0f+x*boxLen/SCREEN_WIDTH/2,-1.0f+y*boxLen/SCREEN_HEIGHT/2);
glDrawPixels(16,16,GL_RGB,GL_UNSIGNED_BYTE, picMap.Data);
}It draws a subimage of a whole image(which is 4x4 images, with each image being 16x16 pixels), num specifies the image, and x,y specefies the position.

This func is run a lot of times in a close loop, and I'm wondering what's the best way to optimise it.

Should I design so it isn't drawing a subimage?
Would that help?

Or should I write to a local buffer, and then blit it off on the screen?

IDK wishes you Happy programming!

sqrt[-1]
02-08-2007, 10:29 PM
If you want speed, don't use glDrawPixels. Upload you data into a texture and write it to the screen using an ortho projection.

IDK
02-09-2007, 08:17 AM
Ok, thanks a lot.