java-2d

Java 2D Drawing Optimal Performance

I'm in the process of writing a Java 2D game. I'm using the built-in Java 2D drawing libraries, drawing on a Graphics2D I acquire from a BufferStrategy from a Canvas in a JFrame (which is sometimes full-screened). The BufferStrategy is double-buffered. Repainting is done actively, via a timer. I'm having some performance issues though, e...

Java2D: Clipping a Graphics object with a Line

Is there a way to use a Graphics object's 'setClip()' method to clip using a Line-ish shape? Right now I'm trying to use a Polygon shape but I'm having problems simulating the "width" of the line. I basically draw the line, and when I reach the end, I redraw it but this time subtract the line width from y-coordinate: Polygon poly = ne...

Java2D: Is it always safe to cast Graphics into Graphics2D

Assuming we always use a Sun JVM (say, 1.5+), is it always safe to cast a Graphics reference to Graphics2D? I haven't seen it cause any problems yet and, to my understanding, the Graphics class is legacy code but the Java designers didn't want to change the interfaces for Swing and AWT classes in order to preserver backwards compatibi...

Java2D Performance Issues

I'm having performance oddities with Java2D. I know of the sun.java2d.opengl VM parameter to enable 3D acceleration for 2D, but even using that has some weird issues. Here are results of tests I ran: Drawing a 25x18 map with 32x32 pixel tiles on a JComponent Image 1 = .bmp format, Image 2 = A .png format Without -Dsun.java2d.opengl=t...

Raw Java 2D implementation of a scrollbar

How would I go about writing my own scrollbar using standard Java 2D. I really don't want to use swing, and I've already made up my own component parts for everything else such as buttons etc. I'm not really looking for code, rather the math involved in the event changes and the drawing. ...

Best API for simple 2d graphics with Java

I'm not sure what the best api for simple 2d graphics with Java is. I know java.awt.Graphics2D was the standard but has it been replaced? Swing is the new api for java GUI apps but it seems a bit heavy for what I want. What I really want is something like the C SDL(http://libsdl.org/) library. ...

Where is groovy.swing.factory.BindProxyFactory?

When trying to use GraphicsBuilder, I get a java.lang.NoClassDefFoundError for groovy.swing.factory.BindProxyFactory. This is my environment: % java -version java version "1.6.0_10" Java(TM) SE Runtime Environment (build 1.6.0_10-b33) Java HotSpot(TM) Server VM (build 11.0-b15, mixed mode) % groovy --version Groovy Version: 1.5.7 JVM: ...

Getting started with a 2d online game

I've plotted out the basic game idea outline, but rather than make another mod of some other game, I want to dip my toes into the waters of stand-alone game development at long last. This will likely be an RPG-style, top-down online multiplayer versus game with elements of puzzle solving, cat and mouse mind games, and even some shooter ...

Open Source Libraries for Rendering Vector Graphics Formats Through Java2D?

What are my options for rendering graphics encoded by Java2D to vector graphics formats such as EPS, SWF, SVG, VML, PDF and others I might not have heard of yet with open source libraries? Batik is the most widely-used library for rendering SVG. What other options are there? iText is widely used for rendering PDF. Is there something le...

code works for java graphics, but not graphics2d

inside a paintcomponent. it takes g as parameter, and g can be graphics or graphics2d. the class extends jpanel. then: super.paintComponent(g); this.setBackground( Color.BLACK ); if g is graphics it works, but if it's graphics2d it doesn't. it compiles with both, but graphics2d doesn't change the background color. how come? ...

tinting sprites in Java2D on the fly?

I am creating a game with an ascii-like map using Java2D on Linux (like a roguelike). By rendering BufferedImages via Graphics2D.drawImage the terrain is rendered. I would like to change the hue of each drawn image on the fly, without hurting performance too much. How can I achieve this? I suspect setComposite is part of the puzzle. C...

What are some faster alternatives to Java2d?

I'm looking to do some physics simulations and I need fast rendering in Java. I've run into performance issues with Java2d in the past, so what are the fast alternatives? Is JOGL significantly faster than Java2d? ...

Rotation and Scaling -- How to do both and get the right result?

I've got a set of Java2D calls that draw vectors on a graphics context. I'd like for the image to be doubled in size and then rotated 90 degrees. I'm using the following code to do this: Graphics2D g2 = // ... get graphics 2d somehow ... AffineTransform oldTransform = g2.getTransform(); AffineTransform newTransform = (AffineTransform)...

Horrendous Performance in a Simple Java2D App

Hi all, I've just finished my entry for the 14th Ludum Dare 48-hours game making competition yesterday, and decided to do it in java using java2d for the graphics. I'm not that familiar with the API and haven't done a lot of graphics programming, but my game is quite small (only a dozen or so very small moving object) so I assumed I c...

how can i do to a 2D image and spin it around it's X, Y, or Z axis as if it were a 3D image.in java ??

I want to achieve the effect of a 2D image I have but a little inclined, for example a plane, I want the image can be rotated about its axis Y. .. anyone can help me with some idea of how to do ..** ...

Java2D: scaling issues

Hi all, I'm a reasonably experienced Java programmer but relatively new to Java2D. I'm trying to scale an image but I'm getting poor quality results. The image is a preview of a panel so contains things like text and textfields. I'll always be scaling down, never up. Currently I'm using the following code:- g.drawImage(panelImage, 0, ...

Low-hanging graphics programming fruits?

Hi, I'm currently working on a tile-based game in Java2D, and I was thinking of adding some cheap eye candy. For example, implementing a simple particle system (maybe something like this) for explosions and/or smoke. Do you have any suggestion for relatively easy to program effects that wouldn't require drawing a lot (or at all) of ...

Does anyone know of a java2d text library?

This is what I need in my game regarding text: Word Wrap Support given a bounding box Vertical and Horizontal alignment given a bounding box Now, I've been reading about how to use TextLayout, and it seems possible to write all this myself but I'd prefer to think at a higher level. I just want a Label class with a signature like this:...

Simulate a Piping System in Java

Hey, I need to simulate a fairly complex water piping system (2D) in Java. I need to be able to show the flow of water through some pipes when some others are blocked. What toolkit/APIs can I use? I am a newbie to graphics programming. Kindly advice. Thanks DC ...

Accessing font kerning information in Java2D

Little background.. I'm in the process of making an OpenGL game using Java and LWJGL. I've written a TextRenderer-class that renders text using cached pages of glyphs. The glyphs itself are rendered in Java2D to BufferedImages and packed into texture pages along with the glyph measurements. TextRenderer draws the characters as textured ...