Results 1 to 4 of 4

Thread: GL4Java

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2003
    Location
    Greenbelt, MD US
    Posts
    1

    GL4Java

    Is anyone familiar with GL4Java? If so I have a problem I could really use some assistance with. I'm trying to do something as basic as rendering a polygon, however, when I run I am unable to see object just black background. Also I have a menu bar (through SWING) at the top of the frame and it click on certains items the list is hidden behind the black canvas. Can anyone assist. Below is my code for the polygon


    import gl4java.GLContext;
    import gl4java.awt.GLAnimCanvas;

    public class gci_glcode extends GLAnimCanvas {



    public gci_glcode(int w, int h) {
    super(w,h);
    }
    public void preInit()
    {
    doubleBuffer = true;
    stereoView = false; // buffering but not stereoview
    }

    public void init(){
    float width = (float)getSize().width;
    float height = (float)getSize().height;

    gl.glShadeModel(GL_SMOOTH); gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); //This Will Clear The Background Color To Black
    gl.glClearDepth(1.0); //Enables Clearing Of The Depth Buffer
    gl.glEnable(GL_DEPTH_TEST); //Enables Depth Testing
    gl.glDepthFunc(GL_LEQUAL); //The Type Of Depth Test To Do
    gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective

    /*qobj = (int)glu.gluNewQuadric();
    glu.gluQuadricNormals(qobj, GLU_SMOOTH); // Create Smooth Normals ( NEW )
    glu.gluQuadricTexture(qobj, GL_TRUE);*/
    }
    public void doCleanup(){
    stop();
    }

    public void reshape(int width, int height){
    //Reset The Current Viewport And Perspective Transformation

    System.out.println("Width : "+width+" Height: "+height);
    if(height==0)height=1;
    gl.glViewport(0, 0, width, height); // Reset The Current Viewport And Perspective Transformation
    gl.glMatrixMode(GL_PROJECTION); // Select The Projection Matrix
    gl.glLoadIdentity(); // Reset The Projection Matrix
    glu.gluPerspective(45.0f, width / height, 0.1f, 100.0f); // Calculate The Aspect Ratio Of The Window
    gl.glMatrixMode(GL_MODELVIEW); // Select The Modelview Matrix
    gl.glLoadIdentity(); // Reset The ModalView Matrix


    }


    public void display(){
    /*if(!cvsIsInit() | | !glj.gljMakeCurrent())
    {
    System.out.println("The program is broken; didn't initialize");
    }*/
    if(glj.gljMakeCurrent()== false) return;
    gl.glMatrixMode(GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT );

    /*gl.glPushMatrix();
    gl.glTranslated(-100,0,0);
    glu.gluSphere(qobj, 20,20,20);
    gl.glPopMatrix();

    gl.glFlush();*/

    gl.glClearColor(0.0f,0.0f,0.0f,0.0f);
    gl.glClear(GL_COLOR_BUFFER_BIT);
    gl.glColor3f(1.0f,1.0f,1.0f);
    gl.glOrtho(0.0,1.0,0.0,1.0,-1.0,1.0);
    gl.glBegin(GL_POLYGON);
    gl.glVertex3f(-1.0f,1.0f,0.0f);
    gl.glVertex3f(1.0f,1.0f,0.0f);
    gl.glVertex3f(1.0f,-1.0f,0.0f);
    gl.glVertex3f(-1.0f,-1.0f,0.0f);
    gl.glEnd();
    gl.glFlush();

    glj.gljSwap(); //Swap buffers
    glj.gljFree(); // release GL
    }
    }

  2. #2
    Senior Member Regular Contributor
    Join Date
    Feb 2003
    Location
    Westerville, Oh, USA
    Posts
    201

    Re: GL4Java

    Chapter 3 of the Red Book has a section called "Troubleshooting Transformations" that lists a lot of reasons why you're screen may be blank.
    http://fly.cc.fer.hr/~unreal/theredbook/chapter03.html

    After a quick glance at your code, do you really want to be translating 100 units down negative X? The default "camera" is situated at the origin pointing down the negative Z axis.

  3. #3
    Member Newbie
    Join Date
    Aug 2002
    Location
    London, England
    Posts
    34

    Re: GL4Java

    The reason why some of your menu bars appear to be below the gl4java canvas is due to your mixing of lightweight and heavyweight components.

    The hardware acceleration path brings with it its own problems though, mainly centred around the mixing of lightweight and heavyweight components. A heavyweight component is one that is based on the older abstract windowing toolkit (AWT) java classes and a lightweight is one that is based upon the newer swing classes. AWT based components are not 100% java based, using an underlay of C/C++ code that is dependable on the operating system. This means that the same application may look totally different on different operating systems. AWT based components also have their own z-ordering scheme whereas swing does not, we will see why this is important in a moment.

    Swing on the other hand is more or less 100% java based, this means that an application developed using swing classes will look the same no matter what operating system it is running on. Whereas AWT components are drawn using peer counterparts from the operating system, swing components are just drawn/painted to blank windows. As mentioned before, swing does not have any z-ordering scheme, which means that an AWT component will ALWAYS be drawn on top of it. This was the main problem that we encountered when we mixed the heavyweight OpenGL component with the lightweight container and information components.

    The solution to this problem was to develop a lightweight version of the OpenGL accelerated panel. The panel would have to be reworked from scratch to make use of the lightweight swing classes. During the development of the new OpenGL panel, further major bugs were encountered. The frame rate of the panel had decreased to a tenth of what is used to be when using the AWT classes. This resultant frame rate was unacceptable, and after spending a great deal of time debugging the problem we finally got the frame rate back up to somewhere near what it used to be.

  4. #4
    Guest

    Re: GL4Java

    "A heavyweight component is one that is based on the older abstract windowing toolkit (AWT) java classes and a lightweight is one that is based upon the newer swing classes."
    No true. A heavyweight control is one that has its own native peer, and such relies upon the underlying OS for its display. A lightweight control is drawn an managed by java code. While AWT is made of heavyweight controls, not all of Swing is lightweight (such as JFrame) and some are able to operate in both methods (menu popups for example).

    "swing does not have any z-ordering scheme"
    No, Swing has it's own ordering system, but AWT controls - being native controls - will not respect this ordering.

    j3d.org has a good article on mixing a heavyweight canvas (a J3d one or GL4Java one) with lightweight controls.

Similar Threads

  1. GL4Java in a JFrame
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 01-12-2004, 05:35 AM
  2. gl4java help
    By JanHH in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-22-2003, 07:51 PM
  3. alternative to gl4java
    By in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 05-09-2003, 08:50 PM
  4. gl4java
    By in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 05-20-2001, 10:54 AM
  5. Can you try this gl4java applet ?
    By aetius in forum OpenGL: Advanced Coding
    Replies: 3
    Last Post: 05-05-2000, 01:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean