Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
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  
  Make a triangle rotate  (Read 2624 times)
0 Members and 1 Guest are viewing this topic.
Offline rvitorper

Junior Newbie





« Posted 2011-07-29 15:27:27 »

Hi,
I'm currently using JOGL ver. 1.1.1 and it seems to me that it calls method display(GLAutoDrawable) only once, whereas the code for C calls it every time it loops. Here is my code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
this is in Main.java:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package test;
import javax.media.opengl.*;
import javax.swing.*;
/**
 *
 * @author ramon
 */

public class Main {

    /**
     * @param args the command line arguments
     */

    public static void main(String[] args) {
        JFrame frame = new JFrame("Jogl Test");
        frame.setSize(640,480);
        frame.setResizable(true);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GLCanvas canvas = new GLCanvas();

        SimpleJogl glevent = new SimpleJogl();
        canvas.addGLEventListener(glevent);
        frame.add(canvas);
        frame.setVisible(true);
    }

}

this is in SimpleJogl.java:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */


package test;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;

/**
 *
 * @author ramon
 */

public class SimpleJogl implements GLEventListener {
    public SimpleJogl() {
    }

    public void init(GLAutoDrawable glad) {
        GL gl = glad.getGL();
        gl.setSwapInterval(1);
        gl.glShadeModel(GL.GL_SMOOTH);
        gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClearDepth(1.0f);
        gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glDepthFunc(GL.GL_LEQUAL);
        gl.glHint(GL.GL_PERSPECTIVE_CORRECTION_HINT, GL.GL_NICEST);

       
    }

    public void display(GLAutoDrawable glad) {
        GL gl = glad.getGL();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        gl.glLoadIdentity();
        gl.glTranslatef(-1.5f, 0.0f, -6.0f);
      gl.glRotatef(rtri, 0.0f, 1.0f, 0.0f);
      gl.glBegin(GL.GL_TRIANGLES);          // Drawing Using Triangles
        gl.glColor3f(1.0f, 0.0f, 0.0f);   // Set the current drawing color to red
        gl.glVertex3f( 0.0f, 1.0f, 0.0f);   // Top
        gl.glColor3f(0.0f, 1.0f, 0.0f);   // Set the current drawing color to green
        gl.glVertex3f(-1.0f,-1.0f, 0.0f);   // Bottom Left
        gl.glColor3f(0.0f, 0.0f, 1.0f);   // Set the current drawing color to blue
        gl.glVertex3f( 1.0f,-1.0f, 0.0f);   // Bottom Right
      gl.glEnd();            // Finished Drawing The Triangle
      gl.glLoadIdentity();
      gl.glTranslatef(1.5f, 0.0f, -6.0f);
      gl.glRotatef(rquad, 1.0f, 0.0f, 0.0f);
      gl.glBegin(GL.GL_QUADS);              // Draw A Quad
        gl.glColor3f(0.5f, 0.5f, 1.0f);   // Set the current drawing color to light blue
        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();
      rtri += 0.2f;
      rquad += 0.15f;

    }

    public void reshape(GLAutoDrawable glad, int x, int y, int width, int height) {
        final GL gl = glad.getGL();
        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();
    }

    public void displayChanged(GLAutoDrawable glad, boolean bln, boolean bln1) {
    }
    private float rquad = 0.0f;
    private float rtri = 0.0f;
}


I'd like to see the triangle rotating always.
Please help!
Offline ra4king

JGO Kernel


Medals: 350
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-07-29 17:00:36 »

JOGL 1.1.1a is extremely outdated. Please use the latest version from www.jogamp.org

Offline lhkbob

JGO Knight


Medals: 32



« Reply #2 - Posted 2011-07-29 17:58:28 »

In JOGL (any version), display() gets called in three ways:
1. In response to repaint() requests from AWT, so you get one display() when the frame is made visible
2. If you use an Animator or FPSAnimotor to repeatedly call display()
3. If you call it yourself (not recommended unless you know what you're doing).

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

Senior Duke


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Reply #3 - Posted 2011-08-01 13:24:11 »

Are people not supposed to be using the GL object nowadays?  Are my friend and I reading some old outdated tutorials?  Is it a complete waste to not use a GL4?

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline gouessej
« Reply #4 - Posted 2011-08-01 13:32:18 »

Are people not supposed to be using the GL object nowadays?  Are my friend and I reading some old outdated tutorials?  Is it a complete waste to not use a GL4?
JOGL has a very thin abstraction layer above OpenGL. In C/C++, this layer is replaced by GLUT for example. Both in Java and in C you have to use something to update your display frequently. In C, when using GLUT, you call glutPostRedisplay() as far as I know. In Java, when using JOGL, you use lhkbob's suggestions, especially the 2 first ones.

Anyway, it does not mean that you don't have to use GL objects. You seem not to understand what a GL object is. It is explained here:
http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained

There is an example of drawing of a triangle in JOGL 2 here:
http://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start

Look at my example on Wikipedia.

Offline lhkbob

JGO Knight


Medals: 32



« Reply #5 - Posted 2011-08-01 16:04:46 »

You have to use GL objects to perform the actual GL operations.  As you've been doing, you get the GL objects from the GLAutoDrawables passed into the methods from the GLEventListener.  This is still the way to do things.

Offline Z-Knight

Senior Duke


Medals: 1



« Reply #6 - Posted 2011-08-01 16:54:37 »

Simple answer is that you need to use the FPSAnimator to make it constantly redraw like it does in C based OpenGL.

Option 3 that lhkbob suggested is what I use and I don't think it is a big deal - I just don't want to have my display constantly repainting the same scene that doesn't change. So I force a display update only on keyboard/mouse inputs or various event updates
Offline Rejechted

Senior Duke


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Reply #7 - Posted 2011-08-01 17:11:44 »

Are people not supposed to be using the GL object nowadays?  Are my friend and I reading some old outdated tutorials?  Is it a complete waste to not use a GL4?
JOGL has a very thin abstraction layer above OpenGL. In C/C++, this layer is replaced by GLUT for example. Both in Java and in C you have to use something to update your display frequently. In C, when using GLUT, you call glutPostRedisplay() as far as I know. In Java, when using JOGL, you use lhkbob's suggestions, especially the 2 first ones.

Anyway, it does not mean that you don't have to use GL objects. You seem not to understand what a GL object is. It is explained here:
http://michael-bien.com/mbien/entry/jogl_2_opengl_profiles_explained

There is an example of drawing of a triangle in JOGL 2 here:
http://jogamp.org/wiki/index.php/Using_JOGL_in_Java_Web_Start

Look at my example on Wikipedia.

When I said "not supposed to use a GL object" i meant a GL object as opposed to a GL2, 3, or 4.  All of the later ones have the exact same fields as the original GL, so is there any reason to not use a GL4?

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Offline lhkbob

JGO Knight


Medals: 32



« Reply #8 - Posted 2011-08-01 21:14:04 »

The numbers after them correspond to the OpenGL version profile that is used.  Since OpenGL 3, OpenGL is no longer backwards compatible.  Additionally, there are different profiles for desktop devices and mobile devices.  The GL object represents the operations defined in OpenGL that are shared by every profile. 

Another example is the GL2GL3 object, this is the extension of GL that defines the OpenGL operations shared between version 2.0 and 3.0.  Depending on what you want to do, you must choose a different version to work with.  I generally use GL2GL3 for a lot of my engine code that can be shared between versions (such as textures and VBOs) so I won't have to rewrite it. 

If you want to use the fixed functionality of OpenGL or run on older graphics cards, you'll need to use GL2.  If you want to use GL4, you'll have to have OpenGL version 4.0 installed and supported on your graphics card.

If you can get away with programming to the GL interface without picking a specific version, I would try that because it will allow you to run your code across more computers more easily.  If you're the only one using your program and you want to program to 4.0 and you have OpenGL 4 (or are fine with only having it run on newer computers), then you can do that too.

Offline Rejechted

Senior Duke


Medals: 1
Projects: 1


Just a guy making some indie games :D


« Reply #9 - Posted 2011-08-02 14:17:31 »

Gotcha.  So if we're intending to make our game compatible with as many computers and GPU's as we can, we should try to stick to GL or GL2.  Currently we are using GL, but from what you're saying it sounds like there's really no reason we wouldn't want to use GL2 instead.

Blog for our project (Codenamed Lead Crystal): http://silvergoblet.tumblr.com
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline lhkbob

JGO Knight


Medals: 32



« Reply #10 - Posted 2011-08-02 15:24:26 »

Correct, GL2 should be a good starting point for you.

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.

Longarmx (36 views)
2014-10-17 03:59:02

Norakomi (28 views)
2014-10-16 15:22:06

Norakomi (24 views)
2014-10-16 15:20:20

lcass (27 views)
2014-10-15 16:18:58

TehJavaDev (52 views)
2014-10-14 00:39:48

TehJavaDev (54 views)
2014-10-14 00:35:47

TehJavaDev (42 views)
2014-10-14 00:32:37

BurntPizza (63 views)
2014-10-11 23:24:42

BurntPizza (36 views)
2014-10-11 23:10:45

BurntPizza (77 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!