尝试获取bmp来包装对象(柱面)。我有一个非图像纹理来包装 圆筒,但当我试图用图像做同样的事情时,它就出来了 用模糊/白色电视屏幕黑白两色?我将发布我已经改变的内容以尝试让bmp工作。希望我能得到一些答案:d
首先,我需要一个24位真彩色256x256图像。我在Paint中创建了这个 将其大小调整为256像素乘256像素并保存为24位(.bmp)
第二个是界面部分。因为它有一些类型和const可能会有所帮助 把这个想出来(解决;计算出;弄明白。在这里我添加了类型RTGB,和TWrap以及var wapper。也 因为24位窗口bmp文件没有alpha,所以使得Const“ColorComps = 3”而不是4 零件。这是界面,因为它可能会有所帮助。但我认为问题在于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;
接下来我添加了ReadBitmap(我认为我的问题就在这里)。 该怎么办.. 打开指定文件,获取文件大小并减去标题大小以获取实际位图的大小。然后它读取文件头并检查有效的位图签名。接下来,该函数读取信息标题并提取宽度和高度(以像素为单位),它通过var参数与调用者通信
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;
最后,我为oncreate事件添加了一些更新。 var sWidth和tHeight 它应该从读取位图函数获得宽度/高度。和openGL命令 包装
Wrapper := ReadBitmap('SomeImage.bmp',sWidth,tHeight);
glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGB,GL_UNSIGNED_BYTE,Wrapper);
freemem(Wrapper);
现在看起来像
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;
答案 0 :(得分:0)
glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGBA,GL_UNSIGNED_BYTE,Wrapper);
要
glTexImage2D(GL_TEXTURE_2D,Level,ColorComps,sWidth,tHeight,Border,GL_RGB,GL_UNSIGNED_BYTE,Wrapper);
刚从GL_RGB中取出A