Slick Forums

Discuss the Slick 2D Library
It is currently Thu May 23, 2013 12:35 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: Thu Jun 14, 2007 10:36 am 
Offline
User avatar

Joined: Fri May 04, 2007 5:58 pm
Posts: 72
We have a Graphics.drawImage method with and without tint color, but the versions who allow for drawing a portion of an image and drawing a portion of an image scaled don't have versions with the color parameter. :(

Code:
public void drawImage(Image image, float x, float y, float srcx, float srcy, float srcx2, float srcy2, Color color)

public void drawImage(Image image, float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2, Color color)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 14, 2007 11:05 am 
Offline
User avatar

Joined: Fri May 04, 2007 5:58 pm
Posts: 72
Functionality was already included in Image, just adapted Graphics to use it. I can't try it here, though, will do tonight.

Code:
   /**
    * Draw a section of an image at a particular location and scale on the screen
    *
    * @param image The image to draw a section of
    * @param x The x position to draw the image
    * @param y The y position to draw the image
    * @param x2 The x position of the bottom right corner of the drawn image
    * @param y2 The y position of the bottom right corner of the drawn image
    * @param srcx The x position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcy The y position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    */
   public void drawImage(Image image, float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2) {
      drawImage(image, x, y, x2, y2, srcx, srcy, srcx2, srcy2, Color.white);
   }

   /**
    * Draw a section of an image at a particular location and scale on the screen
    *
    * @param image The image to draw a section of
    * @param x The x position to draw the image
    * @param y The y position to draw the image
    * @param srcx The x position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcy The y position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    */
   public void drawImage(Image image, float x, float y, float srcx, float srcy, float srcx2, float srcy2) {
      drawImage(image, x, y, x+image.getWidth(), y+image.getHeight(), srcx, srcy, srcx2, srcy2, Color.white);
   }
   
   /**
    * Draw a section of an image at a particular location and scale on the screen
    *
    * @param image The image to draw a section of
    * @param x The x position to draw the image
    * @param y The y position to draw the image
    * @param x2 The x position of the bottom right corner of the drawn image
    * @param y2 The y position of the bottom right corner of the drawn image
    * @param srcx The x position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcy The y position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param col The color to apply to the image as a filter
    */
   public void drawImage(Image image, float x, float y, float x2, float y2, float srcx, float srcy, float srcx2, float srcy2, Color col) {
      predraw();
      image.draw(x,y,x2,y2,srcx,srcy,srcx2,srcy2,col);
      currentColor.bind();
      postdraw();
   }

   /**
    * Draw a section of an image at a particular location and scale on the screen
    *
    * @param image The image to draw a section of
    * @param x The x position to draw the image
    * @param y The y position to draw the image
    * @param srcx The x position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcy The y position of the rectangle to draw from this image (i.e. relative to the image)
    * @param srcx2 The x position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param srcy2 The t position of the bottom right cornder of rectangle to draw from this image (i.e. relative to the image)
    * @param col The color to apply to the image as a filter
    */
   public void drawImage(Image image, float x, float y, float srcx, float srcy, float srcx2, float srcy2, Color col) {
      drawImage(image, x, y, x+image.getWidth(), y+image.getHeight(), srcx, srcy, srcx2, srcy2, col);
   }


Top
 Profile  
 
 Post subject: BUG?
PostPosted: Sat Jun 16, 2007 4:06 pm 
Offline
User avatar

Joined: Fri May 04, 2007 5:58 pm
Posts: 72
I'm playing with this methods, to assemble some tiles, and I think there is something fishy within...

When I use this

Code:
g.drawImage(img, x0, y0, x1, y1, 0, 0, img.getWidth() - 1, img.getHeight() - 1, color);


I get two artifacts:

- The result is one pixel less wide and tall than I expected, goes from x0 to x1-1 and from y0 to y1-1. Is this supposed to be like that?

- If the horizontal scale is big (in my test I'm stretching a texture more or less six times horizontally) a shadow appears to the left of the result. Vertically it hasn't happened to me... at least not yet.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 13, 2007 4:38 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Both of those artifacts are texture scaling issues I think. The shadow definitely. Not sure on the other one - no idea how the subimage copying works - though it may be rounding errors on texture coordinates I guess.

I'll take a look after I finish the current phase of my game.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 16, 2007 9:12 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
These are now in.

Kev


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group