• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Graphics and animation in Java

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

If anyone can, please give me a way to get some resources(tutorials & examples) related to Graphics2D,Grphics3D and animation stuff in Java.

I've found various materials by searching in the net. But couln't get a nice tutorial with examples.

Thanks in advance,
Mani
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you been through the Java Tutorials? You will find 2D there, but I don't think animation.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trail: 2D Graphics
You'll find an animation under the second paragraph on How to Make Applets followed by a link to the source code.
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about hardware acceleration? I've heard that you can only do it using a Canvas because of the createBufferStrategy() method in combination with the GraphicsConfiguration class, but can you do it using Swing components? I've read some about Volatile images, but do not know much about some of the fundamental concepts (i.e. if I just draw to a BufferedImage and then have the JPanel graphic draw that image, is that the same thing, or do I have to allocate the memory in the accelerated graphics memory? Whats the difference?). Sorry for kind of commandeering this thread, but it seems in line with the topic.

Andy
 
Andy Selador
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured it out:

GraphicsConfiguration configuration = GraphicsEnvironment.
getLocalGraphicsEnvironment().
getDefaultScreenDevice().
getDefaultConfiguration();

Then, when you want to draw the image:

VolatileImage image = configuration.
createCompatibleVolatileImage(getWidth(), getHeight());
/* assuming you are extending the component */

Check the VolatileImage API for information on checking if the image is available to be drawn on, and make sure to flush the image if you create a new one assigned to the reference to save resources.

This reply is kind of crap in its explanation, but the JavaDocs for the VolatileImage class and createCompatibleVolatileImage method are good.

(The whole reason to use hardware acceleration is to bypass the CPU, as best as I can tell.)

As for how to handle the buffer strategy with Swing components, and if you even need to...
I have no clue.

Andy
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic