java-2d

Low-hanging graphics programming fruits?

a 夏天 提交于 2019-12-04 13:48:41
问题 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 new art? Tutorials and code samples for said effects would also be most welcome! -Ido. PS - if absolutely necessary I could switch to something like LWJGL/JOGL or even

Drawing a nice circle in Java

▼魔方 西西 提交于 2019-12-04 12:15:40
问题 I'm using Java Graphics and I keep getting "ugly" circles. Here's what my Java program makes And here's the same thing being made in Matlab I think it is clear that the Java one is not as "nice" looking as the Matlab one, particularly on the edges of the circle. Note that this has nothing to do with the resolution...these images are practically the same size. Also note that I am already setting rendering hints. Here's a stand alone with a Main function you can run to test this out. package

Java 2D scene graph library for GUI

我怕爱的太早我们不能终老 提交于 2019-12-04 08:44:06
问题 I'm looking for a 2D scene graph library for building GUI applications. It should be fast, using Java2D and be compatible with Swing (embeddable in a Swing app and also display Swing components). Support for animations is a plus. Do you have any experience with some of the libraries? Are there any libraries that I have missed? I have to add that I'm not totally offended by a Scala library. Project Scene Graph seems reasonably fast only GPL (no LGPL) supports animations abandoned 2 years ago

Java2D: BufferedImage not accelerated on Ubuntu

别来无恙 提交于 2019-12-04 07:51:34
We are currently developing a game in Java using the Java2D API and are experiencing some strange performance issues when running it in an Ubuntu environment. Our frame rate drops from an average of 62fps on Windows and Mac systems to about 10fps on Ubuntu. After some hours of debugging and testing various JVM flags it seems to be that BufferedImages using a bitmask are not being accelerated under Ubuntu because System.out.println(img.getCapabilities(config).isAccelerated()); prints out false. Currently we are loading our images via img = ImageIO.read(url); and are then creating a device

Can't draw thin lines with Java2D

你。 提交于 2019-12-04 07:30:50
I'm trying to draw a polygon with a stroke of 1 pixel. Because the entire polygon is scaled by 100, I set the line width to 0.01. For some reason though, the polygon gets drawn with an on-screen line width of what looks to be 100 pixels instead of 1. I'm using GeneralPath as the polygon shape. Thin lines do get drawn if I use the same approach for drawing Line2D shapes. g2d.scale(100, 100); g2d.setStroke(new BasicStroke(0.01f)); g2d.draw(theShape); New info: If I remove the setStroke line I correctly get a 2 pixel line, since a BasicStroke of 0.02f was set on the Graphics2D object earlier.

How to create a curve between 2 points in 2D and get back Points that makes that curve every d distance?

笑着哭i 提交于 2019-12-04 07:18:31
I'm not good in math. I have 2 points, A(x1, y1) and B(x2, y2) in 2D. I need to create a virtual path from point A to B curved at R(radius), and then return an array of points which are describing this curved path, not all maybe every D(distance) from each other. In Java I need a method like this: private ArrayList<PointF> generateCurve(PointF pFrom,PointF pTo,float pRadius,float pMinDistance){ ArrayList<PointF> pOutPut = new ArrayList<PointF>(); // ...generate result to pOutPut return pOutPut; } How to do this ? Martijn Courteaux I didn't gave up and I've been working on it for a few more

drawPolygon keeps drawing lines from starting (mousePressed) location to current (mouseDragged) location

ぐ巨炮叔叔 提交于 2019-12-04 05:37:47
问题 So, I'm trying to dynamically draw a Polygon starting from when I click the mouse until I stop dragging and release. Instead of, for the purpose of this question, a square outline being drawn when I click, drag down, then right-across, then up, then left-across, this is what happens: http://imgur.com/t8ZN3Pp Any suggestions? Notes: model.addPolygon() creates a Polygon with starting points and adds it to an ArrayList called 'polys' model.addPolygonPoint() adds points to this created polygon

How do I load an enormous image to Java via BufferedImage?

时光怂恿深爱的人放手 提交于 2019-12-04 05:26:35
I want to load large images (18000 x 18000) to my application. If i use BufferedImage with type int_rgb , I need around 1235mb of heap memory to load. This is a very high amount of memory, and end users will likely have less ram (1GB or less). On my development PC, when I load the image from MyEclipse IDE, it throws an out of memory Exception . When i pack my code to an executable jar and run it on my PC external of Eclipse, it still throws an exception. How do I load such a large image into my application using buffered image without using 1235mb of memory? Is there a trick, like splitting

Java Swing deprecated in favor of JavaFx 2.0 [closed]

老子叫甜甜 提交于 2019-12-04 04:13:45
Am I correct that Oracle has deprecated Swing and that JavaFx 2.0 is it's official replacement? This makes sense to me because it would seem kind of goofy for oracle to maintain the development of two competing api's that do pretty much the same thing. Yet Oracle has introduced enhancements like translucent windows, shaped windows, etc into the java 7 swing api. I take it this may be for transitional purposes but still I'd really appreciate it if someone could clue me on what the current 'standard' or 'best practice' choice is for new applications - Swing or javafx 2.0? Another source of

Trying to draw lines with JPanel

两盒软妹~` 提交于 2019-12-03 21:02:37
I am trying to draw lines using JPanel and I have hit somewhat of a wall. I can get two sides down but once it comes to subtracting from the x cord it all goes wrong. package GUIstuff; import java.awt.Graphics; import javax.swing.JPanel; public class DrawPanel extends JPanel{ public void paintComponent (Graphics g){ super.paintComponent(g); int width = getWidth(); int height = getHeight(); int drawCounter = 0; // counters for all the while statements int drawCounter2 = 0; int drawCounter3 = 0; int drawCounter4 = 0; int x1 = 0; // cords change with the while statemetns int x2 = 0; int y1 = 0;