Lighting non-textured polygons
-
- Posts: 5
- Joined: Fri Dec 02, 2011 9:55 pm
Lighting non-textured polygons
Hello, I'm a hobbyist programmer. I'm porting a desktop 3D game written for OpenGL to libnds.
Does anyone know if libnds' GL implementation supports lighting non-textured polygons ?
I've tried to get this to work, but to no avail, so I'm tempted to suppose that it is simply not supported.
Thank you for your time.
Does anyone know if libnds' GL implementation supports lighting non-textured polygons ?
I've tried to get this to work, but to no avail, so I'm tempted to suppose that it is simply not supported.
Thank you for your time.
Re: Lighting non-textured polygons
I believe it is supported. do you have some code that we could look at?
-
- Posts: 5
- Joined: Fri Dec 02, 2011 9:55 pm
Re: Lighting non-textured polygons
Yes. My source code is here: http://github.com/bl0ckeduser/clown3d-DS.
The relevant part is in main.c. For reference, there is standard GL code which sucessfully lights the polygons (guarded by "#ifdef PC_TARGET").
The relevant part is in main.c. For reference, there is standard GL code which sucessfully lights the polygons (guarded by "#ifdef PC_TARGET").
Re: Lighting non-textured polygons
Should be pretty simple. Make sure you've got lights active via glPolyFmt(), and make sure textures are disabled, either by glDisable( ) for global effect, or use glBindTexture( ) if you want textured and non-textured polygons together.
However, by doing that, you effectively lose the ability to use glColor to assign polygons an actual color, mixed with the color the lights give. I think OpenGL does this too unless I'm mistaken, but if you want the polygons to have their own color mixed with the lights, you can use textures to do this. An 8x8 texture of the particular color would do the job.
However, by doing that, you effectively lose the ability to use glColor to assign polygons an actual color, mixed with the color the lights give. I think OpenGL does this too unless I'm mistaken, but if you want the polygons to have their own color mixed with the lights, you can use textures to do this. An 8x8 texture of the particular color would do the job.
Re: Lighting non-textured polygons
You should be able to use an 8x8 all-white texture and use glColor to set the vertex color. It would be better than a texture for each color. Plus you have the advantage of setting color by vertex instead of being limited per face.
-
- Posts: 5
- Joined: Fri Dec 02, 2011 9:55 pm
Re: Lighting non-textured polygons
With OpenGL I managed to light glColor'ed polygons.Discostew wrote:However, by doing that, you effectively lose the ability to use glColor to assign polygons an actual color, mixed with the color the lights give. I think OpenGL does this too unless I'm mistaken, but if you want the polygons to have their own color mixed with the lights, you can use textures to do this. An 8x8 texture of the particular color would do the job.
Discostew and mtheall, the texture hacks you suggest sound like good solutions, I will be trying these.
(Sorry if my replies come in late, they must be approved by an admin before they appear).
Re: Lighting non-textured polygons
as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.
Re: Lighting non-textured polygons
Most definitely you can! How do I know? Because I've done it before. Granted, I haven't tried it with textures enabled, but I don't think that will make a difference. From my experience, using the Normal command does not set the vertex color; it "multiplies" the intensity of the light by some factor that involves the angle of incidence, then it multiplies the result with the vertex color, then you have a final vertex color.elhobbs wrote:as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.
The following ROM demonstrates this. Press the 'down' key until you reach "Open file..." then press 'A'. Then select one of the models and press 'A'. Of particular interest is bowserSmooth.bin. It takes advantage of normals to give the appearance of smoothness. Make sure you try out the various lights. The lights constantly move to different directions. Unfortunately, I only made them white light. I may provide an updated version with different color lights so you can see the effect it will have.
http://mtheall.com/modelviewer.nds
-
- Posts: 5
- Joined: Fri Dec 02, 2011 9:55 pm
Re: Lighting non-textured polygons
Nice. That's exactly what I'm trying to do. Did you do this with the white texture hack ?mtheall wrote:Most definitely you can! How do I know? Because I've done it before. Granted, I haven't tried it with textures enabled, but I don't think that will make a difference. From my experience, using the Normal command does not set the vertex color; it "multiplies" the intensity of the light by some factor that involves the angle of incidence, then it multiplies the result with the vertex color, then you have a final vertex color.elhobbs wrote:as discostew pointed out, you cannot use hardware lights and glColor on the same polygon. hardware lights set the vertex color when you call glNormal - one overwrites the other.
The following ROM demonstrates this. Press the 'down' key until you reach "Open file..." then press 'A'. Then select one of the models and press 'A'. Of particular interest is bowserSmooth.bin. It takes advantage of normals to give the appearance of smoothness. Make sure you try out the various lights. The lights constantly move to different directions. Unfortunately, I only made them white light. I may provide an updated version with different color lights so you can see the effect it will have.
http://mtheall.com/modelviewer.nds
Re: Lighting non-textured polygons
No these models are textureless (textures are not enabled). However, you should be able to do this with textures enabled with an all-white texture. I will try to convert my example to do so.
Who is online
Users browsing this forum: Bing [Bot] and 2 guests