Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (568)
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  
  LWJGL Static Light Source  (Read 1085 times)
0 Members and 1 Guest are viewing this topic.
Offline Vladiedoo
« Posted 2012-12-16 22:27:12 »

Hi, I am having trouble with lighting.
Before I go on I have one quick question.

1  
2  
3  
IntBuffer lights = BufferUtils.createIntBuffer(16);
GL11.glGetInteger(GL11.GL_MAX_LIGHTS, lights);
writeLine("Maximum number of light sources: " + lights.get(0));

That code outputs the number 8. I am sure my understanding of OpenGL lights is incorrect but how is possible that I can only create 8 lights? As in, to my understanding, games can create a lot more than 8 lights.

Okay and here is my attempt at setting up lights.

(Perhaps I should have uploaded a larger image) parts of quads are lit up but not others, some corners have two quads lit but not the third.

The room is drawn with 6 quads and texture bound over them (I need to move on to floatBuffers).
Here is the light setup.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, floatBuffer(1.0f, 1.0f, 1.0f, 1.0f));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, floatBuffer(0.1f, 0.1f, 0.1f, 1.0f));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, floatBuffer(1.0f, 1.0f, 1.0f, 1.0f));
GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_TRUE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
// For the last line, what is the last float used for? Shouldn't it just be x,y,z?
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, floatBuffer(-5f, -5f, -5f, 1f));
/* Rendering here. */


public FloatBuffer floatBuffer(float a, float b, float c, float d) {
   float[] data = new float[] { a, b, c, d };
   FloatBuffer fb = BufferUtils.createFloatBuffer(data.length);
   fb.put(data);
   fb.flip();
   return fb;
}


Perhaps I need to setup normals (I'm not too informed on normals) on my quads?

Thank you for your time and help.
Offline JohnyCilohokla

Senior Newbie


Exp: 2 years



« Reply #1 - Posted 2012-12-16 23:16:21 »

Hi, I am having trouble with lighting.
Before I go on I have one quick question.
1  
2  
3  
[code]IntBuffer lights = BufferUtils.createIntBuffer(16);
GL11.glGetInteger(GL11.GL_MAX_LIGHTS, lights);
writeLine("Maximum number of light sources: " + lights.get(0));

That code outputs the number 8. I am sure my understanding of OpenGL lights is incorrect but how is possible that I can only create 8 lights? As in, to my understanding, games can create a lot more than 8 lights.

The 8 lights is not the maximum number of light sources you can create. It is the maximum number of active light sources.
You can switch between unlimited amount of light during rendering.

Okay and here is my attempt at setting up lights.

(Perhaps I should have uploaded a larger image) parts of quads are lit up but not others, some corners have two quads lit but not the third.


You would have to tell us what you are trying to achieve.
Will it be possible to use the closest(8 or less) light sources to light up each quad/set of quads?

The room is drawn with 6 quads and texture bound over them (I need to move on to floatBuffers).
Here is the light setup.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL11.GL_LIGHT0);
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_DIFFUSE, floatBuffer(1.0f, 1.0f, 1.0f, 1.0f));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_AMBIENT, floatBuffer(0.1f, 0.1f, 0.1f, 1.0f));
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_SPECULAR, floatBuffer(1.0f, 1.0f, 1.0f, 1.0f));
GL11.glLightModeli(GL11.GL_LIGHT_MODEL_TWO_SIDE, GL11.GL_TRUE);
GL11.glEnable(GL11.GL_COLOR_MATERIAL);
GL11.glColorMaterial(GL11.GL_FRONT_AND_BACK, GL11.GL_AMBIENT_AND_DIFFUSE);
// For the last line, what is the last float used for? Shouldn't it just be x,y,z?
GL11.glLight(GL11.GL_LIGHT0, GL11.GL_POSITION, floatBuffer(-5f, -5f, -5f, 1f));
/* Rendering here. */


public FloatBuffer floatBuffer(float a, float b, float c, float d) {
   float[] data = new float[] { a, b, c, d };
   FloatBuffer fb = BufferUtils.createFloatBuffer(data.length);
   fb.put(data);
   fb.flip();
   return fb;
}


Perhaps I need to setup normals (I'm not too informed on normals) on my quads?

Thank you for your time and help.[/code]

If you really need more that 8 light sources per vertex you should look at shaders.
Otherwise try to group vertex(quads) by light sources that are affecting them, and then setup lights, render, setup lights, render, setup lights, render...
Offline Vladiedoo
« Reply #2 - Posted 2012-12-16 23:25:55 »

For this project I do not actually need light sources, I am just trying to incorporate them so I can learn. As of now I just want to learn how to place one light at the center of the cube. So no, I do not need more than 8 light sources.

With the code I have I thought it would possibly place a light at -5, -5, -5. Then at that position I would see everything around it be more light up than the rest of the cube. (-5, -5, -5 is not the center of the cube).

EDIT: In the past whenever I tried to incorporate lights, the game would be very dim and would light up only when I turned my Camera to certain angles. I got that issue to go away but I don't see a proper light source, I don't see any "light bulb" of light coming from anywhere, and if I change many individual parts of my code, the outcome doesn't change. Do I need to learn more about normals?

EDIT2: Perhaps it is a bit hard to decipher as my image has lots of fading colors, here is a before and after.
WITHOUT LIGHT

WITH LIGHT
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 802
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #3 - Posted 2012-12-16 23:48:33 »

If you are debugging lighting, don't use textures that are mainly black. Preferably every surface (texture, vertex color) should be fully white, so you can see exactly what the lighting is doing.

For positioned lights (as opposed to directional lights): when using vertex lighting, don't make your surfaces to big (relative to the light). Either sub-divide your geometry, or try to get per-pixel-lighting to work through shaders.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
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.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (20 views)
2014-09-24 16:12:06

Grunnt (46 views)
2014-09-23 14:38:19

radar3301 (28 views)
2014-09-21 23:33:17

BurntPizza (64 views)
2014-09-21 02:42:18

BurntPizza (36 views)
2014-09-21 01:30:30

moogie (42 views)
2014-09-21 00:26:15

UprightPath (51 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!