Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (429)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (468)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: [SOLVED] Shear transformation in libgdx on: 2013-09-28 15:47:13
My original Java2D application that I want to convert to libGdx uses a different shear transformation for every drawed image. Using the SpriteBatch.setTransformMatrix is not an option because it will render the SpriteBatch useless (flushes each draw to the GPU).

I tought about extending the Sprite class or build a wrapper around it. Problem with this solution is that it can become implemetation dependent on the Sprite class real fast.

I noticed that the transformations of the Sprite class are a bit different from the Java2D implementation. For example: rotate in Java2D rotates default around the bottom left point of an image. Sprite rotates around the center of the image. Of course this can all be solved.

Making my own AffineTransform implementation has the benefit that the original code doesn't have to be rewritten much.

In the end it is a decision with both pro's and con's. Rewrite more parts of the original code or create an easy way to use libGdx for this application. In this case I choose not to rewrite big parts of the original code.
2  Game Development / Newbie & Debugging Questions / Re: [SOLVED] Shear transformation in libgdx on: 2013-09-27 22:11:04
Indeed. Looks like I have to make my own AffineTransform implementation that behaves like the Java2D one.
3  Game Development / Newbie & Debugging Questions / Re: Shear transformation in libgdx on: 2013-09-23 22:26:54
Fixed. I now use the standard Java AfineTransform to change the vertices. This makes converting my existing code (Java2D) much easier because AfineTransform is used there quite frequently. See the example code below.

And of course. Thanks for the help  Smiley

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  
public class GdxPerf implements ApplicationListener {
   private OrthographicCamera camera;
   private SpriteBatch batch;
   private Texture texture;
   private Sprite sprite;
   private AffineTransform transform = new AffineTransform();
   
   private float[] verticesSrc = null;
   private float[] verticesDst = null;
   private float[] src = new float[8];
   private float[] dst = new float[8];
   
   @Override
   public void create() {      
      camera = new OrthographicCamera();
     
      batch = new SpriteBatch();
     
      texture = new Texture(Gdx.files.internal("data/Alice.png"));
      texture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
     
      TextureRegion region = new TextureRegion(texture, 0, 0, 512, 512);
     
      sprite = new Sprite(region);
      sprite.setPosition(0, 0);
     
      verticesSrc = sprite.getVertices();
      verticesDst = Arrays.copyOf(sprite.getVertices(), sprite.getVertices().length);
     
      transform = new AffineTransform();
   }

   @Override
   public void dispose() {
      batch.dispose();
      texture.dispose();
   }

   @Override
   public void render() {      
      Gdx.gl.glClearColor(0, 0, 0, 0);
      Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     
      transform.setToIdentity();
     
      transform.translate(50.0d, 50.0d);
      transform.scale(1.5d, 1.5d);
      transform.shear(0.25d, 0.10d);
      transform.rotate(-Math.PI / 8.0d);
     
      src[0] = verticesSrc[SpriteBatch.X1];
      src[1] = verticesSrc[SpriteBatch.Y1];
      src[2] = verticesSrc[SpriteBatch.X2];
      src[3] = verticesSrc[SpriteBatch.Y2];
      src[4] = verticesSrc[SpriteBatch.X3];
      src[5] = verticesSrc[SpriteBatch.Y3];
      src[6] = verticesSrc[SpriteBatch.X4];
      src[7] = verticesSrc[SpriteBatch.Y4];

      transform.transform(src, 0, dst, 0, 4);
     
      verticesDst[SpriteBatch.X1] = dst[0];
      verticesDst[SpriteBatch.Y1] = dst[1];
      verticesDst[SpriteBatch.X2] = dst[2];
      verticesDst[SpriteBatch.Y2] = dst[3];
      verticesDst[SpriteBatch.X3] = dst[4];
      verticesDst[SpriteBatch.Y3] = dst[5];
      verticesDst[SpriteBatch.X4] = dst[6];
      verticesDst[SpriteBatch.Y4] = dst[7];

      camera.setToOrtho(false);
      batch.setProjectionMatrix(camera.combined);
      batch.begin();
     
      batch.draw(texture, verticesDst, 0, verticesDst.length);
           
      batch.end();
   }

   @Override
   public void resize(int width, int height) {
   }

   @Override
   public void pause() {
   }

   @Override
   public void resume() {
   }
}
4  Game Development / Newbie & Debugging Questions / Re: Shear transformation in libgdx on: 2013-09-22 18:35:56
Setting a shear transformation on the SpriteBatch is not an option for me. I have many sprites that are sheared different ways. This will (like you say) kill the SpriteBatch. I'am going to try manipulation the vertices. I will keep you posted.
5  Game Development / Newbie & Debugging Questions / [SOLVED] Shear transformation in libgdx on: 2013-09-22 15:42:03
I recently started experimenting with libgdx. Creating a SpriteBatch drawing sprites on it. Work like a sharm. It is possible to resize and rotate an sprite but I can't find a method to performe a shear transformation on a sprite, like it is possible in Java2D: http://docs.oracle.com/javase/7/docs/api/java/awt/geom/AffineTransform.html

Can somebody help me out on how to perform a shear operation on a sprite in libgdx?
6  Java Game APIs & Engines / Java 2D / Flickering during resizing of a window on: 2011-07-01 18:14:19
To avoid flickering during the resize of my game window I'am using the sun.awt.noerasebackground property. This works oké for simple drawings. However when the drawing complexity increases so does the flickering! I have tried different things to get rid of the flickering but I'am running out of options.

By the way... I don't wan't to use Toolkit.getDefaultToolkit().setDynamicLayout(false). This eliminates flickering completely but makes it impossible to resize the drawing during a resize.

OS: Vista 64bit;
JRE: build 1.6.0_26-b03

Because code says more than a thousand words  Wink see the example below. Use the static variable COMPLEXITY to increase the "complexity" of the drawing till the point the flickering starts.

Any suggestions to get rid of this flickering?

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  
114  
115  
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.Graphics2D;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferStrategy;

import javax.swing.JFrame;

public class FlickerDemo
{
   // The frame to contain this canvas
  private JFrame jFrame = null;
   
   // The canvas to draw on
  private Canvas canvas = null;
   
   // The buffer strategy
  private BufferStrategy strategy = null;
   
   // Drawing routine complexity
  private static final int COMPLEXITY = 10000;
   
   public static void main(String[] args)
   {
      new FlickerDemo().start();

   }
   
   public FlickerDemo()
   {
      // No flickering during resize
     System.setProperty("sun.awt.noerasebackground", "true");
     
      // Acquiring the current Graphics Environment, Device and Configuration
     GraphicsEnvironment graphicsEnv = GraphicsEnvironment.getLocalGraphicsEnvironment();
      GraphicsDevice graphicsDev = graphicsEnv.getDefaultScreenDevice();
      GraphicsConfiguration graphicsConf = graphicsDev.getDefaultConfiguration();

      // Create a canvas
     canvas = new Canvas(graphicsConf);      
      canvas.setFocusTraversalKeysEnabled(false);
      canvas.setIgnoreRepaint(true);
     
      // Set background color to red to make flickering more visible
     canvas.setBackground(Color.red);
     
      // Create a frame
     jFrame = new JFrame(graphicsConf);
      jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      jFrame.setTitle("FlickerDemo");
      jFrame.setFocusTraversalKeysEnabled(false);
      jFrame.setIgnoreRepaint(true);
      jFrame.setAlwaysOnTop(false);
      jFrame.setUndecorated(false);            
     
      // Add canvas to the frame
     jFrame.add(canvas);
     
      // Make the window visible
     jFrame.pack();
      jFrame.setResizable(true);
      jFrame.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
      jFrame.setVisible(true);
     
      // Set the size and location of the jframe
     jFrame.setSize(800, 600);
      jFrame.setLocation(0, 0);
     
      // Create the buffering strategy which will allow AWT to manage the accelerated graphics
     canvas.createBufferStrategy(2);
      strategy = canvas.getBufferStrategy();
   }

   public void start()
   {
      while(true)
      {        
         // Get the size of the canvas
        Dimension windowSize = canvas.getSize();
         int screenX = windowSize.width;
         int screenY = windowSize.height;
         
         // Get hold of a graphics context for the accelerated surface
        Graphics2D g = (Graphics2D)strategy.getDrawGraphics();
         
         // Fill background
        g.setColor(Color.black);
         g.fillRect(0, 0, screenX,screenY);

         // Draw contents of window
        draw(g, screenX, screenY);
         
         // finally, we've completed drawing so clear up the graphics
        // and flip the buffer over
        g.dispose();
         strategy.show();
      }
   }
   
   /*
    * Draw a square in the center of the canvas
    */

   private void draw(Graphics2D g, int screenX, int screenY)
   {
      g.setColor(Color.red);
      for(int i=0; i<COMPLEXITY; i++)
      {
         g.fillRect(screenX / 2 - 10, screenY / 2 - 10, 20, 20);
      }
   }  
}
7  Java Game APIs & Engines / Java 2D / Re: Java demo needs testers on: 2002-12-04 10:59:20
Works on my system, but only when the bitdepth of the demo is the same as the bitdepth of my desktop! When I choose a different bitdepth than the bitdepth of my desktop the graphics are all "scrambled" (full screen mode).

Java version: 1.4.1-b21
OS: W2K SP3
Proc: T-Bird 1Ghz
Mem: 512MB
Graphics: GF4 TI4200
8  Java Game APIs & Engines / Java 2D / Re: Transparent images. What am I doing wrong? on: 2002-11-28 09:53:32
Drawing an accelerated "gif" image into an Image with Transparency.BITMASK does not accelarate this Image.

The only ways that I have found to create an working accelerated image with 1-bit transparency is by creating an gif or png file with an 8-bit indexed palette in wich one color is specified as transparent.

I'am now using indexed png files as a workaround. What also could work is creating an BufferdImage of type TYPE_BYTE_INDEXED. I havend tried it yet but it seems to fit the patern.

Has anybody else simular experiences with transparent images?
9  Java Game APIs & Engines / Java 2D / Re: Transparent images. What am I doing wrong? on: 2002-11-21 10:12:28
I have been able to create 1-bit transparent accelerated images with gif's and 8-bit color indexed png files. Creating 1-bit transparent accelerated images with "Transparency.BITMASK" has failed however.

Anyway I want to be able to create images with at least a colordepth of 16-bit and with 1-bit transparency. Is it possible (and so yes. how?) to create 16-bit indexed images (png files) in wich one color represents transparency and are these images accelerated?

Second question: Has anyone a full working example of creating an 1-bit transparent accelerated image with "Transparency.BITMASK"?
10  Java Game APIs & Engines / Java 2D / Re: Transparent images. What am I doing wrong? on: 2002-11-15 17:17:40
It is true, that transparency doesn't work on VolatileImages. It is however possible to do hardware acceleration on images with 1bit transparency. This requires a "workaround" that I have read in another post. However I can't seem to get this working.

Quote

In answer to your first question, there is unfortunately no way to create a VolatileImage that is non-opaque (translucent or transparent).  This is API that we should introduce in jdk1.5 (a ways off, but I just thought I'd mention it).  The main idea behind the first VolatileImage API was to have the ability to force the back buffer to live in hardware.  Back buffers are usually opaque, so this simple API did the trick.  Now that that functionality is there, we can beef up the Volatile API to include other related operations/formats that people care about.

As to how you work around the issue, you should be able to use createCompatibleImage(w,h,transparent) for any background which will remain static.  Say you have a scrolling starfield (or whatever); you can create this as a compatible image and simply copy from there into your Volatile back buffer.  At some point (usually the second copy), we will recognize this as something that we can do better in hardware and we will create a VRAM version of that compatible image to use from then on.  As long as you are not touching the pixels of the compatible image, we will continue to use the VRAM version of it and you will get native-hardware speeds.

Things to watch for:
- DO NOT grab the Raster or DataBuffer for the compatible image.  If you do this, we give up on accelerating that image because we cannot guarantee that our VRAM version matches the original image (because you can tweak the pixels directly without our knowing).  We will probably introduce some sort of Lock/Unlock API for this in the future, but for now just avoid it if at all possible.
- Accelerating compatible images only works for opaque and transparent images for now.  We're working on translucency acceleration; this should be there in jdk1.5.
- There can be problems with images larger than the screen size (we may not be able to create a VRAM image larger than that size), so if you need a background image larger than this, you'll have to tile it into several images.

11  Java Game APIs & Engines / Java 2D / Transparent images. What am I doing wrong? on: 2002-11-15 15:59:00
For a game I have created an VolatileImage as a backbuffer. I have tried to blit transparent gif images to this backbuffer and this works ok. The sprite is accelerated. When I try to create my own transparent BufferedImage the sprite works, but is not accelerated. I know that it can be done. So what im I doing wrong.

Below is the part of the code that blits the sprite to the backbuffer. the gif image is accelerated, but my own Image is not accelerated.

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public class TestTransparent 
{    
    private Image img = null;
   
    /** Creates a new instance of TestTransparent */
    public TestTransparent(GraphicsConfiguration graphConfig)
    {
//      img = Toolkit.getDefaultToolkit().getImage("G:\\trans.gif");
       
        img = graphConfig.createCompatibleImage(400, 400, Transparency.BITMASK);
    }
   
    public void draw(Graphics g, int x, int y)
    {
        g.drawImage(img, x, y, null);
    }
}
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (81 views)
2014-04-15 18:08:23

BurntPizza (73 views)
2014-04-15 03:46:01

UprightPath (84 views)
2014-04-14 17:39:50

UprightPath (67 views)
2014-04-14 17:35:47

Porlus (84 views)
2014-04-14 15:48:38

tom_mai78101 (107 views)
2014-04-10 04:04:31

BurntPizza (167 views)
2014-04-08 23:06:04

tom_mai78101 (263 views)
2014-04-05 13:34:39

trollwarrior1 (214 views)
2014-04-04 12:06:45

CJLetsGame (223 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!