Java-Gaming.org    
Featured games (78)
games approved by the League of Dukes
Games in Showcase (426)
Games in Android Showcase (89)
games submitted by our members
Games in WIP (466)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  2D Rendering  (Read 1387 times)
0 Members and 1 Guest are viewing this topic.
Offline kitfox

Junior Member




Java games rock!


« Posted 2005-11-14 20:14:18 »

I'm trying to figure out the best way to incorporate a 2D HUD into my OpenGL application.

I've considered using a JPanel and drawing my 2D the Swing way, but I found some drawbacks
-The current JPanel is really slow.  While one of my demos flies at 900 FPS with a GLCanvas, a JPanel sinks it to 50 FPS (and even then, I suspect it's lower becasue the animation is choppy)
-While JPanel is much faster in Mustang, Mustang's still more than eight months from release.
- Even in Mustang, the Vertex Buffer Object is really slow.  The demo also has problems, with windows sometimes vanishing or terminating abruptly.

My next best idea so far is to create a large texture on the GPU, draw my HUD into a BufferedImage and use glTexSubimage2D() to upload it whenever my HUD changes. 

Or would it be best to keep my image on the client side and use glDrawPixels() to draw my image each pass?

I will potentially have a 1600x1200 screen size, and would appreciate hearing what worked for other folks with HUD creation.
Offline Niwak

Senior Member


Medals: 1
Projects: 1



« Reply #1 - Posted 2005-11-14 21:30:23 »

I've come across the same choice lately. It appeared that (as always) there is no definitive answer to this.
- Using Swing is a quick but a bit ineffective way of doing the job (for the moment). Perhaps Mustang will solve this (albeit only with the Sun JVM ?). I used the bridge existing in Xith3D it gives you a good example of how to do this (It is a bit buggy with the event processing).
- Using a texture for the complete screen was not adapted for my system (too high video memory & fill rate consumption) but I can imagine that some UI would benefit for it (when they cover most of the screen). I did not try this.
- Using a texture per top level widget seems to be a good trade-off since it allows you to only update the modified part of the texture and not send the whole widget like you would with glDrawPixel.
- For some widgets it happens to be usefull to be allowed to provide free geometry (example : in the player selection buttons of my game, you have an animated model of the selected character).

In my system, I end up using the main engine scenegraph for the UI part ;
- A top-level shell is in charge of managing the dispatch of events to top-level widgets as well as managing the laying-out updates,
- By default, each widget adds up and manages the geometry it wants to the top-level shell,
- Special top-level window allows for texture cached widgets (planned in the design but not yet implemented),
- The z components of the geometry define the z-ordering of the widgets.
- The UI is rendered in its own pass after clearing the depth buffer.
This allows the UI to use all the feature of the graphic engine (like animated models, correctly sorted blending,...).

This design looked to me like a good compromise between the performance cost and the design flexibility.
I think that you can come with lots of clean other solution for this.

For another solution, you may want to have a look to http://www.cegui.org.uk/ which has proven to work for a few projects.

             Vincent
Offline tom
« Reply #2 - Posted 2005-11-15 00:43:09 »

The most efficient way is ofcourse to ditch software rendering and use opengl instead. I admit it is not easy, and it limits what you can do. Still I think it is the way most real games does it.

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ajmas

Junior Member




Miles away from here!


« Reply #3 - Posted 2005-11-15 01:25:42 »

I haven't tried doing this before either, but I wonder whether you could draw your hud as opengl objects prior to drawing anything else. That way you can draw the without any transformations effecting them. Then you can do any other trick that you would expect of an OpenGL 'object'. The thing which might cause a problem is the interaction with the lighting model. I'll have to give it a go. As with the previous posters, I would be curious as to what a seasoned developer would suggest.

I will see if gamedev.net suggests anything.
Offline ryanm

Senior Member


Projects: 1


Used to be bleb


« Reply #4 - Posted 2005-11-15 04:33:57 »

I haven't tried doing this before either, but I wonder whether you could draw your hud as opengl objects prior to drawing anything else. That way you can draw the without any transformations effecting them. Then you can do any other trick that you would expect of an OpenGL 'object'. The thing which might cause a problem is the interaction with the lighting model. I'll have to give it a go. As with the previous posters, I would be curious as to what a seasoned developer would suggest.

I will see if gamedev.net suggests anything.


I would suggest drawing your gui overlay after the rest of your scene. The sequence of operations might go something like:

1) draw scene
2) Set projection matrix to orthographic
3) Clear depth buffer
4) Disable lighting
4) Draw GUI elements

As to prior transformations affecting your GUI, surely all that is needed is some pushMatrix()/popMatrix() activity?

However, I'm about as green an OpenGL developer as you'll find, so this is probably all rubbish.  Sad
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

xsi3rr4x (73 views)
2014-04-15 18:08:23

BurntPizza (68 views)
2014-04-15 03:46:01

UprightPath (80 views)
2014-04-14 17:39:50

UprightPath (65 views)
2014-04-14 17:35:47

Porlus (81 views)
2014-04-14 15:48:38

tom_mai78101 (105 views)
2014-04-10 04:04:31

BurntPizza (164 views)
2014-04-08 23:06:04

tom_mai78101 (260 views)
2014-04-05 13:34:39

trollwarrior1 (210 views)
2014-04-04 12:06:45

CJLetsGame (220 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!