anyone have a example for useing volitile image in exclusive mode with

i need a example of how to use a volitile image in exclusive mode with active rendering .

anyone know of one or even partial code of how to do it ive been racking my brain trying to figure out how to do it.

or even a example of fullscreen that i can use to draw to the screen in exclusive fullscreen mode.

and im not talking about the sun tutorial no one can even answer my question about it when i asked in the java forum

[447 byte] By [lightxxxa] at [2007-9-28 11:44:11]
# 1

here's the best I could do in 10 mins:

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

public class Example extends Frame implements Runnable, KeyListener {

VolatileImage v;

int w,h,x,size;

boolean done;

public Example() {

super(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

setUndecorated(true);

setIgnoreRepaint(true);

if (device.isFullScreenSupported()) {

device.setFullScreenWindow(this);

}

if (device.isDisplayChangeSupported()) {

device.setDisplayMode(new DisplayMode(640,480,16,0));

}

show();

w = getSize().width;

h = getSize().height;

x = 0;

size = 30;

v = createVolatileImage(w,h);

done = false;

addKeyListener(this);

new Thread(this).start();

}

public void run() {

while (!done) {

x += 2;

if (x >= w-size) x = 0;

paint(getGraphics());

try {

Thread.sleep(1);

}

catch (InterruptedException e) {

done = true;

}

}

System.exit(0);

}

public void paint(Graphics g) {

Graphics gfx = v.getGraphics();

while (v.contentsLost()) {

if (v.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {

v = createVolatileImage(w,h);

}

gfx = v.createGraphics();

}

gfx.setColor(Color.black);

gfx.fillRect(0,0,w,h);

gfx.setColor(Color.cyan);

gfx.fillOval(x,h/2-(size/2),size,size);

g.drawImage(v,0,0,null);

}

public void update(Graphics g) {

paint(g);

}

public void keyPressed(KeyEvent e) {

if (!done) done = true;

}

public void keyReleased(KeyEvent e) {}

public void keyTyped(KeyEvent e) {}

public static void main(String[] args) {

new Example();

}

}

Woogleya at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 2

thank you sir .

i see that you use the paint method doesnt that thierfore make

it passively rendered ?

would you happen to know how to use this same thing with out useing the paint method i can get the full screen mode up with the code i had but i couldnt figure out how to draw to the screen let me post my code

maybe you can see what i was doing wrong

dont be too harsh though i know my code's pretty bad.

import java.awt.*;

import java.awt.event.*;

import java.awt.Image.*;

public class fullscreentest extends Frame

{

// VARIABLES OR USED CLASSES

private static DisplayMode OD_Mode;

private static DisplayMode D_Mode;

Frame mainFrame;

// CONSTRUCTOR

public fullscreentest(){

go(); // call go method

// could make render loop here as main thread should exit go

// and stay in full screen mode

}

// METHODS

public static void main(String[] args) {

try {

fullscreentest test = new fullscreentest();// call constructor to begin

} catch (Exception e) {

e.printStackTrace();

}

System.exit(0);

}

public void go(){

GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();

// grab monitor device so we can use it to change the monitor resolution

GraphicsDevice device = env.getDefaultScreenDevice();

// i already know the mode im going to set is support so ill skip by this

if(device.isFullScreenSupported() == false){System.out.println(" Warning full screen is not supported "); }

if(device.isFullScreenSupported() == true){

device.setFullScreenWindow(this);

//device.setFullScreenWindow(Window w);

System.out.println(" full screen is supported ");

}

// graphics configuration class not to sure about this

// looks like were grabing the default config which is in full screen becacuse we set device to fullscreen

// or not? because were geting the default configuration im a lil confused here

GraphicsConfiguration gc = device.getDefaultConfiguration();

// create a frame is it in full screen below or not ?

mainFrame = new Frame(gc);

mainFrame.setUndecorated(true);// get rid of title bars and stuff

mainFrame.setIgnoreRepaint(true);// ignore repainting que

mainFrame.setResizable(false);// do not allow the frame to be resized

OD_Mode = device.getDisplayMode();// save the old device configuration

D_Mode = device.getDisplayMode();// initialy make new config as old

if (device.isDisplayChangeSupported() == false) {

System.out.println(" warning display mode change is unsupported ");

}

if (device.isDisplayChangeSupported() == true) {// hopefully this is possible

// set new d_mode to 640,480

DisplayMode D_MODE = new DisplayMode(640, 480, 32, 0);

// mow d_mode should basically have all the info for the device and the screen size

// and the colormodel that is being used

System.out.println(" display mode change is supported ");

}

// is this still correct ?

// know i have no idea how to use a volitile image or if i even need to

Graphics pen = mainFrame.getGraphics();

int acc_mem = device.getAvailableAcceleratedMemory();

System.out.println(" available accelerated memory or ram left reported "+acc_mem);

boolean done = true;

long count = 0;

while (done) {

// Draw as appropriate using myGraphics ? draw to what. memory ?

// thats kinda a cut off in the tutorial left me hanging.

count ++;

//pen = getPaintGraphics();

//pen = mainFrame.getPaintGraphics();

//pen.setColor(Color.blue);

//pen.drawLine(100,100,50,50);

pen.drawLine(100,100,50,50);

// check for exit

if(count > 200000000){

System.out.println(" count "+count);

done = false;

pen.dispose();

}

}

}

}

lightxxxa at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 3

just because I'm using a paint method doesn't mean it's passive rendering. It's active rendering because I'm not calling repaint() and waiting for the JVM to decide to paint, I call paint(getGraphics()) so I can paint whenever I need to. I think the only time you don't use paint is if you use BufferStrategy. Now that you know the difference with painting methods, see if you can figure your code out yourself. If you really can't do it, put up a few dukes and I'll take a peek :P

Woogleya at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 4
:) point taken na with the example you gave me. i should have no problem figureing out the remaining peices.that i didnt understand.
lightxxxa at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 5
thanks again wooley i threw a duke your way. i dont think their really worth anything anymore.
lightxxxa at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 6
I collect them anyways, one of the many boring things I do. :)
Woogleya at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...
# 7

by the way, here's a commented version of the example I gave earlier in case the puzzle pieces are upside down for you...

import java.awt.*;

import java.awt.event.*;

import java.awt.image.*;

/* Goes into FullScreen with 640x480 16 bit

* Not all proper checks are made (like getting available DisplayModes),

* But you can always look at the doc for the rest of the checks. Besides,

* What computer doesn't have 640x480...?

*/

public class Example extends Frame implements Runnable, KeyListener {

VolatileImage v;

int w,h,x,size; // x and size are for the moving ball

boolean done; // when this is true, the program exits

public Example() {

/* Sets up the frame to be used for fullscreen */

super(GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration());

GraphicsDevice device = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();

/* the below 2 methods aren't required

* but using them results in best performance.*/

setUndecorated(true);

setIgnoreRepaint(true);

/* A few mandatorial checks */

if (device.isFullScreenSupported()) {

device.setFullScreenWindow(this);

}

if (device.isDisplayChangeSupported()) {

device.setDisplayMode(new DisplayMode(640,480,16,0));

}

/* our frame must be showing before we

* we create our BufferStrategy or image,

* in this case a VolatileImage.

* Showing our frame also switches to

* fullscreen mode.

*/

show();

w = getSize().width;

h = getSize().height;

x = 0;

size = 30;

v = createVolatileImage(w,h); // creates volatile image (duh)

done = false; // program exits when true

addKeyListener(this); // used for exiting

new Thread(this).start(); // starts the thread

}

public void run() {

while (!done) {

x += 2; // increase ball location

if (x >= w-size) x = 0; // back to left if all the way right

/* You could also use repaint() here,

* but you won't get a screen update

* until the system decides it's time.

* calling paint(getGraphics()) is much faster

*/

paint(getGraphics());

/* Pausing of the thread... */

try {

Thread.sleep(1);

}

catch (InterruptedException e) {

done = true; // exit if there was some error

}

}

System.exit(0); // this won't be called until done is true

}

public void paint(Graphics g) {

/* this attempts to get the graphics

* from VolatileImage */

Graphics gfx = v.getGraphics();

/* If VolatileImage has no image memory,

* we restore it and get the graphics for it */

while (v.contentsLost()) {

if (v.validate(getGraphicsConfiguration()) == VolatileImage.IMAGE_INCOMPATIBLE) {

v = createVolatileImage(w,h);

}

gfx = v.createGraphics();

}

/* this paints the ball etc */

gfx.setColor(Color.black);

gfx.fillRect(0,0,w,h);

gfx.setColor(Color.cyan);

gfx.fillOval(x,h/2-(size/2),size,size);

g.drawImage(v,0,0,null); // draw the VolatileImage

}

public void update(Graphics g) { // used for no blinking

paint(g);

}

public void keyPressed(KeyEvent e) {

if (!done) done = true; // program exits on any key press

}

public void keyReleased(KeyEvent e) {}

public void keyTyped(KeyEvent e) {}

public static void main(String[] args) {

new Example();

}

}

Woogleya at 2007-7-12 2:32:02 > top of Java-index,Other Topics,Java Game Development...