Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a ball of light in openGL?

I'm trying to make a orb of light (Like a sun) but I can't seem to make it visible at all. I'll give you some snipets of code I have. It's in Java LWJGL, so it might look a little different.

private float lightAmbient[] = { 0.0f, 1.0f, 1.0f, 1.0f };  // Ambient Light Values ( NEW )
    private float lightDiffuse[] = { 1.0f, 1.0f, 1.0f, 1.0f };      // Diffuse Light Values ( NEW )
    private float lightPosition[] = { 0.0f, 0.0f, -5.0f, 1.0f }; // Light Position ( NEW )
    float lightSpecular[] = { 0f, 0f, 0.5f, 1.0f };  // highlight

and

ByteBuffer temp = ByteBuffer.allocateDirect(16);
        temp.order(ByteOrder.nativeOrder());
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_AMBIENT, (FloatBuffer)temp.asFloatBuffer().put(lightAmbient).flip());              // Setup The Ambient Light
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_DIFFUSE, (FloatBuffer)temp.asFloatBuffer().put(lightDiffuse).flip());              // Setup The Diffuse Light
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_POSITION,(FloatBuffer)temp.asFloatBuffer().put(lightPosition).flip());         // Position The Light
        GL11.glLight(GL11.GL_LIGHT1, GL11.GL_SPECULAR,(FloatBuffer)temp.asFloatBuffer().put(lightSpecular).flip());         // Position The Light

        GL11.glEnable(GL11.GL_LIGHT1); 

What else do I have to do to make the light visible?

like image 383
William Avatar asked Dec 28 '09 04:12

William


People also ask

How does OpenGL simulate light?

Lighting in OpenGL is therefore based on approximations of reality using simplified models that are much easier to process and look relatively similar. These lighting models are based on the physics of light as we understand it. One of those models is called the Phong lighting model .

How do I turn on lighting in OpenGL?

In OpenGL, to enable or disable lighting, users need to call glEnable(GL_LIGHTING) or glDisable(GL_LIGHTING). When lighting is enabled, colors that are specified by glColor*() will become invalid. Light position is set using GL_POSITION. Light components are set using GL_AMBIENT, GL_DIFFUSE.

What components make up a light source in OpenGL *?

In fact, in OpenGL, each light source has three colors: an ambient color, a diffuse color, and a specular color. Just as the color of a material is more properly referred to as reflectivity, color of a light is more properly referred to as intensity or energy.

How do you calculate ambient light?

The math for ambient light is trivial. An RGB value that represents the color of an object is multiplied by the ambient percentages to calculate a pixel's final color.


1 Answers

Lights are never visible.

However, their affects on the materials of other objects are. It's therefore important that all objects in the scene have appropriate material properties set.

You may be interested in this article that mentions all the common mistakes one makes when trying to illuminate scenes.

alt text

You will want to look up the glColorMaterial functions as they are the easiest way to set material properties.

like image 65
Frank Krueger Avatar answered Sep 18 '22 01:09

Frank Krueger