Logo Search packages:      
Sourcecode: blender version File versions

void glaDrawPixelsTex ( float  x,
float  y,
int  img_w,
int  img_h,
void *  rect 
)

Functions like a limited glDrawPixels, but actually draws the image using textures, which can be tremendously faster on low-end cards, and also avoids problems with the raster position being clipped when offscreen. The routine respects the glPixelZoom values, pixel unpacking parameters are _not_ respected.

Attention:
This routine makes many assumptions: the rect data is expected to be in RGBA unsigned byte format, and the modelview and projection matrices are assumed to define a 1-to-1 mapping to screen space.

Definition at line 240 of file glutil.c.

References glaDrawPixelsTex(), glaGetOneFloat(), and glaGetOneInteger().

Referenced by glaDrawPixelsTex().

{
      unsigned char *uc_rect= (unsigned char*) rect;
      float xzoom= glaGetOneFloat(GL_ZOOM_X), yzoom= glaGetOneFloat(GL_ZOOM_Y);
      int ltexid= glaGetOneInteger(GL_TEXTURE_2D);
      int lrowlength= glaGetOneInteger(GL_UNPACK_ROW_LENGTH);
      int subpart_x, subpart_y, tex_w, tex_h;
      int texid= get_cached_work_texture(&tex_w, &tex_h);
      int nsubparts_x= (img_w+(tex_w-1))/tex_w;
      int nsubparts_y= (img_h+(tex_h-1))/tex_h;

      glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
      glBindTexture(GL_TEXTURE_2D, texid);

      for (subpart_y=0; subpart_y<nsubparts_y; subpart_y++) {
            for (subpart_x=0; subpart_x<nsubparts_x; subpart_x++) {
                  int subpart_w= (subpart_x==nsubparts_x-1)?(img_w-subpart_x*tex_w):tex_w;
                  int subpart_h= (subpart_y==nsubparts_y-1)?(img_h-subpart_y*tex_h):tex_h;
                  float rast_x= x+subpart_x*tex_w*xzoom;
                  float rast_y= y+subpart_y*tex_h*yzoom;

                  glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, GL_RGBA, GL_UNSIGNED_BYTE, &uc_rect[(subpart_y*tex_w)*img_w*4 + (subpart_x*tex_w)*4]);

                  glColor3ub(255, 255, 255);
                  glEnable(GL_TEXTURE_2D);
                  glBegin(GL_QUADS);
                  glTexCoord2f(0, 0);
                  glVertex2f(rast_x, rast_y);

                  glTexCoord2f((float) subpart_w/tex_w, 0);
                  glVertex2f(rast_x+subpart_w*xzoom, rast_y);

                  glTexCoord2f((float) subpart_w/tex_w, (float) subpart_h/tex_h);
                  glVertex2f(rast_x+subpart_w*xzoom, rast_y+subpart_h*yzoom);

                  glTexCoord2f(0, (float) subpart_h/tex_h);
                  glVertex2f(rast_x, rast_y+subpart_h*yzoom);
                  glEnd();
                  glDisable(GL_TEXTURE_2D);
            }
      }

      glBindTexture(GL_TEXTURE_2D, ltexid);
      glPixelStorei(GL_UNPACK_ROW_LENGTH, lrowlength);
}


Generated by  Doxygen 1.6.0   Back to index