Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (581)
games submitted by our members
Games in WIP (500)
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  
  [JOGL/JSR-231] Specular problem  (Read 514 times)
0 Members and 1 Guest are viewing this topic.
Offline JuMisMa

Senior Newbie


Medals: 1



« Posted 2009-01-11 20:44:41 »

Hi everybody.

First, I'm french, so I'm sorry for my poor english.

I'm a JOGL (JSR-231) newbie and I have 2 difficulties with the specular component of my lighting.

1 / when my camera is pointing to z -, all seems to be working. The good code portion:

1  
2  
3  
4  
final float[] CAMERA_POSITION = new float[]{0F, 5F, 15F};
final float[] CAMERA_DIRECTION = new float[]{0F, 0F, 0F};
final float[] SPOT_POSITION = new float[]{0F, 5F, 15F, 1F};
final float[] SPOT_DIRECTION = new float[]{0F, 0F, -1F, 1F};


but if I'm pointing to the z-, I lose the specular component. The bad code portion:

1  
2  
3  
4  
final float[] CAMERA_POSITION = new float[]{0F, 5F, -15F};
final float[] CAMERA_DIRECTION = new float[]{0F, 0F, 0F};
final float[] SPOT_POSITION = new float[]{0F, 5F, -15F, 1F};
final float[] SPOT_DIRECTION = new float[]{0F, 0F, 1F, 1F};


2 / If i activate this :

1  
gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, GL.GL_TRUE)


I'm losing also the specular composant

The entire 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  
117  
118  
119  
120  
121  
122  
123  
124  
125  
126  
127  
128  
129  
130  
131  
132  
133  
134  
package Test1;

import com.sun.opengl.util.Animator;
import com.sun.opengl.util.GLUT;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.Insets;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.media.opengl.*;
import javax.media.opengl.glu.*;
import javax.swing.SwingUtilities;

public class TestAPoster extends Frame implements GLEventListener {

    private final GLU GLU = new GLU();
    private final GLUT GLUT = new GLUT();
    private final Dimension CLIENT_MINIMUM_DIMENSION = new Dimension(640, 480);

    final float[] CAMERA_POSITION = new float[]{0F, 5F, 15F};
    final float[] CAMERA_DIRECTION = new float[]{0F, 0F, 0F};
    final float[] SPOT_POSITION = new float[]{0F, 5F, 15F, 1F};
    final float[] SPOT_DIRECTION = new float[]{0F, 0F, -1F, 1F};

    public TestAPoster() {

        // Hardware OpenGl
       GLCapabilities glCapabilities = new GLCapabilities();
        glCapabilities.setDoubleBuffered(true);
        glCapabilities.setHardwareAccelerated(true);

        // Canvas JOGL
       GLCanvas canvas = new GLCanvas();
        canvas.addGLEventListener(this);
        canvas.setPreferredSize(CLIENT_MINIMUM_DIMENSION);
        add(canvas);

        // Fenêtre
       setTitle(getClass().getSimpleName());
        setLocation(20, 20);
        setVisible(true);
        final Insets insets = getInsets();
        setMinimumSize(new Dimension(CLIENT_MINIMUM_DIMENSION.width + insets.left + insets.right, CLIENT_MINIMUM_DIMENSION.height + insets.top + insets.bottom));
        pack();

        // Boucle d'affichage
       final Animator animator = new Animator(canvas);
        addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent e) {
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        animator.stop();
                        System.exit(0);
                    }
                }).start();
            }
        });
        // Et c'est parti ...
       animator.start();
    }

    @Override
    public void init(GLAutoDrawable _glDrawable) {
    }

    @Override
    public void display(GLAutoDrawable _glDrawable) {
        final GL gl = _glDrawable.getGL();
        gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
        GLUT.glutSolidTeapot(3);
    }

    @Override
    public void reshape(GLAutoDrawable _glDrawable, int _x, int _y, int _width, int _height) {
        final GL gl = _glDrawable.getGL();

        // Couleur de fond et du zbuffer
       gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
        gl.glClearDepth(1.0f);

        // Caméra et projection
       gl.glMatrixMode(GL.GL_PROJECTION);
        gl.glLoadIdentity();
        GLU.gluPerspective(45, (double) ((double) _width / (double) _height), 0.1D, 100D);
        GLU.gluLookAt(CAMERA_POSITION[0], CAMERA_POSITION[1], CAMERA_POSITION[2], CAMERA_DIRECTION[0], CAMERA_DIRECTION[1], CAMERA_DIRECTION[2], 0D, 1D, 0D);

        // Matrix de vue
       gl.glMatrixMode(GL.GL_MODELVIEW);
        gl.glLoadIdentity();

        // Modèle d'éclairage
       gl.glShadeModel(GL.GL_SMOOTH);
        //gl.glLightModeli(GL.GL_LIGHT_MODEL_LOCAL_VIEWER, GL.GL_TRUE);

        // Lumière ponctiuelle
       gl.glLightfv(GL.GL_LIGHT0, GL.GL_POSITION, SPOT_POSITION, 0);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPOT_DIRECTION, SPOT_DIRECTION, 0);
        gl.glLightf(GL.GL_LIGHT0, gl.GL_SPOT_CUTOFF, 60F);
        gl.glLightf(GL.GL_LIGHT0, GL.GL_SPOT_EXPONENT, 3.0F);

        gl.glLightfv(GL.GL_LIGHT0, GL.GL_AMBIENT, new float[]{0.2F, 0.2F, 0.2F, 1F}, 0);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_DIFFUSE, new float[]{1F, 0F, 0F, 1F}, 0);
        gl.glLightfv(GL.GL_LIGHT0, GL.GL_SPECULAR, new float[]{1F, 1F, 1F, 1F}, 0);

        // Matériau de l'objet
       gl.glMaterialfv(GL.GL_FRONT, GL.GL_AMBIENT, new float[]{0.2F, 0.2F, 0.2F, 1F}, 0);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_DIFFUSE, new float[]{1F, 0F, 0F, 1F}, 0);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_SPECULAR, new float[]{1F, 1F, 1F, 1F}, 0);
        gl.glMaterialfv(GL.GL_FRONT, GL.GL_SHININESS, new float[]{30F}, 0);

        // Etats
       gl.glEnable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_LIGHTING);
        gl.glEnable(GL.GL_LIGHT0);
    }

    @Override
    public void displayChanged(GLAutoDrawable _glDrawable, boolean _modeChanged, boolean _deviceChanged) {
    }

    public static void main(String[] _args) {
        final TestAPoster test = new TestAPoster();
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                test.setVisible(true);
            }
        });
    }
}


In attachment the pictures.

Thank you very much for your answers.


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.

xsi3rr4x (63 views)
2014-04-15 18:08:23

BurntPizza (61 views)
2014-04-15 03:46:01

UprightPath (74 views)
2014-04-14 17:39:50

UprightPath (57 views)
2014-04-14 17:35:47

Porlus (75 views)
2014-04-14 15:48:38

tom_mai78101 (100 views)
2014-04-10 04:04:31

BurntPizza (160 views)
2014-04-08 23:06:04

tom_mai78101 (255 views)
2014-04-05 13:34:39

trollwarrior1 (208 views)
2014-04-04 12:06:45

CJLetsGame (215 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!