lightmaps in OGL?

Started by
3 comments, last by InsanE 23 years, 3 months ago
How do I use lightmaps in OGL?
Advertisement
OpenGL doesn''t have any built in support for lightmaps. To actually use a lightmap, you either use the multitexture extension or you use multi-pass rendering.

With multitexturing you just activate the base texture and lightmap texture and specify two sets of texture co-ordinates for each primitive, assuming you''ve checked that the extension is supported and used wglGetProcAddress to get the addresses of the relevant functions.

  glActiveTextureARB(GL_TEXTURE0_ARB);glBindTexture(GL_TEXTURE_2D, baseTextureID);glActiveTextureARB(GL_TEXTURE1_ARB);glBindTexture(GL_TEXTURE_2D, lightmapID);glMultiTexCoord2fARB(GL_TEXTURE0_ARB, 0.0f, 0.0f);glMultiTexCoord2fARB(GL_TEXTURE1_ARB, 0.0f, 0.0f);glVertex3f(0.0f, 0.0f, 0.0f);  


Multi-pass rendering is a bit harder, you have to render each primitive twice, once with the base texture and once with the lightmap texture setting the appropriate blending mode each time.

To generate your lightmaps you can use any technique, radiosity, ray tracing etc.

an example is on my site under the multitexture extension

http://members.xoom.com/myBollux
Thanks for the help! I will use Multitexturing and check your link out.

BTW: is there a nice tut talking about the creation of well looking lightmaps?
As I said you can use any method for generating the lightmaps. Just create an array of width x height x bpp, where width and height corresponds to the width and height of the lightmap texture and bpp represents the required number of bits per pixels for the lightmap texture. Then fill the array with colour values you calculate using the technique of your choice. When that''s done you can write the array to a file. For specific information on generating the values in the lightmaps check the articles section on gamedev and flipcode or search the net for topics like lightmaps, radiosity, Lambertian, ray tracing and so on.

This topic is closed to new replies.

Advertisement