OpenGL仅将glMaterial应用于一个对象

时间:2018-11-14 18:06:34

标签: opengl

使用下面的代码,我试图将光照应用于太阳。当我应用GL_EMISSION时,似乎也将照明应用到了创建的其他对象上。

GL11.glPushMatrix();
        {


            // how shiny are the front faces of the sun (specular exponent)
            float sunFrontShininess  = 2.0f;
            // specular reflection of the front faces of the sun
            float sunFrontSpecular[] = {0.1f, 0.1f, 0.0f, 1.0f};
            // diffuse reflection of the front faces of the sun
            float sunFrontDiffuse[]  = {1.0f, 1.0f, 1.0f, 1.0f};


            float sunEmission[] = {0.2f, 0.2f, 0.2f, 1f};

            // set the material properties for the sun using OpenGL

            //???????????????????????????????????????????????????????????????????????????????????????
            GL11.glMaterial(GL11.GL_FRONT, GL11.GL_EMISSION, FloatBuffer.wrap(sunEmission));
            //???????????????????????????????????????????????????????????????????????????????????????



            GL11.glMaterialf(GL11.GL_FRONT, GL11.GL_SHININESS, sunFrontShininess);
            GL11.glMaterial(GL11.GL_FRONT, GL11.GL_SPECULAR, FloatBuffer.wrap(sunFrontSpecular));
            GL11.glMaterial(GL11.GL_FRONT, GL11.GL_DIFFUSE, FloatBuffer.wrap(sunFrontDiffuse));

            // position and draw the sun using a sphere quadric object
            GL11.glTranslatef(4.0f, 7.0f, -19.0f);
            new Sphere().draw(0.5f,10,10);



        }
        GL11.glPopMatrix();

0 个答案:

没有答案