Résolution de l'écran

Résolu
Utilisateur anonyme - 12 mars 2009 à 22:46
 Utilisateur anonyme - 21 nov. 2010 à 13:51
Bonjour,

j'aimerais changer la résolution de mon écran lorsque je fais tourner une application.
J'ai donc implémenter ce code :

        GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
        DisplayMode mode = new DisplayMode(400, 400, 32, DisplayMode.REFRESH_RATE_UNKNOWN);
       
        if(device.isDisplayChangeSupported()){
            device.setDisplayMode(mode);
        }
    
Mais la résolution ne change pas.
J'ai donc mis une tempo pour laisser le temps, et la résolution ne change quand même pas.
J'ai donc pensé que seule l'application graphique du programme java lui-même avait une résolution changée.
Ainsi j'ai dessiné dans une JWindow un cercle et un carré, et j'ai mis la JWindow en mode plein écran.

J'ai bien sûr testé différentes résolutions, et le carré et le cercle garde toujours la même taille et le même emplacement, preuve que même la résolution dans mon application graphique reste inchangée.

Avez-vous une solution pour changer la résolution de l'écran et la remettre par défaut à la fin du programme, et sinon au moins changer la résolution de mon application graphique ?
Le but étant d'avoir une application graphique en mode plein écran, mais dont je contrôle la résolution, et je pense que cela passe nécessairement par un changement de résolution de tout l'écran.

Merci d'avance
++ et bonne prog

23 réponses

salma87 Messages postés 3 Date d'inscription mardi 13 janvier 2009 Statut Membre Dernière intervention 21 novembre 2010
21 nov. 2010 à 00:40
Bonjour, Je code pour mon projet de courbe Bspline et nurbs un programme en jogl, et pour une étape initale je cherche à faire un déplacement de points sur la scéne en cliquant, j'ai crée deux variables xc et yc qui changent à chaque fois que je clique sur le canva en prenant les coordonnées de mon clique, mais je suis surprise par mon point qui disparait de la scéne??


//import ihm.MainFrame;

import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.media.opengl.DebugGL;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.swing.JFrame;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.FPSAnimator;
import com.sun.opengl.util.GLUT;
/**
* A minimal JOGL demo.
*
* @author [mailto:kain@land-of-kain.de Kai Ruhl]
* @since 26 Feb 2009
*/
public class PVetex extends GLCanvas implements GLEventListener,MouseListener, MouseMotionListener
{public static double xc;
public static double yc;

/** Serial version UID. */
private static final long serialVersionUID = 1L;
public static Frame frame = new Frame("LES SPLINES");
/** The GL unit (helper class). */
private static GLU glu;

/** The frames per second setting. */
private static int fps = 1;

/** The OpenGL animator. */
static FPSAnimator animator= new FPSAnimator(fps);

static GLAutoDrawable draw;
/**
* A new mini starter.
*
* @param capabilities The GL capabilities.
* @param width The window width.
* @param height The window height.
*/
public PVetex( GLCapabilities capabilities,double a, double b) {
super();
addGLEventListener(this);
addMouseListener(this);
//xc=a;
//yc=b;
}

/**
* @return Some standard GL capabilities (with alpha).
*/
private static GLCapabilities createGLCapabilities() {
GLCapabilities capabilities = new GLCapabilities();
capabilities.setRedBits(8);
capabilities.setBlueBits(8);
capabilities.setGreenBits(8);
capabilities.setAlphaBits(8);
return capabilities;
}

/**
* Sets up the screen.
*
* @see javax.media.opengl.GLEventListener#init(javax.media.opengl.GLAutoDrawable)
*/
public void init(GLAutoDrawable drawable) {
draw=drawable;
drawable.setGL(new DebugGL(drawable.getGL()));
final GL gl = draw.getGL();

// Enable z- (depth) buffer for hidden surface removal.
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);

// Enable smooth shading.
gl.glShadeModel(GL.GL_SMOOTH);

// Define "clear" color.
gl.glClearColor(1f, 1f, 1f, 1f);

// We want a nice perspective.
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

// Create GLU.
glu = new GLU();
((Component) drawable).addMouseListener(this);
gl.glPointSize (4.0f);
// Start animator.

// animator.start();
// drawable.addMouseListener(this);
}

/**
* The only method that you should implement by yourself.
*
* @see javax.media.opengl.GLEventListener#display(javax.media.opengl.GLAutoDrawable)
*/
public void display(GLAutoDrawable drawable) {
double xx=1;
double yy=1;


draw=drawable;

final GL gl = draw.getGL();


// Clear screen.
gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

// Set camera.
setCamera(gl, glu, 100);

// Write triangle.
gl.glLoadIdentity();
//gl.glTranslatef((float) xc, (float) yc, -5.0f);
//double r = 0.9f; // Radius.
//gl.glTranslatef(0.0f, 0.0f, -5.0f);
//gl.glBegin( GL.GL_TRIANGLE_STRIP ); {
//gl.glPolygonMode( GL.GL_FRONT_AND_BACK, GL.GL_FILL );
//gl.glBegin( GL.GL_POLYGON ); {
//gl.glTranslated(400, 400, 0.0);
//gl.glRotatef((float) xc, 1.0f, 0.0f, 0.0f);
//gl.glRotatef((float) yc, 0.0f, 1.0f, 0.0f);
gl.glBegin( GL.GL_POINTS );

dessiner(gl,xc,yc);
xx=xc;
yy=yc;
gl.glEnd();
/*for( float a = 0; a <= 360; a+=10 ) {
float ang = (float) Math.toRadians( a );
float x = (float) (xx + (float) (r*Math.cos( ang )));
float y = (float) (yy + (float) (r*Math.sin( ang )));
// float z = zc + 0f;
//System.out.println( "x:"+x+" y:"+y+"");
gl.glVertex3d( x, y, 0 );
}
*/
//gl.glEdgeFlag( true );

// drawScene(drawable,xc,yc);



repaint();
}
public void dessiner(GL gl,double x, double y)
{gl=GLU.getCurrentGL();

// System.out.println( "x:"+xc+" y:"+yc+"");

gl.glColor4f( 0f, 0f, 1f, 0.5f );
gl.glVertex3d( x, y, 0); // Center.
gl.glColor4f( 1f, 1f, 1f, 0.5f );

gl.glColor4f( 0f, 0f, 1f, 0.5f );
gl.glVertex3d( 2, 2, 0); // Center.
gl.glColor4f( 1f, 1f, 1f, 0.5f );

repaint();
}
/**
* Resizes the screen.
*
* @see javax.media.opengl.GLEventListener#reshape(javax.media.opengl.GLAutoDrawable,
* int, int, int, int)
*/
public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
draw=drawable;
final GL gl =drawable.getGL();
if(height <= 0) {
height = 1;
}
float h = (float)width / (float)height;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(50.0f, h, 1.0, 1000.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
repaint();
}

/**
* Changing devices is not supported.
*
* @see javax.media.opengl.GLEventListener#displayChanged(javax.media.opengl.GLAutoDrawable,
* boolean, boolean)
*/
public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
repaint();
//throw new UnsupportedOperationException("Changing display is not supported.");
}

/**
* @param gl The GL context.
* @param glu The GL unit.
* @param distance The distance from the screen.
*/
private void setCamera(GL gl, GLU glu, float distance) {
// Change to projection matrix.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();

// Perspective.
float widthHeightRatio = (float) getWidth() / (float) getHeight();
glu.gluPerspective(45, widthHeightRatio, 1, 1000);
glu.gluLookAt(0, 0, distance, 0, 0, 0, 0, 1, 0);

// Change back to model view matrix.
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}

/**
* Starts the JOGL mini demo.
*
* @param args Command line args.
*/
public static void main(String[] args) {
for (UIManager.LookAndFeelInfo laf :
UIManager.getInstalledLookAndFeels() ){
if ("Nimbus".equals(laf.getName())) {
try {
UIManager.setLookAndFeel(laf.getClassName());
UIManager.put("nimbusBase",new Color(255,128,64));
UIManager.put("nimbusBlueGrey", new Color(253,207,49));
UIManager.put("control", new Color(254,239,188));
} catch (Exception e) {
// TODO: handle exception
}

}
}SwingUtilities.invokeLater(new Runnable() {
public void run()
{
GLCapabilities capabilities = createGLCapabilities();
//GLCanvas canvas = new GLCanvas();

PVetex canva = new PVetex(capabilities, 50, 150);
// canva.createGLCapabilities();
//canva.canvas=canvas;
//this.addGLEventListener(canvas);
//addGLEventListener(canva);
// canvas.addMouseListener(canva);

Controle p= new Controle();

frame.add(canva, BorderLayout.CENTER);
frame.add(p, BorderLayout.WEST);
frame.setSize(800, 500);
//frame.setDefaultCloseOperation(Frame.EXIT_ON_CLOSE);
frame.setVisible(true);

animator.start();
canva.requestFocus();

}
});

}

@Override
public void mouseClicked(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub


xc=e.getX();
yc=e.getY();


}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub

}



}
ci joint mon code.

Merci pour votre aide ça serai gentil
0
salma87 Messages postés 3 Date d'inscription mardi 13 janvier 2009 Statut Membre Dernière intervention 21 novembre 2010
21 nov. 2010 à 00:51
dsl g posté mon code avec beaucoup de commentaire,
je le reposte en enlevant les com pour qu'il ne soit pas ambigut

Et merci encore une fois pour votre aide
import java.awt.Color;
import java.awt.Component;
import java.awt.Frame;

import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import java.awt.BorderLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.media.opengl.DebugGL;
import javax.media.opengl.GL;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLCanvas;
import javax.media.opengl.GLCapabilities;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.GLU;
import javax.media.opengl.glu.GLUquadric;
import javax.swing.JFrame;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.FPSAnimator;
import com.sun.opengl.util.GLUT;

public class PVetex extends GLCanvas implements GLEventListener,MouseListener, MouseMotionListener
{public static double xc;
public static double yc;

/** Serial version UID. */
private static final long serialVersionUID = 1L;
public static Frame frame = new Frame("LES SPLINES");
/** The GL unit (helper class). */
private static GLU glu;

/** The frames per second setting. */
private static int fps = 1;

/** The OpenGL animator. */
static FPSAnimator animator= new FPSAnimator(fps);

static GLAutoDrawable draw;
public PVetex( GLCapabilities capabilities,double a, double b) {
super();
addGLEventListener(this);
addMouseListener(this);
}

private static GLCapabilities createGLCapabilities() {
GLCapabilities capabilities = new GLCapabilities();
capabilities.setRedBits(8);
capabilities.setBlueBits(8);
capabilities.setGreenBits(8);
capabilities.setAlphaBits(8);
return capabilities;
}

public void init(GLAutoDrawable drawable) {
draw=drawable;
drawable.setGL(new DebugGL(drawable.getGL()));
final GL gl = draw.getGL();

// Enable z- (depth) buffer for hidden surface removal.
gl.glEnable(GL.GL_DEPTH_TEST);
gl.glDepthFunc(GL.GL_LEQUAL);

// Enable smooth shading.
gl.glShadeModel(GL.GL_SMOOTH);

// Define "clear" color.
gl.glClearColor(1f, 1f, 1f, 1f);

// We want a nice perspective.
gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

// Create GLU.
glu = new GLU();
((Component) drawable).addMouseListener(this);
gl.glPointSize (4.0f);

}

public void display(GLAutoDrawable drawable) {
double xx=1;
double yy=1;


draw=drawable;

final GL gl = draw.getGL();

gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);

setCamera(gl, glu, 100);

gl.glLoadIdentity();


gl.glBegin( GL.GL_POINTS );

dessiner(gl,xc,yc);
xx=xc;
yy=yc;
gl.glEnd();
/*for( float a = 0; a <= 360; a+=10 ) {
float ang = (float) Math.toRadians( a );
float x = (float) (xx + (float) (r*Math.cos( ang )));
float y = (float) (yy + (float) (r*Math.sin( ang )));
// float z = zc + 0f;
//System.out.println( "x:"+x+" y:"+y+"");
gl.glVertex3d( x, y, 0 );
}
*/
//gl.glEdgeFlag( true );

// drawScene(drawable,xc,yc);



repaint();
}
public void dessiner(GL gl,double x, double y)
{gl=GLU.getCurrentGL();

// System.out.println( "x:"+xc+" y:"+yc+"");

gl.glColor4f( 0f, 0f, 1f, 0.5f );
gl.glVertex3d( x, y, 0); // Center.
gl.glColor4f( 1f, 1f, 1f, 0.5f );

gl.glColor4f( 0f, 0f, 1f, 0.5f );
gl.glVertex3d( 2, 2, 0); // Center.
gl.glColor4f( 1f, 1f, 1f, 0.5f );

repaint();
}

public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
draw=drawable;
final GL gl =drawable.getGL();
if(height <= 0) {
height = 1;
}
float h = (float)width / (float)height;
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();
glu.gluPerspective(50.0f, h, 1.0, 1000.0);
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
repaint();
}

public void displayChanged(GLAutoDrawable drawable, boolean modeChanged, boolean deviceChanged) {
}
private void setCamera(GL gl, GLU glu, float distance) {
// Change to projection matrix.
gl.glMatrixMode(GL.GL_PROJECTION);
gl.glLoadIdentity();

// Perspective.
float widthHeightRatio = (float) getWidth() / (float) getHeight();
glu.gluPerspective(45, widthHeightRatio, 1, 1000);
glu.gluLookAt(0, 0, distance, 0, 0, 0, 0, 1, 0);

// Change back to model view matrix.
gl.glMatrixMode(GL.GL_MODELVIEW);
gl.glLoadIdentity();
}

public static void main(String[] args) {
for (UIManager.LookAndFeelInfo laf :
UIManager.getInstalledLookAndFeels() ){
if ("Nimbus".equals(laf.getName())) {
try {
UIManager.setLookAndFeel(laf.getClassName());
UIManager.put("nimbusBase",new Color(255,128,64));
UIManager.put("nimbusBlueGrey", new Color(253,207,49));
UIManager.put("control", new Color(254,239,188));
} catch (Exception e) {
// TODO: handle exception
}

}
}SwingUtilities.invokeLater(new Runnable() {
public void run()
{
GLCapabilities capabilities = createGLCapabilities();

PVetex canva = new PVetex(capabilities, 50, 150);

Controle p= new Controle();

frame.add(canva, BorderLayout.CENTER);
frame.add(p, BorderLayout.WEST);
frame.setSize(800, 500);

frame.setVisible(true);

animator.start();
canva.requestFocus();

}
});

}

@Override
public void mouseClicked(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub

}

public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub


xc=e.getX();
yc=e.getY();


}

@Override
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseDragged(MouseEvent e) {
// TODO Auto-generated method stub

}

@Override
public void mouseMoved(MouseEvent e) {
// TODO Auto-generated method stub

}



}
0
Utilisateur anonyme
21 nov. 2010 à 13:51
Bonjour

Poste plutôt ici ce genre de question :
http://jogamp.762907.n3.nabble.com/jogl-f782158.html



TUER : http://tuer.sourceforge.net/tuer.jnlp

yeah! vive java
0
Rejoignez-nous