[JAVA2D] line2D length problem

2008-08-05 Thread java2d
Hi All,
  
  Hoping someone can help me with this one ...?
  
  I need to draw lines with a width greater than 1 and the lengths may be a 
real value so I am using 
  Line2D.Float.
  
  I need to draw exact (calculated)lengths so I am using CAP_BUTT so the line 
does not have any additional 
  apparent length (the other CAP options have the effect of adding the line 
width to the line)
  
  The problem I am having is that once the line width is set to greater than 1, 
the lines are actually drawn 1 pixel short.
  I am sure I am missing soething simple here but have spent a lot of time on 
it!
  I know that I can work around it but do I need to, I shouldn't have to + 1 to 
my line lengths depending on there width?
  
  The following demonstrates the problem. I am drawing on a JPanel within a 
JFrame,  JDK/JRE 6, Windows

  g2.setStroke(new BasicStroke(1,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
  g2.setColor(Color.BLACK);
  g2.draw(new Line2D.Float(20,40,20,75));   // vertical line as marker only
   

// draw 2 lines with line width of 1
g2.setColor(Color.RED);
g2.draw(new Line2D.Float(20,60,21,60));  // draws 2 pixel line as 
expected
g2.draw(new Line2D.Float(22,60,23,60));  // draws 2 pixel line as 
expected ... total of 4 pixels 


// draw 2 lines with line width of 10
g2.setStroke(new 
BasicStroke(10,BasicStroke.CAP_BUTT,BasicStroke.JOIN_BEVEL));
g2.setColor(Color.GREEN);
g2.draw(new Line2D.Float(20,70,21,70));  // draws 1 pixel only at 20,70
g2.setColor(Color.YELLOW);
g2.draw(new Line2D.Float(22,70,23,70));  // draws 1 pixel only at 
22,70... so, each line is shortened by 1 pixel


// this applies to any line width > 1









Thanks
Lew
[Message sent by forum member 'aussielew' (aussielew)]

http://forums.java.net/jive/thread.jspa?messageID=291753

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread java2d
Okay, when I decide to use "active rendering" in windowed mode, do I get 
hardware acceleration as well? I just surfed a little bit through the net 
regarding this topic and read here 
http://www.gamedev.net/reference/programming/features/javarender/page2.asp , 
that this attempt uses blitting in windowed mode. That is exactly what I wanted 
to avoid because in the beginning of my coding, I used BufferedImages and got 
100% CPU usage because the transfering of the image from main memory to the 
graphics card (-> the blitting) was so cost expensive.

Maybe i didn't get this issue right here, because after all that what I already 
tried and all the different possibilities, I am very confused . .. . 

If I would be in fullscreen mode and could use page flipping, that would be an 
alternative if not my accelerated memory on my graphics card would be so 
limited (-> 64MB). Page flipping would mean, that I have to allocate twice the 
size of my image in memory, right? You have to remember, that there are some 
more backbuffers for our old images that have to be stored in that memory, too. 
After exprimentationing and testing the whole day, today, I got to the point 
that my biggest problem is exactly this limited VRAM memory . . . . . 
Especially because it is very frustrating, that the memory is lockked a long 
time after an image had been disposed (I hoped that VolatileImage.flush() would 
have helped that problem, but it does not really . . .).
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291707

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread Ken Warner

That's the way I do things.  I do active rendering using BufferStrategy.

I turn off repaint() setIgnoreRepaint(true) while I'm active rendering and
then when I'm not active rendering and the applet is just sitting there,
I turn on repaint() with setIgnoreRepaint(false) so that if the applet
gets covered and then re-exposed, it repaints on the screen properly.

My paint() method looks a lot like my active rendering method with slight
differences in the implementation.

I think that way of drawing on the screen is great especially if you
need a high frame rate.  Depending on the size of the screen area
rendered to, I can get a frame in less than 100 milliseconds on
my old, slow computer.

The tricky part is trying to get the "look and feel" of the applet
to be constant on computers with much faster graphics and processors.

I try to adjust the amount of drawing by calculating the average number
of frames per second and then adjusting the "movement" of the image.

Lot's of fussy details...

Dmitri Trembovetski wrote:

  You can certainly use repaint() with VolatileImages as back buffers.

  The alternative approach is called "active rendering", where you
  control when stuff gets rendered.

  Take a look at this:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/rendering.html

  While this is a "full screen" tutorial, the same applies for rendering
  in windowed mode.

  Also, I reiterate, it is better to use active rendering and 
BufferStrategy

  for double buffering, especially if your application is 'game-like'.

  Thanks,
Dmitri


[EMAIL PROTECTED] wrote:


Hi Ken,


With VolitileImages, you should render directly from
your program by calling your own render method directly.
Don't call repaint().



I do use my own render method, but that method only renders on my 
background volatile image. After that is finished I somehow have to 
get my image onto the screen (or to be more precise on my panel). 
Then, I assume, I have to call repaint() (of the panel) out of my own 
render method, don't I?


Maik
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291577

=== 

To unsubscribe, send email to [EMAIL PROTECTED] and include in the 
body
of the message "signoff JAVA2D-INTEREST".  For general help, send 
email to

[EMAIL PROTECTED] and include in the body of the message "help".



===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".



===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread Dmitri Trembovetski

  You can certainly use repaint() with VolatileImages as back buffers.

  The alternative approach is called "active rendering", where you
  control when stuff gets rendered.

  Take a look at this:
http://java.sun.com/docs/books/tutorial/extra/fullscreen/rendering.html

  While this is a "full screen" tutorial, the same applies for rendering
  in windowed mode.

  Also, I reiterate, it is better to use active rendering and BufferStrategy
  for double buffering, especially if your application is 'game-like'.

  Thanks,
Dmitri


[EMAIL PROTECTED] wrote:

Hi Ken,


With VolitileImages, you should render directly from
your program by calling your own render method directly.
Don't call repaint().


I do use my own render method, but that method only renders on my background 
volatile image. After that is finished I somehow have to get my image onto the 
screen (or to be more precise on my panel). Then, I assume, I have to call 
repaint() (of the panel) out of my own render method, don't I?

Maik
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291577

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread java2d
Hi Ken,

>With VolitileImages, you should render directly from
>your program by calling your own render method directly.
>Don't call repaint().

I do use my own render method, but that method only renders on my background 
volatile image. After that is finished I somehow have to get my image onto the 
screen (or to be more precise on my panel). Then, I assume, I have to call 
repaint() (of the panel) out of my own render method, don't I?

Maik
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291577

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread Ken Warner

If you call repaint() you invoke the AWT thread and paint()
is called by the AWT thread.  update() and paint() should
not be called directly by your program they are generally
called from the AWT thread in response to some sort of
system event like Expose or Move etc.

With VolitileImages, you should render directly from
your program by calling your own render method directly.
Don't call repaint().

Dmitri, did I get that right?

[EMAIL PROTECTED] wrote:

Hi Ken,

I'm just at work and see that I call it indirectly through repaint().

To be honest, it confuses me a bit that there are the methods repaint(), 
paint(Grphics g) and even update(Graphics g). I'm sure that I read about the 
differences and when I have to use one or the other at the time I was first 
creating my panel, but now, I just don't know anymore the differences and 
meanings of them . . . .

Maik
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291504

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".



===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".


Re: [JAVA2D] VolatileImage.validate() does not (always) work

2008-08-05 Thread java2d
Hi Ken,

I'm just at work and see that I call it indirectly through repaint().

To be honest, it confuses me a bit that there are the methods repaint(), 
paint(Grphics g) and even update(Graphics g). I'm sure that I read about the 
differences and when I have to use one or the other at the time I was first 
creating my panel, but now, I just don't know anymore the differences and 
meanings of them . . . .

Maik
[Message sent by forum member 'kiamur' (kiamur)]

http://forums.java.net/jive/thread.jspa?messageID=291504

===
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST".  For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".