- procedure CreateCubeNormalMap;
- type
- TRGB=record
- r,g,b:byte;
- end;
- var
- i,a,b:integer;
- v:TVertex;
- s,t:single;
- texdata:array[0..255,0..255] of TRGB;
- begin
- glenable(GL_TEXTURE_CUBE_MAP_EXT);
- glbindtexture(GL_TEXTURE_CUBE_MAP_EXT,texid[0]);
- for i:=0 to 5 do
- begin
- for a:=0 to 255 do
- for b:=0 to 255 do
- begin
- s:=(((a+0.5)/255)*2-1);
- t:=(((b+0.5)/255)*2-1);
- case i of
- 0:v:=vector(1,-t,-s);
- 1:v:=vector(-1,-t,s);
- 2:v:=vector(s,1,t);
- 3:v:=vector(s,-1,-t);
- 4:v:=vector(s,-t,1);
- 5:v:=vector(-s,-t,-1);
- end;
- v:=vec_normalize(v);
- texdata[b,a].r:=trunc(v.x*127)+128;
- texdata[b,a].g:=trunc(v.y*127)+128;
- texdata[b,a].b:=trunc(v.z*127)+128;
- end;
- glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X_EXT+i,0,gl_rgb8,256,256,0,gl_RGB,gl_unsigned_byte,@texdata[0]);
- gltexparameteri(GL_TEXTURE_CUBE_MAP_EXT,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE_EXT);
- gltexparameteri(GL_TEXTURE_CUBE_MAP_EXT,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE_EXT);
- end;
- gldisable(GL_TEXTURE_CUBE_MAP_EXT);
- end;