unit _Textures;

interface

Uses
  _Geometry, OpenGL, _OpenGL;

procedure Create_Dummy_Texture(var tex:Cardinal);

Var Dummy_Texture:Cardinal;

implementation

{$REGION 'Gen texture'}
function GenTexture(Var pData: Pointer;Width: LongWord;Height: LongWord; var Texture: GLuint): Boolean;
begin
  if (Assigned(pData)) then
    Result := True
  else
  begin
    Result := False;
    exit;
  end;
  glGenTextures(1, @Texture);
  glBindTexture(GL_TEXTURE_2D, Texture);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);  {Texture blends with object background}
//  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_DECAL);  {Texture does NOT blend with object background}
//  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND);  {Texture does NOT blend with object background}
//  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);  {Texture does NOT blend with object background}
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_REPEAT);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); { only first two can be used }
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); { all of the above can be used }
// gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData);
  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, Width, Height, 0, GL_RGBA, GL_UNSIGNED_BYTE, pData);  // Use when not wanting mipmaps to be built by openGL
end;

{$ENDREGION}

{$REGION 'Dummy'}
procedure Create_Dummy_Texture(var tex:Cardinal);
var
  i,j,w,h:integer;        {для циклов}
  TA:array of byte;
  S:Pointer;
begin
 w:=128;
 h:=128;
 SetLength(TA,w*h*4);
 For j:=0 to h-1 do {проходим все строки}
  For i:=0 to w-1 do {элементы в строке}
  begin
   TA[i*4+(j)*w*4+0]:=(((i div 8)+(j div 8)) mod 2)*255;
   TA[i*4+(j)*w*4+1]:=255;//(((i div 8)+(j div 8)) mod 2)*255;
   TA[i*4+(j)*w*4+2]:=(((i div 8)+(j div 8)) mod 2)*255;
   TA[i*4+(j)*w*4+3]:=255;
  end;
 S:=TA;
 GenTexture(S,W,H,tex);
end; 
{$ENDREGION}

end.
