Author Topic: 2D foreground in hardware rendering mode  (Read 4760 times)

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
2D foreground in hardware rendering mode
« on: December 15, 2008, 01:15:02 am »
Here's another question that's probably been asked a hundred times:

Is there a way to get a Graphics context to draw on when using hardware rendering mode?  I can't use getGraphics() since, as the Javadoc states, "when using OpenGL support, this value is rather meaningless".

I suppose I could draw my layer onto an Image, and use that to create a Texture to use in the blit() method.  I'd have to rethink how I handle images that change dynamically (since I wouldn't want to create a new texture every frame).  Also, is a texture's alpha information taken into account by blit()?  If not, is there another way to draw simi-transparent 2D stuff on top of the rendered scene?

--EDIT-- I see that one of the blit() methods has the ability to set an additional color.  I'll play around with this to see if I can get the results I'm looking for.
« Last Edit: December 15, 2008, 01:20:44 am by paulscode »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D foreground in hardware rendering mode
« Reply #1 on: December 15, 2008, 12:41:26 pm »
Using a graphics context doesn't work, blitting is the way to go. Either that or use the Overlay from the util-package, which is similar to blitting but not exactly the same.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 2D foreground in hardware rendering mode
« Reply #2 on: December 15, 2008, 01:34:15 pm »
Thanks!  I hadn't noticed the Overlay class ( I should really spend more time reading the Javadoc  ;) )  That will definitely be useful for my 2D images that are more or less permanant, like borders or the outline for a life-meter, etc, and the blit() method looks best for dynamicaly changing foreground stuff like menus and highlighting.

Do both of these take a Texture's alpha information into account when drawing on top of the scene?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: 2D foreground in hardware rendering mode
« Reply #3 on: December 15, 2008, 07:59:05 pm »
Yes, both support alpha when using the hardware renderer. When using the software renderer, only the overlay will.

Offline paulscode

  • double
  • *****
  • Posts: 863
    • View Profile
    • PaulsCode.Com
Re: 2D foreground in hardware rendering mode
« Reply #4 on: December 15, 2008, 09:04:56 pm »
Cool.  I'll probably stick with the Overlay class then.  I noticed it has a setVisibility() method, so as long as I break my dynamically changing images down into small enough components, this class should be able to handle everything, without having to constantly dispose() and create new Overlay instances.  That way I won't have to write different code between software or hardware renderers.

Thanks for the info!