Jump to content
  • Advertisement
Sign in to follow this  
WWakerFAN

OpenGL lighting in a 2d game

This topic is 4839 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i'm having a little bit of trouble implementing opengl lighting into a 2d game, could someone point me in the right direction?

Share this post


Link to post
Share on other sites
Advertisement
i'm sorry to be rude, but do you even need ligthing in a 2D game? also, can you post your exact problems? i don't want to answer you with something your not even looking for:-) so post the problems, and i'll get back to you:-)

later

Share this post


Link to post
Share on other sites
Quote:
Original post by lack the hack
i'm sorry to be rude, but do you even need ligthing in a 2D game? also, can you post your exact problems? i don't want to answer you with something your not even looking for:-) so post the problems, and i'll get back to you:-)

later


i guess my problem is that the lights seem too dark and i'm not sure of the best way to "brighten" things up


Share this post


Link to post
Share on other sites
You can brithen things up by changing the Blending Mode. In DirectX if you set your Source to SrcAlpha,and your Destination to INVDESTCOLOR and change the Texture Stage State to D3DTOP_MODULATE2X on the COLOROP you can then draw your tiles brither than they look which in term means you are adding light. I hope that help

Share this post


Link to post
Share on other sites
Quote:
Original post by kburkhart84
I would need to know how yo are doing lighting now to be able to tell you how to modify that to get better lighting.


GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };
GLfloat LightDiffuse[]= { 1.0f, 1.0f, 1.0f, 1.0f };
GLfloat LightPosition[]= { 128.0f, 116.0f, 2.0f, 1.0f };

/\/\/\/\/\/\/\/\/
glLightfv(GL_LIGHT1, GL_AMBIENT, LightAmbient);
glLightfv(GL_LIGHT1, GL_DIFFUSE, LightDiffuse);
glLightfv(GL_LIGHT1, GL_POSITION,LightPosition);
glEnable(GL_LIGHT1);

/\/\/\/\/\/\/\/\/
glEnable(GL_LIGHTING);

Share this post


Link to post
Share on other sites

You haven't shown any screenshots, so it's difficult to tell what should be changed.

IMHO you should play with ambient.

Share this post


Link to post
Share on other sites
Other suggestions

1) Set up normals correctly ( for example set every normal as 0,0,1 )
2) Remember that by default OpenGL assumes your normals have unit length; if you glScale an object you have to 'renormalize' the normals accordingly.
3) Read the light tutorial on the red book (the first link I've found with google)
4) Do you really need lighting in a 2D game ? Can you simulate it ? (today you have no speed penalty in using real time light however...)

Share this post


Link to post
Share on other sites
I've been doing light in just the way that BornToCode describes, with great results, with a generic light sprite that I draw over top of a tile map. I also split my tilemap into layers, and lightmap the floor layer. (With walls occluding light)

This is actually a lot easier to do then you might think, just look into line/box intersection.

For a tilebased game, I think this is a cool way to do it, but I have no idea if your game is tilebased or not.

Share this post


Link to post
Share on other sites
OpenGL lights work too.

GLfloat LightAmbient[]= { 0.5f, 0.5f, 0.5f, 1.0f };

This ambient light will be a grayish light. Maybe if you made it like this.

GLfloat LightAmbient[]= { 0.8f, 0.8f, 0.8f, 1.0f };

That is a brighter white color, if that is what you are looking for. This is the ambient light that hits everything though.

**EDIT**

Also, check all the normals and make sure they are what they should be. The next step for cool lighting will be setting up spotlights in the 2d world. For example, Inside a room, put a spotlight at the position(0, 0, 5) and set the cone angle right. Have it point at your tile map, vector(0, 0, -1), and if the angle is right, you get a circle look, or at least the center will be brighter than the outside areas by the walls.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!