Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (109)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Java Game APIs & Engines / JOGL Development / Make a triangle rotate on: 2011-07-29 17: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!
2  Java Game APIs & Engines / Java 3D / Re: Help with meshes/models on: 2011-07-28 17:34:59
I don't get it =S, how can I do it?
3  Java Game APIs & Engines / Java 3D / Help with meshes/models on: 2011-07-28 16:56:00
I'm about to go crazy with this code. I load the mesh/model from a 3ds file with a proper loader and I put it to render but nothing appears. Here is the 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  
package teste;
import com.sun.j3d.loaders.*;
import com.sun.j3d.loaders.objectfile.ObjectFile;
import com.sun.j3d.utils.geometry.Text2D;
import javax.swing.*;
import javax.media.j3d.*;
import com.sun.j3d.utils.universe.*;
import java.awt.*;
import java.io.*;
import javax.vecmath.*;
import ncsa.j3d.*;
import ncsa.j3d.loaders.*;
/**
 *
 * @author ramon
 */

public class Main {

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

    public static void main(String[] args) throws Exception{
        JFrame frame = new JFrame("Teste Java3D");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(640, 480);
        frame.setResizable(false);
        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas = new Canvas3D(config);
        SimpleUniverse universe = new SimpleUniverse(canvas);
        BranchGroup group = new BranchGroup();
        final int BOUNDSIZE = 100;
        BoundingSphere bounds = new BoundingSphere(new Point3d(0,0,0), BOUNDSIZE);
        Scene s = null;
        ModelLoader map = new ModelLoader();
        try {
            s = map.load("/home/ramon/data/models/Coolrobo.3ds");
        }
        catch(Exception e) {
            e.printStackTrace();
        }
        BranchGroup gr = s.getSceneGroup();
        gr.setBounds(bounds);
        TransformGroup tg = new TransformGroup();
        tg.addChild(gr);
        Switch sw = new Switch();
        sw.addChild(tg);
        sw.setCapability(Switch.ALLOW_SWITCH_WRITE);
        sw.setWhichChild( Switch.CHILD_ALL );
        group.addChild(sw);
        group.compile();
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.addBranchGraph(group);
        frame.add(canvas);
        frame.setVisible(true);
    }

}


Text3D works finely, Text2D also, the primitives as well, my only problem is with the mesh/model.
Please someone give me some help!!

P.S.: My problem is that I can't see the mesh rendered! It's not the API, other program(not written by me) works finely with the very same mesh. It's not the lib. I don't know what is!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

CogWheelz (18 views)
2014-07-30 21:08:39

Riven (26 views)
2014-07-29 18:09:19

Riven (15 views)
2014-07-29 18:08:52

Dwinin (13 views)
2014-07-29 10:59:34

E.R. Fleming (34 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

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

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

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

Riven (31 views)
2014-07-23 20:56:16
List of Learning Resources
by SilverTiger
2014-07-31 18:29:50

List of Learning Resources
by SilverTiger
2014-07-31 18:26:06

List of Learning Resources
by SilverTiger
2014-07-31 13:54:12

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
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!