IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Graphisme Java Discussion :

Double buffering


Sujet :

Graphisme Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éprouvé Avatar de Actarus78
    Homme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Septembre 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 87
    Par défaut Double buffering
    Bonjour à tous,

    Après avoir regardé les faq et autres infos sur le double buffering hardware ou software, je me retrouve en difficulté pour l'appliquer. Si l'un d'entre vous peux m'aiguiller sur la façon de faire

    J'ai un jgoodie qui lance une petite animation de fading sur un Quit button mais je me retrouve avec cet effet que bcp d'entre vous on du surrement déjà avoir et c 'est vrai que c est tout moche tout moche!

    Donc si quelqu'un peut jeter un coup d'oeil sur le code ci dessous et m'aiguiller pour réussir avec du double buffering Hard ou soft ca serrait cool merci!!

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
     
    import java.awt.AlphaComposite;
    import java.awt.Composite;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.Robot;
    import java.awt.Toolkit;
    import java.awt.Window;
    import java.awt.image.BufferedImage;
     
    import javax.swing.JComponent;
    import javax.swing.JFrame;
     
    public class Dissolver extends JComponent implements Runnable{
    	Frame frame;
    	Window fullscreen;
    	int count;
    	BufferedImage frame_buffer;
    	BufferedImage screen_buffer;
    	//2nd buffer
    	Graphics buffer;
    	Image image;
     
    	public Dissolver(){}
     
    	public void update(Graphics g){
    	      paint(g);
    	}
     
     
    	public void dissolveExit(JFrame frame){
    		try{
    			this.frame = frame;
    			Robot robot = new Robot();
     
    			//cap screen w/ frame to frame buffer
    			Rectangle frame_rect = frame.getBounds();
    			frame_buffer = robot.createScreenCapture(frame_rect);
     
    			//hide frame
    			frame.setVisible(false);
     
    			//cap screen w/o frame
    			Dimension screensize = Toolkit.getDefaultToolkit().getScreenSize();
    			Rectangle screen_rect = new Rectangle(0,0,screensize.width, screensize.height);
    			screen_buffer = robot.createScreenCapture(screen_rect);
     
    			//create big window w/o decorations
    			fullscreen = new Window(new JFrame());
    			fullscreen.setSize(screensize);
    			fullscreen.add(this);
    			this.setSize(screensize);
    			fullscreen.setVisible(true);
     
    			//start animation
    			new Thread(this).start();
    		}catch(Exception e){
    			System.out.println(""+e);
                      	}
    	}
     
    	public void run(){
    		try{
    			count = 0;
    			Thread.sleep(100);
    			for(int i=0; i<20; i++){
    				count = i;
    				fullscreen.repaint();
    				Thread.sleep(100);
    			}
    			System.exit(0);
    		}catch(Exception e){
    			System.out.println(""+e);			System.exit(0);
    		}
    	}
     
     
    	public void paint(Graphics g){
     
    		Graphics2D g2 = (Graphics2D)g;
    		//création du buffer si il n'existe pas
    	    if(buffer==null){
    	       image = createImage(fullscreen.getWidth(),fullscreen.getHeight());
    	       buffer = image.getGraphics();
    	    }
     
    		/** Désactivation de l'anti-aliasing */
    		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    		/** Demande de rendu rapide */
    		g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    		g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    		g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    		g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
     
    		//draw the screen, offset in case the window isn't at 0,0
    		g.drawImage(screen_buffer, -fullscreen.getX(), -fullscreen.getY(), null);
     
    		//draw the frame
    		Composite old_comp = g2.getComposite();
     
    		Composite fade = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f-((float)count)/20f);
    		g2.setComposite(fade);
    		g2.drawImage(frame_buffer, frame.getX(), frame.getY(), null);
    		g2.setComposite(old_comp);
     
       }
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import java.awt.Color;
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
     
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
     
    import com.rfo.framework.gui.tools.Dissolver;
    import com.rfo.framework.gui.tools.SpinDissolver;
     
     
    public class Test {
     
    	static JTextField text;
    	/**
             * @param args
             */
    		public static void main(String[] args) {
    		// TODO Auto-generated method stub
    			final JFrame frame = new JFrame("Test");
     
    			JButton quit = new JButton("Quit");
    			quit.addActionListener(new ActionListener(){
    				public void actionPerformed(ActionEvent evt){
    					new SpinDissolver().dissolveExit(frame);
    				}
    			});
     
    			frame.getContentPane().add(quit);
    			frame.pack();
    			frame.setLocation(300,300);
    			frame.setSize(400,400);
    			frame.setVisible(true);
    	}
     
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
     
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import java.awt.geom.AffineTransform;
     
    public class SpinDissolver extends Dissolver{
     
    	public void paint(Graphics g){
    		Graphics2D g2 = (Graphics2D)g;
     
    		/** Désactivation de l'anti-aliasing */
    		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
    		g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    		/** Demande de rendu rapide */
    		g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED);
    		g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_SPEED);
    		g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_OFF);
    		g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DISABLE);
     
     
    		//draw the screen, offset in case the window isn't at 0,0
    		g.drawImage(screen_buffer, -fullscreen.getX(), -fullscreen.getY(), null);
     
    		//save the current transform
    		AffineTransform old_trans = g2.getTransform();
     
    		//move to the upper-lefthand corner of the frame
    		g2.translate(frame.getX(), frame.getY());
     
    		//move the frame off toward the left
    		g2.translate(-((count+1) * (frame.getX()+frame.getWidth())/20),0);
     
    		//shrink the frame
    		float scale = 1f /((float)count+1);
    		g2.scale(scale,scale);
     
    		//rotate around the center
    		g2.rotate(((float)count)/3.14/1.3, frame.getWidth()/2, frame.getHeight()/2);
     
    		//finally draw the frame
    		g2.drawImage(frame_buffer, 0, 0, null);
     
    		//restore the current transform
    		g2.setTransform(old_trans);
    	}
     
    }
    [ Sujet déplacé depuis le forum java par Viena ]
    Les Règles du Forum

  2. #2
    Membre chevronné
    Profil pro
    Inscrit en
    Avril 2003
    Messages
    509
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France

    Informations forums :
    Inscription : Avril 2003
    Messages : 509
    Par défaut
    Tu devrais plutot essayé du coté du Forum Interface graphique !
    Mais moi perso je dirais d'essayer SWING plutot que AWT il me semble que SWING gere le double buffering .
    Mais je suis pas un pro SWING/AWT !!!

    EDIT: Bon a priori tu utilise SWING j'avais juste regardé le debut des import
    Autant pour moi !!!!

  3. #3
    Membre chevronné
    Avatar de Glob
    Homme Profil pro
    Architecte de système d'information
    Inscrit en
    Avril 2002
    Messages
    428
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : Suisse

    Informations professionnelles :
    Activité : Architecte de système d'information

    Informations forums :
    Inscription : Avril 2002
    Messages : 428
    Par défaut
    Hello.

    Le "double buffering" (ou plus si affinités, triple pour casser la vsync) s'utilise de la façon suivante:
    1) Window ou JFrame .createBufferStrategy(int numBuffer)
    2) Window.getBufferStartegy pour récupérer le BufferStrategy
    3) À chaque tour de piste:
    a) bufferStrategy.getDrawGraphics()
    b) dessiner sur le Graphics récupéré en a)
    c) bufferStrategy.show()

    Mais dans ton cas précis... heu perso je fais habituellement du rendu actif et non passif, donc...

    Je te laisse voir la javadoc et l'excellent tutorial suivant http://java.sun.com/docs/books/tutorial/extra/fullscreen/ qui t'apprendra également à faire du plein écran si t'en veux

  4. #4
    Membre éprouvé Avatar de Actarus78
    Homme Profil pro
    Ingénieur qualité méthodes
    Inscrit en
    Septembre 2005
    Messages
    87
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 46
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur qualité méthodes
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2005
    Messages : 87
    Par défaut
    Je la partage la solution avec vous tous. Il suffit d'utilisé une JWindow au lieu d'une Window pour eviter le scintillement.

    Merci pour votre aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [GDI+] Double buffer
    Par sebbb dans le forum MFC
    Réponses: 3
    Dernier message: 24/05/2005, 15h19
  2. [MFC] Scinttillement vs Double buffering
    Par DamessS dans le forum MFC
    Réponses: 9
    Dernier message: 07/04/2005, 09h01
  3. Réponses: 1
    Dernier message: 04/04/2005, 11h19
  4. Réponses: 7
    Dernier message: 03/08/2004, 16h33
  5. [Exception]Double buffering & NullPointerException
    Par Seiya dans le forum API standards et tierces
    Réponses: 25
    Dernier message: 09/07/2004, 18h41

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo