Trying to get an bmp to wrap an object (cylinder). I got an non image texture to wrap the
cylinder, but when i tried to do the same with an image it comes out
with a fuzzy/white tv screen black and white color to it? I am going to post what i had changed to try and get bmp to work. Hopefully i can get some answers :d
First I needed a 24 bit true color 256×256 image. I created this in Paint
resized it to 256 pixels by 256 pixels and saved as 24 bit (.bmp)
Second here is the interface part. As it has a few types and const that may help
figure this out. In this i added the type RTGB, and TWrap along with the var wapper. Also
made Const “ColorComps=3” instead of 4 due to 24 bit windows bmp file has no alpha
component. This is the interface , as it might help. But i think the issue is with the function readbitmap.
unit zap1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls,opengl,shapes, Vcl.Forms, Vcl.Dialogs, Transfrm, cOpenGL;
type
TTexe13=packed record
red,
green,
blue: GLubyte;
end;
TTexe14=packed record
red,
green,
blue,
alpha: gLubyte;
end;
TForm2 = class(TForm)
OpenGL1: TOpenGL;
Transform1: TTransform;
procedure FormCreate(Sender: TObject);
procedure FormResize(Sender: TObject);
procedure FormPaint(Sender: TObject);
procedure Transform1Paint(Sender: TObject);
procedure CylinderT(sTex,tTex:glFloat);
private
{ Private declarations }
deltax,
deltaY,
deltaZ:GLfloat;
procedure idle(Sender:TObject;var Done:boolean);
public
{ Public declarations }
Function ReadBitmap(const FilePath:string;var sWidth,tHeight:glsizei):pointer;
end;
var
Form2: TForm2;
const
Level=0;
Border=0;
ColorComps=3;
type
TRGB=packed record
r,g,b: byte;
end;
TWrap=array[0..0] of TRGB;
var
Wrapper: pointer;
Next i added the ReadBitmap (which i think my problem lies here).
What it should do..
Opens the designated file, gets the file size and subtracts the header sizes to obtain the size of the actual bitmap. Then it reads the file header and checks for a valid bitmap signature. Next the function reads the info header and extracts the width and height in pixels, which it communicates to the caller via the var parameters
finally it allocates the required memory and asigns the bimap into that memory. the function then returns a pointer to the memory containing the raw true-color bitmap. Then at the end i added a pixel-flipping loop. due to openGL uses RGB and windows BGR.
Function TForm2.ReadBitmap(const FilePath:String;var sWidth,tHeight:GLsizei):pointer;
const
szh=SizeOf(TBitmapFileHeader);
szi=SizeOf(TBitmapInfoHeader);
var
bmpfile: file;
bfh:TBitmapFileHeader;
bmi:TBitmapInfoHeader;
t:byte;
x,
fpos,
size: integer;
begin
assignfile(bmpfile,FilePath);
reset(bmpfile,1);
size := FileSize(bmpfile)-szh-szi;
blockread(bmpfile,bfh,szh);
if bfh.bfType<>$4D42 then
raise EinvalidGraphic.Create('Invalid Bitmap');
blockread(bmpfile,bmi,szi);
with bmi do
begin
sWidth := biWidth;
tHeight := biHeight;
end;
getmem(result,size);
blockread(bmpfile,result^,size);
for x := 0 to sWidth*tHeight-1 do
with TWrap(result^)[x] do
begin
t := r;
r := b;
b := t;
end;
end;
last of all i added a few updates to oncreate event. the var sWidth and tHeight
which should get the width / height from the read bitmap function. and the openGL command
for wrapping
Wrapper := ReadBitmap('SomeImage.bmp',sWidth,tHeight);
glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGB,GL_UNSIGNED_BYTE,Wrapper);
freemem(Wrapper);
WHich now looks like
procedure TForm2.FormCreate(Sender: TObject);
var
swidth,
theight: GLsizei;
begin
glPixelStorei(GL_UNPACK_ALIGNMENT,1);
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);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST);
Wrapper := ReadBitmap('Fig11-11.bmp',sWidth,tHeight);
glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGBA,GL_UNSIGNED_BYTE,Wrapper);
freemem(wrapper);
glEnable(GL_TEXTURE_2D);
glTexEnvf(GL_TEXTURE_ENV,GL_TEXTURE_ENV_MODE,GL_DECAL);
application.OnIdle := idle;
deltaX := 0.01;
deltaY := 0.01;
deltaZ := 0.01;
cylinderBase;
end;
To
just took the A out of GL_RGB