MasterOfDisaster
|
 |
«
Posted
2006-01-02 20:42:45 » |
|
hi, i'm trying to get rendering hints to work (and it seems they are not difficult to use  ) but for some unknown reason they are ignored in my game. i want to rotate an image on the fly and turn the following hint on in order to have smoother results: g.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); i compared a working example ( http://www.rgagnon.com/javadetails/java-0248.html - the second one - i only added the line above) with my code and i cannot see a difference which seems to be relevant. but i'm most probably wrong. some questions: 1: are there any components i should not use in connection with rendering hints (jframe, canvas, ...)? 2: could BufferStrategy influence this particular part of the rendering process? 3: is Toolkit doing some magic? i use ImageIO ... here a screenshot to show what i mean:  any help is greatly appreciated!
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #1 - Posted
2006-01-02 20:46:31 » |
|
grml ... 1 minute after posting the topic above i did one final test and exchanged the image loading code in the tutorial code with my own (old: Toolkit, new: ImageIO) and now i have the same bad results. how come? i thought ImageIO is the preferred way to load images.  maybe i'm doing something wrong with ImageIO, i will browse the forums ...
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #2 - Posted
2006-01-02 21:04:50 » |
|
hmm ... and it's got something to do with this piece of code: Image image = CONFIG.createCompatibleImage(sourceImage.getWidth(null),sourceImage.getHeight(null),trans); if i comment that out, everything works fine, but do i still have accelerated graphics then? seems like my understanding of how things work was completely wrong... 
|
|
|
|
Games published by our own members! Check 'em out!
|
|
Ask_Hjorth_Larsen
Junior Member  
Java games rock!
|
 |
«
Reply #3 - Posted
2006-01-03 00:39:35 » |
|
I have used VALUE_INTERPOLATION_BILINEAR to perform what I think you want to do. The code you linked to does not contain any stuff with RenderingHints, want to explain?
|
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #4 - Posted
2006-01-03 08:25:01 » |
|
i know but i have written that i just added the renderinghint line above to the tutorial code and it worked. sorry for not pointing that out clearer ...
|
|
|
|
Ask_Hjorth_Larsen
Junior Member  
Java games rock!
|
 |
«
Reply #5 - Posted
2006-01-03 18:27:59 » |
|
Oh, my bad then. Try posting your code, that might reveal the reason. The createCompatibleImage stuff shouldn't itself produce a problem AFAI can see.
|
|
|
|
|
appel
|
 |
«
Reply #6 - Posted
2006-01-03 18:38:06 » |
|
Could be a difference in the versions of JRE?
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #7 - Posted
2006-01-03 19:22:46 » |
|
Could be a difference in the versions of JRE?
i compiled and executed the tutorial code in exactly the same way as my game code. in the meantime i found out that it's not the Toolkit/ImageIO thing i mentioned above. @hjorth: here's the code: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
| sprite loading code: ====================
protected static final GraphicsDevice DEVICE; protected static final GraphicsConfiguration CONFIG; static { DEVICE = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); CONFIG = DEVICE.getDefaultConfiguration(); }
public Sprite getSprite(String ref, int trans) { BufferedImage sourceImage = null; try { URL url = this.getClass().getClassLoader().getResource(ref); if (url == null) { fail("Can't find ref: "+ref); } sourceImage = ImageIO.read( new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(ref)) ); } catch (Exception e) { fail("Failed to load: "+ref); e.printStackTrace(); }
Sprite sprite = new Sprite(sourceImage, ref); sprites.put(ref,sprite); return sprite; } drawing code: ===========
public void drawRotated(Graphics2D g2d, int x, int y, double angle) { g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY); AffineTransform origXform = g2d.getTransform(); AffineTransform newXform = (AffineTransform)(origXform.clone());
int xRot = (int) (x + getWidth() / 2); int yRot = (int) (y + getHeight() / 2);
newXform.translate(-halfWidth, -halfHeight); newXform.rotate(-angle, xRot, yRot);
g2d.setTransform(newXform); g2d.drawImage(image, x, y, null); g2d.setTransform(origXform); } |
|
|
|
|
appel
|
 |
«
Reply #8 - Posted
2006-01-03 20:20:45 » |
|
I don't know about the bufferedinputstream: 1 2 3
| sourceImage = ImageIO.read( new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(ref)) ); |
I use this, and it works for me: 1
| BufferedImage SPRITE = ImageIO.read(getClass().getResource("sprite.gif")); |
are you using double-buffering strategy?
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #9 - Posted
2006-01-04 10:24:58 » |
|
your method does not work for me. i get java.lang.IllegalArgumentException: input == null! at javax.imageio.ImageIO.read(ImageIO.java:1354)
... although i only changed this piece of code:
sourceImage = ImageIO.read(new BufferedInputStream(this.getClass().getClassLoader().getResourceAsStream(ref)));
... to that one:
sourceImage = ImageIO.read(getClass().getResource(ref));
about the bufferstrategy: yes i use it:
canvas.createBufferStrategy(2);
|
|
|
|
Games published by our own members! Check 'em out!
|
|
darkprophet
Senior Member   
Go Go Gadget Arms
|
 |
«
Reply #10 - Posted
2006-01-04 13:34:55 » |
|
getClass().getResource(...); obtains the resource using the full path, so you have to specify C:/mygames/ThisGame/stuff/sprite.png
whereas getClass().getClassLoader().getResource(...); obtains the resource relative to the top most package, so if you have com/mygames/thisGame and next to com, you have data/sprite.png, all you have to do is:
getClass().getClassLoader().getResource("data/spring.png");
DP
|
|
|
|
appel
|
 |
«
Reply #11 - Posted
2006-01-04 14:23:45 » |
|
Wondering what Sprite does with the BufferedImage (after you've loaded the image): 1
| Sprite sprite = new Sprite(sourceImage, ref); |
And where do you define "image" in this? (when drawing the image) 1
| g2d.drawImage(image, x, y, null); |
|
|
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #13 - Posted
2006-01-04 15:59:59 » |
|
Wondering what Sprite does with the BufferedImage (after you've loaded the image): 1
| Sprite sprite = new Sprite(sourceImage, ref); |
And where do you define "image" in this? (when drawing the image) 1
| g2d.drawImage(image, x, y, null); |
a Sprite is just a wrapper for an Image object. i don't modify the Image object between loading and drawing. do you see any mistakes in my code?
|
|
|
|
woogley
|
 |
«
Reply #14 - Posted
2006-01-04 16:42:12 » |
|
by the way, rotations are not hardware accelerated (even if you do use createCompatibleImage()). your best bet is to enable the OpenGL pipline or use LWJGL or the like.
remove the code that is enabling the image to be HW accelerated and you should be fine
|
|
|
|
|
appel
|
 |
«
Reply #15 - Posted
2006-01-04 17:15:14 » |
|
Try filling the window with a white rectangle, and then draw the image on that background.
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #16 - Posted
2006-01-04 23:44:40 » |
|
by the way, rotations are not hardware accelerated (even if you do use createCompatibleImage()). your best bet is to enable the OpenGL pipline or use LWJGL or the like.
remove the code that is enabling the image to be HW accelerated and you should be fine
yes, i noticed that. when i remove the code, it works just fine but performance severely goes down. i tried that in my chopper game and the framerate went down to 7 fps or so. 
|
|
|
|
MasterOfDisaster
|
 |
«
Reply #17 - Posted
2006-01-04 23:46:43 » |
|
Try filling the window with a white rectangle, and then draw the image on that background.
you mean no transparency around the turtle image? no, you can't mean that ... 
|
|
|
|
appel
|
 |
«
Reply #18 - Posted
2006-01-05 08:08:36 » |
|
I think it needs something to have been drawn in the background so it get *blend* the translucent pixels of the image with it.
|
|
|
|
|
|
|