Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (292)
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 430 times)
0 Members and 1 Guest are viewing this topic.
Offline JuMisMa

Junior Newbie





« 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.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars and Titan!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (66 views)
2013-05-17 21:29:12

alaslipknot (75 views)
2013-05-16 21:24:48

gouessej (106 views)
2013-05-16 00:53:38

gouessej (103 views)
2013-05-16 00:17:58

theagentd (114 views)
2013-05-15 15:01:13

theagentd (103 views)
2013-05-15 15:00:54

StreetDoggy (148 views)
2013-05-14 15:56:26

kutucuk (171 views)
2013-05-12 17:10:36

kutucuk (169 views)
2013-05-12 15:36:09

UnluckyDevil (178 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.323 seconds with 21 queries.