Sign in to follow this  

[java] [JOGL] Is it a way to NOT use GLEventListener ?

This topic is 3777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to do a simple game using JOGL but I can't find a way to do it without implementing GLEventListener. It's not like I don't want to do it, but how can I be sure that the GLEventListener.init (GLDrawable) is called before any update of the game. Here a sample of my game loop:
Frame mainFrame = new Frame ();
CGameEngine game = new CGameEngine ("testGame");
game.Init (mainFrame);    // I would like to do any JOGL init here
while (true)
{
    game.Update ();
    game.Render ();    // I would like to do every OGL call here
}

I tried to call init myself but every members of GL is null when I do that. Here the code that doesn't work:
GLCanvas canvas = new GLCanvas ();
GL device = canvas.getGL ();
System.err.println (device.glGetString(GL.GL_VERSION));    // Output null

If anyone can help me, your help will be really appreciate. [smile]

Share this post


Link to post
Share on other sites
I don't think so.

But that doesn't change anything. Your code simply becomes:

class Game implements GLEventListener {

public void setUpGame()
{
// initialize the game related stuff
}

public void update()
{
// do game stuff
}

public void render()
{
canvas.update();
}
private GLCanvas canvas;
}

Game game = ... // make game
game.setUpGame();
while (true) {
game.update();
game.render();
}





And you implement your rendering in appropriate GLEventListener.

Quote:
It's not like I don't want to do it, but how can I be sure that the GLEventListener.init (GLDrawable) is called before any update of the game.


You can't. That's the whole point of listener interface. It gets called when needed. Same for redrawing. That's how event driven approach works.

Share this post


Link to post
Share on other sites

This topic is 3777 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this