Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (512)
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  
  [JOGL/JSR-231] Specular problem  (Read 566 times)
0 Members and 1 Guest are viewing this topic.
Offline JuMisMa

Senior Newbie


Medals: 1



« Posted 2009-01-11 19: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.

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

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

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

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

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

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

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

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

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

BurntPizza (84 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!