Posted by
Xerxes Rånby on
Feb 17, 2016; 2:08pm
URL: https://forum.jogamp.org/Implement-AWT-in-JOGL-tp4036268p4036287.html
GLG2D is an implementation of Graphics2D that uses JogAmp JOGL
https://github.com/brandonborkholder/glg2dhttp://brandonborkholder.github.io/glg2d/Since your example uses Graphics2D then this is a good way to accelerate
your application!
" In order to render your scene using OpenGL instead of Java2D, just wrap your JComponent inside a GLG2DCanvas.
JComponent renderPane = ...
JFrame frame = new JFrame("My Game");
frame.setContentPane(new GLG2DCanvas(renderPane));
...
And that's it! "
2016-02-17 14:41 GMT+01:00 choracy69 [via jogamp] <
ml-node+s762907n4036285h98@n3.nabble.com>:
> Ok, I will try with byteBUffer.
>
> This is my fragment of code:
>
> public class Fire extends Applet
> implements MouseListener, MouseMotionListener, KeyListener, Runnable
> {
> int d = 900;
> int h = 600;
>
> Random rand = new Random();
> BufferedImage bi;
> Graphics2D big;
> Thread artist = null;
>
> int [][] grid, futureGrid; // asigns 2 arrays
> int a = 0;
> int b = 0;
> int tempx = 0;
> int tempy = 0;
> int mwfuel, tranfuel, conifuel, decifuel, burnt, bfire, fire;
> //color of different fuel types
> int terrain = 0;
> int E = rand.nextInt(100);
> int windd = 0;
> int wspeed = 0;
> int xt = 0;
> String direc;
> int spread = 0;
> int spoty = 0;
> int spotx = 0;
>
>
>
> public void init()
> {
> setSize(d, h);
> setBackground( new Color(48,48,48) );
> addMouseMotionListener(this);
> addMouseListener(this);
> addKeyListener(this);
> setFocusable(true);
> bi = (BufferedImage) createImage(d, h);
> big = bi.createGraphics();
>
> wspeed = rand.nextInt(25);
> mwfuel = new Color(190,204,91).getRGB();
> tranfuel = new Color(168,192,20).getRGB();;
> conifuel = new Color(85,101,39).getRGB();;
> decifuel = new Color(110,80,42).getRGB();;
> burnt = new Color(48,48,48).getRGB();;
> bfire = new Color(192,64,0).getRGB();;
> fire = new Color(255,96,0).getRGB();;
>
> grid = new int[d][h];
> futureGrid = new int[d][h];
>
> for (int i=0; i<d;i++){ // sets the whole terrain to 0
> indicating that this pixel did not catch fire
> for (int j=0; j<h;j++){
> grid[i][j] = 0;
> terrain = rand.nextInt(5);
> switch(terrain) {
> case 1:
> bi.setRGB(i,j,mwfuel);
> break;
> case 2:
> bi.setRGB(i,j,tranfuel);
> break;
> case 3:
> bi.setRGB(i,j,conifuel);
> break;
> case 4:
> bi.setRGB(i,j,decifuel);
> break;
> }
> }
> }
>
> windd = rand.nextInt(5);
> switch (windd) {
> case 1:
> direc = "North";
> break;
> case 2:
> direc = "South West";
> break;
> case 3:
> direc = "West";
> break;
> case 4:
> direc = "North West";
> break;
> }
> System.out.println("Init sie wykonał");
> }
>
> ...
> }
>
> And fragment of paint()
>
> public void paint(Graphics g)
> {
> Graphics2D g2 = (Graphics2D) g;
>
> //System.out.println("PAINT");
> if (xt<wspeed) {
> xt++;
> }
> if (xt>wspeed) {
> xt--;
> }
> if (xt==wspeed) {
> wspeed = rand.nextInt(25);
> }
> if ((xt>10)&&(xt<15)) {
> spread = 1;
> }
> if ((xt>=15)&&(xt<20)) {
> spread = 2;
> }
> if (xt>=20) {
> spread = 3;
> }
>
> for (int x=1;x<d-1; x++){
> for (int y=1; y<h-1;y++){
>
>
>
> int nb = neighbors(x,y);
> if ((grid[x][y] == 0)&&(nb == 0)){ //current is green
> and neighbours are green
> futureGrid[x][y] = 0;
> }
> else if ((grid[x][y] == 0) && (nb != 0) && (bi.getRGB(x,y) ==
> mwfuel) && (E<59)) {
> bi.setRGB(x,y,fire);
> futureGrid[x][y] = 1;
> if(windd == 1) {
> if((y-spread>0)&&(y-spread<h)){
> for(int w=0;w<=spread;w++) {
> bi.setRGB(x,y-w,fire);
> futureGrid[x][y-w] = 1;
> }
> int tempy = rand.nextInt(y);
> if (spread == 3) {
> if (tempy<5) {
> tempy = rand.nextInt(y);
> bi.setRGB(x,tempy,fire);
> grid[x][tempy]=1;
> }
> }
> }
> }
>
> if(windd ==2) {
> if((x-spread>0)&&(x-spread<d-1)) {
> if((y+spread>0)&&(y+spread<h)){
> for(int w=0;w<=spread;w++) {
> bi.setRGB(x-w,y+w,fire);
> futureGrid[x-w][y+w] = 1;
> }
> }
> }
> }
> ...
> int[][] temp = grid;
> grid = futureGrid;
> futureGrid = temp;
> g2.drawImage(bi, null, 0, 0);
> }
>
> ------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
>
http://forum.jogamp.org/Implement-AWT-in-JOGL-tp4036268p4036285.html> To start a new topic under jogl, email
> ml-node+s762907n782158h61@n3.nabble.com
> To unsubscribe from jogamp, click here
> <
http://forum.jogamp.org/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=762907&code=eGVyeGVzQGd1ZGlubmEuY29tfDc2MjkwN3wtNTE5NjUwMzEw>
> .
> NAML
> <
http://forum.jogamp.org/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>