Show Posts
|
|
Pages: [1]
|
|
1
|
Java Game APIs & Engines / Java 2D / setSourceProgressivePasses
|
on: 2005-01-25 15:09:44
|
Hi! I'm using the following code to create thumbnails from images. The two ImageReadParam specified are parameters to improve the reading performance of the source images. I'd like to know how can I tweak these parameters quite a bit to get more performance, because I'm not an expert in 2D subjects. 1 2 3 4 5
| ... param.setSourceProgressivePasses(0, 4); param.setSourceSubsampling(128, 128, 0, 0); BufferedImage image = reader.read(0, param); ... |
Thanks in advance
|
|
|
|
|
2
|
Java Game APIs & Engines / Java 2D / Re: Slow fade effect
|
on: 2005-01-02 19:23:22
|
Bummer!! What OS are you on. Does the game say it sent me an error message? I'd like to find out what's wrong with that so I'll check the logs just in case.
Sorry, it was my fault  . It works nicely, a bit slow in my computer, though. I copied your render() code and I get that annoying ghosting effect still. I don't know what I'm doing wrong. :-/ How do you call the render() op ?
|
|
|
|
|
4
|
Java Game APIs & Engines / Java 2D / Re: Slow fade effect
|
on: 2005-01-01 17:42:43
|
haha whoops  Yes it's not re-created EVERY frame, but it's existance can still be done without. Sorry for the misreadings... new years, you know  Yeah, the advice still holds though. You don't need that buffer at all. I've already tried to draw directly unto the panel's graphic context resulting in an annoying ghosting effect between the two images which doesn't appear if I use that intermediate buffer to draw the composite. BTW, I know it's the buffer slowing the effect to a crawl, thanks for reminding me of this. I have other effects (scrolling and sliding) where I draw directly unto the panel's graphic context (no intermediate buffer) and they are pretty fast. I'd like to know how to make the same effect without using this buffer.
|
|
|
|
|
5
|
Java Game APIs & Engines / Java 2D / Re: Slow fade effect
|
on: 2005-01-01 12:05:09
|
|
Before you ask me, I've already tried to use the BufferStrategy class instead of my intermediate buffer with fairly similar results. I cannot use FSEM, therefore I'm unable to use the page flipping, and I have to resort to blit the contents from the buffer unto the panel's graphic context. Is there any way to speed up blit operations in java ?
|
|
|
|
|
6
|
Java Game APIs & Engines / Java 2D / Slow fade effect
|
on: 2004-12-31 19:03:32
|
Hi! I'm using the following code to do a fade transition effect between two images: 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
| public void render(Graphics g, Image imageFrom, Image imageTo, int width, int height) { BufferedImage buffer=gc.createCompatibleImage(width,height); Graphics2D g2 = (Graphics2D)buffer.getGraphics(); int counter=0; while (counter<90) { counter=counter+2; double alphaScalar = Math.sin(Math.toRadians(counter)); g2.setComposite(AlphaComposite.SrcOver); g2.drawImage(imageFrom, 0, 0, null); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)alphaScalar)); g2.drawImage(imageTo, 0, 0, null); g.drawImage(buffer, 0, 0, null); try { Thread.sleep(5); } catch(InterruptedException ex){} } g.dispose(); g2.dispose(); buffer.flush(); } |
My main problem is that using a buffer to save the image composite before drawing it over the panel's Graphic context slows the effect considerably. I have other effects (scrolling, sliding and some more) which don't require the use of an intermediate buffer and they are way faster without it. I'm looking for a way to improve the perfomance of my fade effect. I've tried to draw the image composite over the panel's Graphic context directly (no buffer) but the screen flickers. Can anyone help me, please ? Regards
|
|
|
|
|
7
|
Java Game APIs & Engines / Java 2D / Fade in/out effect too slow
|
on: 2004-10-19 11:13:00
|
Hi! I'm trying to do a fade in/out effect between two images using the following 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
| public void render(Graphics g, Image imageFrom, Image imageTo, int width, int height) {
Image buffer=gc.createCompatibleVolatileImage(width,height);
Graphics2D g2 = (Graphics2D)buffer.getGraphics(); int counter=0; while (counter<90) { counter=counter+2; double alphaScalar = Math.sin(Math.toRadians(counter)); g2.setComposite(AlphaComposite.SrcOver); g2.drawImage(imageFrom, 0, 0, null); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, (float)alphaScalar)); g2.drawImage(imageTo, 0, 0, null); g.drawImage(buffer, 0, 0, null); try { Thread.sleep(1); } catch(InterruptedException ex){} } g.dispose(); g2.dispose(); buffer.flush(); } |
The problem is that it's too slow and jerky. I need a smoother transition. Before you ask me, I've put a "Thread.sleep(1)" line to allow another thread playing a background music to breath. Thanks in advance
|
|
|
|
|
9
|
Java Game APIs & Engines / Java 2D / copy the contents of an image
|
on: 2004-10-17 15:43:20
|
|
Hi!
I need to copy the contents of an image (bufferedimage or volatileimage) unto another for backup purposes. Is it enough to do a simple variable assignation like this ?
Image im1; Image im2; ... im1=im2;
thanks in advance
|
|
|
|
|
12
|
Java Game APIs & Engines / Java 2D / Scroll transition between two images
|
on: 2004-10-11 18:31:26
|
Hi! I'm using the following code to render a left to right scroll transition between two images over a JPanel: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| public void render(JPanel panel, Image imageFrom, Image imageTo) {
Image buffer = gc.createCompatibleVolatileImage(panel.getWidth(), panel.getHeight());
Graphics g = buffer.getGraphics(); Graphics g2 = panel.getGraphics(); for (int x=0; x<=panel.getWidth(); x+=10) { g.drawImage(imageFrom, x, 0, panel); g.drawImage(imageTo, x-panel.getWidth(), 0, panel); g2.drawImage(buffer, 0, 0, panel); try { Thread.sleep(20); } catch(InterruptedException ex){} }
g.dispose(); g2.dispose(); buffer.flush(); } |
As you can see I render out of the bounds of the screen many times during the transition. I suppose I can improve the performance not drawing the offscreen parts. How can I do it ? Is easy ? Can anyone help me, please ? Thanks in advance
|
|
|
|
|
13
|
Java Game APIs & Engines / Java 2D / Re: Drawing images over a JPanel
|
on: 2004-10-09 07:24:54
|
|
Yes, I'm doing animation. I'm developing a slideshow app using a panel to show the photos and do transitions (fade, scrolling, etc...) between them. I don't know if the paintComponent method you are suggesting is valid in this case.
|
|
|
|
|
14
|
Java Game APIs & Engines / Java 2D / Re: Drawing images over a JPaneso
|
on: 2004-10-08 17:08:23
|
|
Another question, I'm a beginner in Java2D and active rendering so I don't know much them. I use the loop I shown you before to render an image on screen during some seconds. Why did I call drawImage inside a loop and didn't I call drawImage once and then call to sleep ? Because when I switch apps with alt+tab and return I loose the image on screen. Is there a better way to do this, I mean, only render the image when I loose the contents on screen ? This loop is eating all my CPU.
|
|
|
|
|
15
|
Java Game APIs & Engines / Java 2D / Drawing images over a JPanel
|
on: 2004-10-07 07:03:54
|
I'm using active rendering over a JPanel implementing Runnable and I have some doubts I want share with you. Which of the following codes is better (performace, etc...): 1st one: ----------- 1 2 3 4 5 6 7
| BufferedImage im=loadImage(file); Graphics2D g = (Graphics2D) getGraphics();
while (threadSuspended) { g.drawImage(im, 0, 0, this); } g.dispose(); |
2nd one: ------------ 1 2 3 4 5 6 7
| BufferedImage im=loadImage(file);
while (threadSuspended) { Graphics2D g = (Graphics2D) getGraphics(); g.drawImage(im, 0, 0, this); g.dispose(); } |
Do I have to flush the BufferedImage too ? when ? Thanks in advance
|
|
|
|
|
16
|
Java Game APIs & Engines / Java 2D / Threading issues
|
on: 2004-09-28 19:32:48
|
|
I don't know if this is the right forum to ask this. Please move it if you find it doesn't fit here.
I'm developing a slideshow app. I'm using Java2D and the javalayer lib to play MP3 files as background music for the slideshows. I'm drawing the images using active rendering on a JPanel implementing Runnable and the music plays in its own thread too. I had to lower the priority of the drawing thread because the music one wouldn't start until the end of the slideshow, and I want the music to play during the slideshow. I have a problem though, every time there is a transition between the slides, the music stops for a second or something and then it continues. I'm a bit lost about this issue, so any guiding in the right direction would be appreciated.
Thanks
|
|
|
|
|
18
|
Java Game APIs & Engines / Java 2D / Re: Active rendering
|
on: 2004-06-10 21:15:50
|
Thanks for the article, it helped me understand this whole thing better. Is there a particular reason you were using a VolatileImage instead of a BufferStrategy for your backbuffer? Can BufferStrategy be used outside FSEM ?
|
|
|
|
|
19
|
Java Game APIs & Engines / Java 2D / Active rendering
|
on: 2004-06-10 10:22:59
|
|
I'm using active rendering in my pseudo fullscreen mode app (no FSEM) using a VolatileImage as a buffer, but I don't know how to recover the screen after switching apps or when I click the mouse to open a popup I registered in the frame of my app. Any help, please ?
|
|
|
|
|
20
|
Java Game APIs & Engines / Java 2D / Image transition effects
|
on: 2004-05-22 16:38:38
|
|
Hi!
I'd like to know if there is a ready made library with source code for image transitions, like fades, dissolves, scrollings, and so on. If there is none, where can I find information about this, please ?
regards
|
|
|
|
|
21
|
Java Game APIs & Engines / Java 2D / Re: How to fade between two images ?
|
on: 2004-05-02 22:18:45
|
I found a full piece of code at Sun site that does exactly what I was trying to do LOL 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 66 67 68 69 70 71
| import java.awt.*; import java.awt.image.*; import javax.swing.*; import java.util.Timer; import java.util.TimerTask; public class Converge extends JFrame { ImageIcon saloonIcon = new ImageIcon("saloon.gif"); ImageIcon coachIcon = new ImageIcon("oldstage.gif"); Image saloon = saloonIcon.getImage(); Image coach = coachIcon.getImage(); BufferedImage dest; float sourcePercentage = 1, destinationPercentage = 0; private static int STEPS = 100; private static float STEP_CHANGE = 1.0f/STEPS; private static int SLEEP_DELAY = 100; Insets insets; public Converge() { super("Image Blending"); setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE); dest = new BufferedImage(200, 200, BufferedImage.TYPE_INT_ARGB); setSize(200, 200); TimerTask task = new TimerTask() { public void run() { repaint(); sourcePercentage -= STEP_CHANGE; destinationPercentage += STEP_CHANGE; if (sourcePercentage < 0) { sourcePercentage = 0; destinationPercentage = 1; cancel(); } } }; Timer timer = new Timer(); timer.schedule(task, 0, SLEEP_DELAY); } public void paint(Graphics g) { if (insets == null) { insets = getInsets(); } g.translate(insets.left, insets.top); Graphics2D g2d = (Graphics2D)g; Graphics2D destG = dest.createGraphics();
destG.setComposite(AlphaComposite.getInstance( AlphaComposite.SRC, sourcePercentage)); destG.drawImage(coach, 0, 0, this); destG.setComposite(AlphaComposite.getInstance( AlphaComposite.XOR, destinationPercentage)); destG.drawImage(saloon, 0, 0, this); g2d.drawImage(dest, 0, 0, this); } public static void main(String args[]) { new Converge().show(); } } |
|
|
|
|
|
22
|
Java Game APIs & Engines / Java 2D / Loading a rescaled version of a JPEG image
|
on: 2004-05-02 19:17:48
|
I'm using the following code to load an scaled version of a big JPEG image. I'd like to know if there are better (faster) ways to do it. I'm developing a thumbnail explorer-type app and I'd like to create the thumbnails the fastest way possible. Here is the code. As you can see, I'm not loading the full image and then rescaling it. I rescale it while loading. Also, I'd like to know if the result BufferedImage is hardware accelerated: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| private static BufferedImage readSubsampling(File file, int maxSize) throws IOException { Iterator readers = ImageIO.getImageReadersByFormatName("jpeg"); ImageReader reader = (ImageReader)readers.next(); ImageInputStream iis=null; iis = ImageIO.createImageInputStream(file); reader.setInput(iis, true, true); ImageReadParam param = reader.getDefaultReadParam(); int size = Math.max(reader.getWidth(0), reader.getHeight(0)); int subsampling = size/maxSize + (size%maxSize != 0 ? 1 : 0); param.setSourceProgressivePasses(0, 4); param.setSourceSubsampling(subsampling, subsampling, 0, 0); BufferedImage image = reader.read(0, param); reader.dispose(); return image; } |
Thanks in advance
|
|
|
|
|
26
|
Java Game APIs & Engines / Java 2D / About fullscreen mode
|
on: 2004-05-01 21:51:01
|
|
Hi!
I'm developing a slideshow java application but I'm new to the whole Java 2D world. I've read some things about the fullscreen mode only available for windows and I'd like my app to run in linux too, is that true ? which is the alternative option, then ? Can you point me in the right direction, please ?
thanks
|
|
|
|
|
|
Add your game by posting it in the WIP section,
or publish it in Showcase.
The first screenshot will be displayed as a thumbnail.
|
|