Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (476)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  A problem I meet when using JOGL  (Read 1508 times)
0 Members and 1 Guest are viewing this topic.
Offline lzpolestar

Junior Newbie





« Posted 2012-03-13 15:38:19 »

This is a NEHE lesson written in JOGL(which is a little outdated,written in 2003),I change some wrong  method invoke because  class or interface has change the method in it.
But when I run the code .The form only flash one time and then only show the backcolor.I don't know why and how to correct it.
Help ME! Sad
THANK YOU!
below are the code.

import java.awt.*;
import java.awt.event.*;

import javax.media.opengl.*;
import javax.media.opengl.glu.GLU;

/** Port of the NeHe OpenGL Tutorial (Lesson 2)
 * to Java using the Jogl interface to OpenGL.  Jogl can be obtained
 * at http://jogl.dev.java.net/
 *
 * @author Kevin Duling (jattier@hotmail.com)
 */
public class Lesson02
{
  static class Renderer
    implements GLEventListener,
               KeyListener
  { 
    /** Called when the display mode has been changed.  <B>!! CURRENTLY UNIMPLEMENTED IN JOGL !!</B>
    * @param gLDrawable The GLDrawable object.
    * @param modeChanged Indicates if the video mode has changed.
    * @param deviceChanged Indicates if the video device has changed.
    */
    public void displayChanged(GLDrawable gLDrawable, boolean modeChanged, boolean deviceChanged)
    {
    }   
      

    /** Invoked when a key has been pressed.
     * See the class description for {@link KeyEvent} for a definition of
     * a key pressed event.
     * @param e The KeyEvent.
     */
    public void keyPressed(KeyEvent e)
    {
      if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
        System.exit(0);
    }
   
    /** Invoked when a key has been released.
     * See the class description for {@link KeyEvent} for a definition of
     * a key released event.
     * @param e The KeyEvent.
     */
    public void keyReleased(KeyEvent e) {}
   
    /** Invoked when a key has been typed.
     * See the class description for {@link KeyEvent} for a definition of
     * a key typed event.
     * @param e The KeyEvent.
     */
    public void keyTyped(KeyEvent e) {}


   @Override
     /** Called by the drawable to initiate OpenGL rendering by the client.
     * After all GLEventListeners have been notified of a display event, the
     * drawable will swap its buffers if necessary.
     * @param gLDrawable The GLDrawable object.
     */
   public void display(GLAutoDrawable glDrawable) {
      // TODO Auto-generated method stub
      final GL gl = glDrawable.getGL();
         gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
         gl.glLoadIdentity();
         gl.glTranslatef(-1.5f, 0.0f, -6.0f);
         gl.glBegin(GL.GL_TRIANGLES);      // Drawing Using Triangles
           gl.glVertex3f( 0.0f, 1.0f, 0.0f);   // Top
           gl.glVertex3f(-1.0f,-1.0f, 0.0f);   // Bottom Left
           gl.glVertex3f( 1.0f,-1.0f, 0.0f);   // Bottom Right
         gl.glEnd();            // Finished Drawing The Triangle
         gl.glTranslatef(3.0f, 0.0f, 0.0f);
         gl.glBegin(GL.GL_QUADS);              // Draw A Quad
           gl.glVertex3f(-1.0f, 1.0f, 0.0f);   // Top Left
           gl.glVertex3f( 1.0f, 1.0f, 0.0f);   // Top Right
           gl.glVertex3f( 1.0f,-1.0f, 0.0f);   // Bottom Right
           gl.glVertex3f(-1.0f,-1.0f, 0.0f);   // Bottom Left
         gl.glEnd();            // Done Drawing The Quad
         gl.glFlush();
   }


   @Override
   public void displayChanged(GLAutoDrawable drawable, boolean modeChanged,
         boolean deviceChanged) {
      // TODO Auto-generated method stub
      
   }


   @Override
    /** Called by the drawable immediately after the OpenGL context is
       * initialized for the first time. Can be used to perform one-time OpenGL
       * initialization such as setup of lights and display lists.
       * @param gLDrawable The GLDrawable object.
       */
   public void init(GLAutoDrawable gLDrawable) {
      // TODO Auto-generated method stub
      final GL gl = gLDrawable.getGL();
         gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
         gl.glShadeModel(GL.GL_FLAT);
         gLDrawable.addKeyListener(this);
   }


   @Override
    /** Called by the drawable during the first repaint after the component has
       * been resized. The client can update the viewport and view volume of the
       * window appropriately, for example by a call to
       * GL.glViewport(int, int, int, int); note that for convenience the component
       * has already called GL.glViewport(int, int, int, int)(x, y, width, height)
       * when this method is called, so the client may not have to do anything in
       * this method.
       * @param gLDrawable The GLDrawable object.
       * @param x The X Coordinate of the viewport rectangle.
       * @param y The Y coordinate of the viewport rectanble.
       * @param width The new width of the window.
       * @param height The new height of the window.
       */
   public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width,
         int height) {
      // TODO Auto-generated method stub
      final GL gl = gLDrawable.getGL();
         final GLU glu = new GLU();

         if (height <= 0) // avoid a divide by zero error!
           height = 1;
         final float h = (float)width / (float)height;
         gl.glViewport(0, 0, width, height);
         gl.glMatrixMode(GL.GL_PROJECTION);
         gl.glLoadIdentity();
         glu.gluPerspective(45.0f, h, 1.0, 20.0);
         gl.glMatrixMode(GL.GL_MODELVIEW);
         gl.glLoadIdentity();
   }
  }

  /** Program's main entry point
   * @param args command line arguments.
   */
  public static void main(String[] args)
  {
    Frame frame = new Frame("Lesson 2: Your First Polygon");
    GLCanvas canvas = new GLCanvas();
    canvas.addGLEventListener(new Renderer());
    frame.add(canvas);
    frame.setSize(640, 480);
    frame.addWindowListener(new WindowAdapter()
    {
      public void windowClosing(WindowEvent e)
      {
        System.exit(0);
      }
    });
    frame.setVisible(true);
    canvas.requestFocus();
  }
}
Offline msiggy

Senior Newbie





« Reply #1 - Posted 2012-03-14 06:33:29 »

It looks like you forgot to attach an animator to your canvas. Try adding this code to your Main method.

Animator animator = new FPSAnimator(canvas, 60);
animator.start();

An animator will call your GlEventListener.display() method in a loop so it can render each frame of your scene.

Offline lzpolestar

Junior Newbie





« Reply #2 - Posted 2012-03-14 08:31:53 »

It looks like you forgot to attach an animator to your canvas. Try adding this code to your Main method.

Animator animator = new FPSAnimator(canvas, 60);
animator.start();

An animator will call your GlEventListener.display() method in a loop so it can render each frame of your scene.



Thank you  very much.I can see the triangle and polygon.
But at the begining the screen has a little flicker. Huh
How to solve it?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2012-03-14 23:33:43 »

Hi

Remove glFlush(). You should switch to JOGL 2.0 as JOGL 1.1.1a is no more maintained. Have a look at the simple example I posted on Wikipedia. Best regards.

Edit.: rather post this kind of question in the JOGL section.

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.

pw (11 views)
2014-07-24 01:59:36

Riven (10 views)
2014-07-23 21:16:32

Riven (11 views)
2014-07-23 21:07:15

Riven (12 views)
2014-07-23 20:56:16

ctomni231 (42 views)
2014-07-18 06:55:21

Zero Volt (38 views)
2014-07-17 23:47:54

danieldean (32 views)
2014-07-17 23:41:23

MustardPeter (34 views)
2014-07-16 23:30:00

Cero (50 views)
2014-07-16 00:42:17

Riven (50 views)
2014-07-14 18:02:53
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!