Jump to content
  • Advertisement
Sign in to follow this  
Ranger_One

Optimized routine to fill rectangle with bitmap?

This topic is 5402 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to find the best (fastest) way to fill a screen rectangle given: X = Screen Lower Left X Y = Screen Lower Left Y W = Rectangle WIdth in pixels H = Rectangle Height in pixels with a bitmap from a texture given: TX = Texture Lower Left X TY = Texture Lower Left Y TW = Texture width in pixels TH = Texture height in pixels Here is what I have right now:
void lugBitmap::Fill(int x, int y, int w, int h, int tx, int ty, int tw, int th)
{
     // repeat fill actions across an down...
     register int ex, ey;
     register int dx, dy;
     register int sx = x;
     
     ex = x + w;		// end x pos
     ey = y + h;		// end y pos
     dy = th;			// Y shift per iteration
     
     glMatrixMode(GL_TEXTURE);
     glScalef(Width,Height,1.0);
     glMatrixMode(GL_MODELVIEW);
     
     glBegin(GL_QUADS);     
     while (y < ey)
     {
          dx = tw;			// X shift per iteration
          if ((ey-y) < dy) dy = ey - y;	// clip a the end if needed
          
          x = sx;
          while (x < ex)
          {
               if ((ex - x) < dx) dx = ex - x;	// clip at the end if needed
               
              		glTexCoord2i(tx,ty);
              	glVertex2i(x,y);
              		glTexCoord2f(tx+dx,ty);
              	glVertex2i(x+dx,y);
              		glTexCoord2f(tx+dx,ty+dy);
              	glVertex2i(x+dx,y+dy);
              		glTexCoord2f(tx,ty+dy);
              	glVertex2i(x,y+dy);
              	x += dx;
          }
          y += dy;
     }     
     glEnd();
     
     glMatrixMode(GL_TEXTURE);
     glLoadIdentity();
}

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Quote:
Original post by Ranger_One
How do you make a single quad repeat just part of a texture?


glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);

Then just specify texture cords larger than 1.0f.

Share this post


Link to post
Share on other sites
Quote:
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);


Won't that repeat the entire texture? I need to repeat just a slice of it (a skin for a GUI)...

Share this post


Link to post
Share on other sites
Ahh ic. I didn't understand before.
Erm if you're cutting out parts of textures for skins etc I recommend using pixel precision and/or not building mipmaps. Otherwise I foresee many problems with scaling causing bleeding from nearby components in the skins.
Personally I perfer to seperate textures where I can & use them individually so this kind of thing doesn't happen (makes coding like that alot easier too)

Erm yeah that code probally looks fine. I'm kinda tired for complex thought right now so can't really analysis it now

Share this post


Link to post
Share on other sites
Poke around your texture coordinates:

to render a quad repeating a part of the texture like in your original post:

x, y - repeated rectangle's position
w,h - repetead rectangle's size
tw, th - texture size
qw, qh - quad size, assuming you want a pixel in the texture to be a pixel onscreen

glTexCoord2i(x, y) x and y should be in the texture's rectangle
glTexCoord2i((x + w) % (tw - x) + x, y)

and the same for Y

draw it out on paper to see if it works and why

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!