Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/delphi/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Delphi中的OpenGL-16位纹理显示_Delphi_Opengl - Fatal编程技术网

Delphi中的OpenGL-16位纹理显示

Delphi中的OpenGL-16位纹理显示,delphi,opengl,Delphi,Opengl,我有个问题,我不知道该怎么解决。 我将一个16位单色纹理从TIFF图像加载到内存中,然后将这个纹理上传到OpenGL纹理中。它工作正常。但我想有两个参数——范围为0..65535的X1和X2整数,其中:小于X1的值表示为黑色,大于X2的值表示为白色,X1和X2之间的值被缩放为8位的位深度。 我如何使用OpenGL实现它?我用GDI制作的,但是对于高分辨率的图像,它的工作速度很慢 Delphi中有一些代码,我初始化OpenGL并加载纹理 开始时创建表单: procedure TForm1.Form

我有个问题,我不知道该怎么解决。 我将一个16位单色纹理从TIFF图像加载到内存中,然后将这个纹理上传到OpenGL纹理中。它工作正常。但我想有两个参数——范围为0..65535的X1和X2整数,其中:小于X1的值表示为黑色,大于X2的值表示为白色,X1和X2之间的值被缩放为8位的位深度。 我如何使用OpenGL实现它?我用GDI制作的,但是对于高分辨率的图像,它的工作速度很慢

Delphi中有一些代码,我初始化OpenGL并加载纹理

开始时创建表单:

procedure TForm1.FormCreate(Sender: TObject);
var
  DC:HDC;
  RC:HGLRC;
begin
  OsX:=0;
  OsY:=0;
  OsZ:=-5;
  Obrot:=0;

  // for Open GL
  DC:=GetDC(Panel1.Handle);
  SetupPixelFormat(DC);  //pixel format setting up
  RC:=wglCreateContext(DC);  //makes OpenGL window out of DC
  wglMakeCurrent(DC, RC);    //makes OpenGL window active
  GLInit; //calling opengl init
end;
设置像素格式:

procedure TForm1.setupPixelFormat(DC:HDC);
const
    pfd:TPIXELFORMATDESCRIPTOR = (
        nSize:sizeof(TPIXELFORMATDESCRIPTOR); 
        nVersion:1; 
        dwFlags:PFD_SUPPORT_OPENGL or PFD_DRAW_TO_WINDOW or PFD_DOUBLEBUFFER;
        iPixelType:PFD_TYPE_RGBA; 
        cColorBits:24; 
        cRedBits:0;
        cRedShift:0;
        cGreenBits:0; 
        cGreenShift:0; 
        cBlueBits:0;
        cBlueShift:0;
        cAlphaBits:0;
        cAlphaShift:0;
        cAccumBits: 0;
        cAccumRedBits: 0; 
        cAccumGreenBits: 0;
        cAccumBlueBits: 0;
        cAccumAlphaBits: 0; 
        cDepthBits:16; 
        cStencilBits:0; 
        cAuxBuffers:0; 
        iLayerType:PFD_MAIN_PLANE; 
        bReserved: 0;
        dwLayerMask: 0; 
        dwVisibleMask: 0;
        dwDamageMask: 0; 
   );
var
  pixelFormat : integer;
begin
  pixelFormat := ChoosePixelFormat(DC, @pfd);
  if (pixelFormat = 0) then exit;
  if (SetPixelFormat(DC, pixelFormat, @pfd) <> TRUE) then exit;
end;
创建纹理:

function TForm1.CreateTexture(Width,Height:Word;pData:Pointer):Cardinal;
Begin
  glGenTextures(1, Texture);
  glBindTexture(GL_TEXTURE_2D, Texture);
  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

  Result:=gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE16, Width, Height, GL_LUMINANCE, GL_UNSIGNED_SHORT, pData); //putting an loaded 16-bit image into opengl texture

end;
图纸:

procedure TForm1.Draw();
begin
  Application.ProcessMessages;

  glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT);
  glLoadIdentity();

  glTranslatef(OsX,0,0);
  glTranslatef(0,OsY,0);
  glTranslatef(0,0,OsZ);

  glRotate(Obrot,0,1,0);

  glEnable(GL_CULL_FACE);
  glEnable(GL_TEXTURE_2D);

  glTexGenf(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
  glTexGenf(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);


  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);


  glBindTexture(GL_TEXTURE_2D, Texture);

  glBegin(GL_QUADS);
    // Front Face
    glTexCoord2f(0.0, 0.0); glVertex3f(-1.0, -1.0,  0.0);
    glTexCoord2f(1.0, 0.0); glVertex3f( 1.0, -1.0,  0.0);
    glTexCoord2f(1.0, 1.0); glVertex3f( 1.0,  1.0,  0.0);
    glTexCoord2f(0.0, 1.0); glVertex3f(-1.0,  1.0,  0.0);
  glEnd();

  SwapBuffers(wglGetCurrentDC);
end;
感谢您的建议:

有一部分GDI图纸使用图形32和扫描线:

TablicaRozmiar(ai_TablicaDraw,Szer,Wys); //getting Width and Height of data
Bitmapa.Width:=Szer; //setting up virtual TBitmap32 Width
Bitmapa.Height:=Wys; //setting up virtual TBitmap32 Height
KolorMakeTable; //making a table of colour - scalling from 16bit to 8 bit display, using X1 and X2 values
For i:=0 to Wys-1 do //making a scanline
Begin
  abi_Punkty:=Bitmapa.ScanLine[i]; //abi_Punkty:PColor32Array
  For j:=0 to Szer-1 do
  Begin
    abi_Punkty[j]:=((KolorTableR[ai_TablicaDraw.Dane[j,i]] shl 8) + KolorTableG[ai_TablicaDraw.Dane[j,i]]) shl 8 + KolorTableB[ai_TablicaDraw.Dane[j,i]]; //putting a grayscale color
  End;
End;

我没有找到一个代码,你目前正在使用缓慢的一个?我已经把所有的代码张贴。所以我想知道你怎么看不到代码?我想adlabac是指你写的GDI版本。哦,我理解错了。。。GDI方法很困难,有两个线程:一个用于迷你地图,另一个用于全尺寸图像。它基于图形32和扫描线。我想让它更快,我认为这只是一种方法-OpenGL。。。但是怎么做呢?嗯,扫描线很好。你确定它不能被优化吗?你能发布那段代码吗?
TablicaRozmiar(ai_TablicaDraw,Szer,Wys); //getting Width and Height of data
Bitmapa.Width:=Szer; //setting up virtual TBitmap32 Width
Bitmapa.Height:=Wys; //setting up virtual TBitmap32 Height
KolorMakeTable; //making a table of colour - scalling from 16bit to 8 bit display, using X1 and X2 values
For i:=0 to Wys-1 do //making a scanline
Begin
  abi_Punkty:=Bitmapa.ScanLine[i]; //abi_Punkty:PColor32Array
  For j:=0 to Szer-1 do
  Begin
    abi_Punkty[j]:=((KolorTableR[ai_TablicaDraw.Dane[j,i]] shl 8) + KolorTableG[ai_TablicaDraw.Dane[j,i]]) shl 8 + KolorTableB[ai_TablicaDraw.Dane[j,i]]; //putting a grayscale color
  End;
End;