Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (531)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  RenderingHints do not work  (Read 2502 times)
0 Members and 1 Guest are viewing this topic.
Offline MasterOfDisaster

Junior Member




O_o


« 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  Wink) 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!

Offline MasterOfDisaster

Junior Member




O_o


« 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.  Huh
maybe i'm doing something wrong with ImageIO, i will browse the forums ...

Offline MasterOfDisaster

Junior Member




O_o


« 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... Undecided

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 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?
Offline MasterOfDisaster

Junior Member




O_o


« 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 ...

Offline 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.
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« Reply #6 - Posted 2006-01-03 18:38:06 »

Could be a difference in the versions of JRE?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline MasterOfDisaster

Junior Member




O_o


« 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();
    }

// solution 1 - old/nok
//    Image image = CONFIG.createCompatibleImage(sourceImage.getWidth(),sourceImage.getHeight(),trans);
//    image.getGraphics().drawImage(sourceImage,0,0,null);
//    Sprite sprite = new Sprite(image, ref);
       
// solution 2 - new/ok
    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);
}

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« 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?

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline MasterOfDisaster

Junior Member




O_o


« 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!
Legends of Yore - The Casual Retro Roguelike
Offline 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

Friends don't let friends make MMORPGs.

Blog | Volatile-Engine
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« 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);

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline tom
« Reply #12 - Posted 2006-01-04 14:58:52 »

The BufferedInputStream is needed to work around a bug in ImageIO. Look at the sticky post ImageIO / Java Web Start bug: Workaround.

Offline MasterOfDisaster

Junior Member




O_o


« 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?

Offline 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
Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« 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.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline MasterOfDisaster

Junior Member




O_o


« 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.  Sad

Offline MasterOfDisaster

Junior Member




O_o


« 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 ...
 Huh

Offline appel

JGO Wizard


Medals: 50
Projects: 4


I always win!


« 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.

Check out the 4K competition @ www.java4k.com
Check out GAMADU (my own site) @ http://gamadu.com/
Offline MasterOfDisaster

Junior Member




O_o


« Reply #19 - Posted 2006-01-05 08:17:42 »

ah, now i got it...

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

pw (13 views)
2014-07-24 01:59:36

Riven (13 views)
2014-07-23 21:16:32

Riven (13 views)
2014-07-23 21:07:15

Riven (14 views)
2014-07-23 20:56:16

ctomni231 (43 views)
2014-07-18 06:55:21

Zero Volt (39 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (35 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!