English 中文(简体)
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?

问题回答

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 Frank said, lights are invisible, they are merely used as an input to the lighting equation used by the rendering system (hardware/software) to calculate the final colors of geometry.

If you want something to look like a light you need to mimic the effects that you are used to seeing when looking at a bright light source. For the sun one of the most noticeable effects is light bloom.

For information on generating light bloom read this OpenGL Bloom Tutorial, and here is some sample code in Java using GLSL to generate a bloom effect.

Depending on if you want full bloom style effects (if so, look at Josh Perry s answer) or just a not-dark object object that seems to emit light you might want to consider this simple approach.

  • Render the scene without the actual sun mesh but with a point light at the centre of your sun .
  • Disable GL Lighting.
  • Render a sphere or use a billboard to render an image of your sun in the appropriate spot.
  • Re-enable GL Lighting before you display your next frame.

Because you ve disabled lighting, the sun will be rendered full-bright with no shading or lighting calculations being performed.





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签