无法通过gl.glEnable打开灯

时间:2015-04-29 19:17:02

标签: java opengl jogl

我正在用opengl编写一个java程序,我试图在用户选择JMenu中点亮的东西的情况下使用它,然后它会在房子/谷仓中打开照明......我有一个名为LightOn的方法,我把gl.glEnable(gl.GL_LIGHT0);但是当我从执行的动作中调用它时,它似乎没有打开...是否我的代码中缺少了一些我应该使用的东西,因为我已经尝试使用布尔值了...所以boolean从false开始,当单击JMenuItem时,actionPerformed将boolean变为true并调用方法LightOn。在显示方法中,我有光应该是什么

照明显示方法中的代码片段:

float [] whiteLight = {1.0f, 1.0f, 1.0f, 1.0f};
float [] ambientLight = {0.1f, 0.1f, 0.1f, 1.0f}; //default
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_DIFFUSE, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_SPECULAR, whiteLight,0);
gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_AMBIENT, ambientLight,0);

float [] lightPosition = {25, 25, 25, 1};
    gl.glLightfv(GL2.GL_LIGHT0, GL2.GL_POSITION, lightPosition,0);

float [] diffuse_mp = {1.0f,0.0f,0.0f,1.0f};//red
    //gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_SPECULAR, ambientLight,0);
    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, diffuse_mp,0);


boolean light = false;
public static void LightOn(GLAutoDrawable drawable)
{
    GL2 gl = drawable.getGL().getGL2();

    boolean light = true;
    //gl.glEnable(GLLightingFunc.GL_LIGHTING);
    gl.glEnable(GLLightingFunc.GL_LIGHT0);  

}
public void actionPerformed(ActionEvent e) {
    if(e.getActionCommand().equals("Lighting On"))
    {
        light = true;
        LightOn(canvas);
        System.out.println("Light on");
    }
 }

0 个答案:

没有答案