Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (784)
Games in Android Showcase (234)
games submitted by our members
Games in WIP (858)
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  
  Why require context?  (Read 1857 times)
0 Members and 1 Guest are viewing this topic.
Offline dolachin

Senior Newbie

Java games rock!

« Posted 2003-09-04 16:11:38 »


My life has taken me from OpenGL to Java3D and now to Jogl. And I have this question.

The way I've been organizing my code is by letting each object build itself and then sticking it into varous contexts. But with Jogl this seems not possible since any routine that does the building needs to have an instance of the GL class. This causes a couple "problems".

1. I need to build each object several times depending on the context.
2. I can't hide implementation (that fact that I'm using Jogl) since all of my routines have GLDrawable as an argument, and I have always been taught to separate logic from implementation.

Any thoughts?

Offline Orangy Tang

JGO Kernel

Medals: 57
Projects: 11

Monkey for a head

« Reply #1 - Posted 2003-09-04 19:10:07 »

This is always a tricky one, and i've been tinkering with various methods for a while now. You're trying to decouple your rendering and game logic, yes?

First off, the standard method nicked from normal J2D rendering is some kind of .paint(Graphics) method, which works nice since you can wrap up animation etc. in its own class and just have it display its current frame in the paint method. While this is slightly possible in a OpenGL driven game, its not even close to efficiant, and as soon as you start on anything more complicated you end up tearing your hair out with GL state problems..

You end up having to take your abstraction to a higher level - instead of your player/enemy/whatever game objects having a draw method, let these hold on to some kind of Sprite or Mesh class (with whatever material/texture/shader set of state that you need). Then these Mesh objects are held by some kind of renderer object which is in charge of drawing them all. Add some sort of camera object and you've got everything you need to draw a frame.

If you look at that again, you'll realise that you've effectivly created your own simple scene graph - a scene consisting of Meshes and Materials, in some sort of collection along with the camera. Your renderer deals with the low level details of turning this abstract representation into an actual image on screen.

This leaves your renderer is free to do all the funky stuff it needs like state sorting on Materials, view culling, building geometry lists from Mesh objects etc. and the rest of your app just has to poke objects into a scene graph and not have to worry about it Grin

Hope that gives you some ideas at least Smiley

[ - Play Growth Spurt, Rescue Squad and Snowman Village ] [ Rebirth - game resource library ]
Offline dolachin

Senior Newbie

Java games rock!

« Reply #2 - Posted 2003-09-05 18:22:43 »

Thank you very much for the reply. WHat you are saying makes sense.

But is my conclusion correct that if I want to have, say,  two views of the same object, I will need two display lists?

Thanks again,

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

Senior Newbie

« Reply #3 - Posted 2003-09-06 06:45:48 »

JoGL now implements shared display lists between GLContexts so you don't need to create 2 lists for the same object if you run 2 GLContexts.
This is a recent feature and you need to get the latest official binary release (september 5) for it.
However, I think you'll still have to set perspective and lighting independantly for each GLContext.
Pages: [1]
  ignore  |  Print  

hadezbladez (1627 views)
2018-11-16 13:46:03

hadezbladez (642 views)
2018-11-16 13:41:33

hadezbladez (1626 views)
2018-11-16 13:35:35

hadezbladez (332 views)
2018-11-16 13:32:03

EgonOlsen (2678 views)
2018-06-10 19:43:48

EgonOlsen (2943 views)
2018-06-10 19:43:44

EgonOlsen (1641 views)
2018-06-10 19:43:20

DesertCoockie (2351 views)
2018-05-13 18:23:11

nelsongames (2255 views)
2018-04-24 18:15:36

nelsongames (2950 views)
2018-04-24 18:14:32
Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20 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‑
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!