Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:58:23+00:00 2026-06-04T09:58:23+00:00

I’ve just written a simple animation in JOGL : a 6-colored cube spins around

  • 0

I’ve just written a simple animation in JOGL : a 6-colored cube spins around y axis. But it seems my animation has a little speed workaround : sometimes it accelerate, and sometimes it slows though i just call glRotate() with a float variable that I increment on each display call (my code is below).

  • My processor is a pentium dual core t3400
  • My operating system is Xubuntu 11.04 32 bits
  • My graphic card is ATI Radeon HD4330 and i’ve installed a recent proprietary driver : 11.6 (downloaded on AMD website, not on ubuntu software manager)

In Eclipse EDI (I’m using Indigo 3.7.0), this is how i’ve set my user library :

  • I’ve downloaded the JOGL 2.0 beta 23 (from 2011, march 03) for i586 linux
  • In the user library I imported the following jars : newt.all.jar, nativewindow.all.jar, jogl.all.jar, gluegen-rt.jar
  • All of the imported jars link to the lib subfolder of uncompressed jogl archive : where are all the *.so files

Here my three classes.

ArcballExperiment.java

package com.gmail.bernabe.laurent.jogl.arcball_experiment;

import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.media.opengl.awt.GLCanvas;
import javax.swing.JFrame;

import com.jogamp.opengl.util.Animator;

public class ArcBallExperiment extends JFrame {

    public ArcBallExperiment(){
        setTitle("ArcBall Experimentation");
        setSize(500, 500);
        setLocationRelativeTo(null);

        GLCanvas glCanvas = new GLCanvas();
        TheGLEventListener glEventListener = new TheGLEventListener();
        glCanvas.addGLEventListener(glEventListener);
        add(glCanvas);

        final Animator animator = new Animator(glCanvas);
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                animator.stop();
                System.exit(0);
            }


        });

        animator.start();
    }

    public static void main(String[] args) {
        new ArcBallExperiment().setVisible(true);
    }

    private static final long serialVersionUID = 1L;

}

Cube.java :

package com.gmail.bernabe.laurent.jogl.arcball_experiment;

import javax.media.opengl.GL2;

public class Cube {

    /**
     * Draws a cube in a GL2 context
     * @param gl - GL2 - GL2 context
     */
    public static void draw(GL2 gl){
        gl.glBegin(GL2.GL_QUADS);

            // front : blue
            gl.glColor3f(0.0f, 0.0f, 1.0f);
            gl.glVertex3f(-0.5f, +0.5f, +0.5f);
            gl.glVertex3f(-0.5f, -0.5f, +0.5f);
            gl.glVertex3f(+0.5f, -0.5f, +0.5f);
            gl.glVertex3f(+0.5f, +0.5f, +0.5f);

            // back : green
            gl.glColor3f(0.0f, 1.0f, 0.0f);
            gl.glVertex3f(+0.5f, -0.5f, -0.5f);
            gl.glVertex3f(+0.5f, +0.5f, -0.5f);
            gl.glVertex3f(-0.5f, +0.5f, -0.5f);
            gl.glVertex3f(-0.5f, -0.5f, -0.5f);

            // left : red
            gl.glColor3f(1.0f, 0.0f, 0.0f);
            gl.glVertex3f(-0.5f, +0.5f, +0.5f);
            gl.glVertex3f(-0.5f, +0.5f, -0.5f);
            gl.glVertex3f(-0.5f, -0.5f, -0.5f);
            gl.glVertex3f(-0.5f, -0.5f, +0.5f);

            // right : orange
            gl.glColor3f(1.0f, 0.4f, 0.0f);
            gl.glVertex3f(+0.5f, +0.5f, -0.5f);
            gl.glVertex3f(+0.5f, +0.5f, +0.5f);
            gl.glVertex3f(+0.5f, -0.5f, +0.5f);
            gl.glVertex3f(+0.5f, -0.5f, -0.5f);

            // top : white
            gl.glColor3f(1.0f, 1.0f, 1.0f);
            gl.glVertex3f(+0.5f, +0.5f, +0.5f);
            gl.glVertex3f(-0.5f, +0.5f, +0.5f);
            gl.glVertex3f(-0.5f, +0.5f, -0.5f);
            gl.glVertex3f(+0.5f, +0.5f, -0.5f);

            // bottom : yellow
            gl.glColor3f(1.0f, 1.0f, 0.0f);
            gl.glVertex3f(+0.5f, -0.5f, +0.5f);
            gl.glVertex3f(+0.5f, -0.5f, -0.5f);
            gl.glVertex3f(-0.5f, -0.5f, -0.5f);
            gl.glVertex3f(-0.5f, -0.5f, +0.5f);

        gl.glEnd();
    }

}

TheGLEventListener.java :

package com.gmail.bernabe.laurent.jogl.arcball_experiment;

import javax.media.opengl.GL2;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import javax.media.opengl.glu.gl2.GLUgl2;

public class TheGLEventListener implements GLEventListener {

    @Override
    public void display(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();

        glu.gluLookAt(
                0f, 0f, 3f,
                0f, 0f, 0f,
                0f, 1f, 0f
        );

        gl.glRotatef(rotationAngle, 0f, 1f, 0f);
        Cube.draw(gl);

        rotationAngle += 0.3f;
        if (rotationAngle >= 360f)
            rotationAngle %= 360f;
    }

    @Override
    public void dispose(GLAutoDrawable drawable) {
        // TODO Auto-generated method stub

    }

    @Override
    public void init(GLAutoDrawable drawable) {
        GL2 gl = drawable.getGL().getGL2();
        gl.glEnable(GL2.GL_DEPTH_TEST);
        gl.glDepthFunc(GL2.GL_LEQUAL);
        gl.glClearDepthf(1.0f);
    }

    @Override
    public void reshape(GLAutoDrawable drawable, int x, int y, int width,
            int height) {
        GL2 gl = drawable.getGL().getGL2();
        gl.glViewport(x, y, width, height);

        gl.glMatrixMode(GL2.GL_PROJECTION);
        gl.glLoadIdentity();
        glu.gluPerspective(60.0f, (float) width/height, 1f, 10f);

        gl.glMatrixMode(GL2.GL_MODELVIEW);
    }

    private GLUgl2 glu = new GLUgl2();
    private float rotationAngle = 0f;

}

I’m thinking it could be because I imported incompatible jars in the user library made for my JOGL eclipse projects, but I’m not sure.

Thanks in advance

(The title ArcBall experiment seems inapropriated, and it’s right : this cube spinning is juste a phase for me to remember again the JOGL programming before going to arcball implementation.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:58:24+00:00Added an answer on June 4, 2026 at 9:58 am

    Finally I solved the problem 🙂
    I changed the animator instance to FPSAnimator instead of Animator, in order to keep a constant FPS. There is just one class to update :
    ArcBallExperiment.java

    package com.gmail.bernabe.laurent.jogl.arcball_experiment;
    
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    
    import javax.media.opengl.awt.GLCanvas;
    import javax.swing.JFrame;
    
    import com.jogamp.opengl.util.FPSAnimator;
    
    public class ArcBallExperiment extends JFrame {
    
        public ArcBallExperiment(){
            setTitle("ArcBall Experimentation");
            setSize(500, 500);
            setLocationRelativeTo(null);
    
            GLCanvas glCanvas = new GLCanvas();
            TheGLEventListener glEventListener = new TheGLEventListener();
            glCanvas.addGLEventListener(glEventListener);
            add(glCanvas);
    
            /*
             *  Here I limit the FPS to a quite lower value than default,
             *  thanks to the FPSAnimator class : 180 FPS here.
             *  That way, cube rotation speed will really be constant
             */
            final FPSAnimator animator = new FPSAnimator(glCanvas, 180);
            addWindowListener(new WindowAdapter() {
    
                @Override
                public void windowClosing(WindowEvent e) {
                    animator.stop();
                    System.exit(0);
                }
    
    
            });
    
            animator.start();
        }
    
        public static void main(String[] args) {
            new ArcBallExperiment().setVisible(true);
        }
    
        private static final long serialVersionUID = 1L;
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.