Skip to main content
GameDev.net gamedev.net
🔒 Locked

Texture coordinate generation

Started by Arkion Feb 3, 2004 at 10:24 AM 0 replies 450+ views
Original Post
Arkion
Arkion
I'm importing LightWave LWO files into my OpenGL 3D viewer. As texture coordinates themselves are not stored in the LWO file, I need to generate texture coordinates manually (using planar mapping) for every vertex of a polygon, given axis of projection (either X, Y or Z), texture width/height and texture u/v offsets. These are the only information found in the LWO file. Is there good simple algorithm for this? I tried using following code but soon realized that it is only ideal for those who are writing their own rasterizer from scratch, as it only returns U/V values in range [0..1[, ie. for every texel on polygon's surface, but never 1.0.
x -= xTextureCenter;
y -= yTextureCenter;
z -= zTextureCenter;
if (textureType == TT_PLANAR)
{
  s = (textureAxis == TA_X) ? z / zTextureSize + .5 : x / 
       xTextureSize + .5;
  t = (textureAxis == TA_Y) ? -z / zTextureSize + .5 : -y / 
      yTextureSize + .5;

  u = fract(s);
  v = fract(t);
}
[edited by - Arkion on February 3, 2004 11:26:47 AM]
Wavewash
Wavewash
I'm not sure if this will help you. But here's a link to projective texture mapping with a code snippit in opengl.

http://cgi3.tky.3web.ne.jp/~tkano/stained.shtml

that's dynamic. I think you want some concrete uv values that don't change. So here's another thread that talked about planar mapping

http://gamedev.net/community/forums/topic.asp?topic_id=204367

I hope that helps.
~Wave

[edited by - Wavewash on February 4, 2004 12:07:27 AM]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.