.


:




:

































 

 

 

 


15. OpenGL




OpenGL (Bitmap), . . , , . , . , .

OpenGL . . . OpenGL

 

glGetIntegerv(GL_MAX_TEXTURE_SIZE,@GLMaxTex),

 

GLMaxTex GLInt . glEnable glDisable c GL_TEXTURE_2D.

glTexImage2D. . LoadBmpTexture, Object Pascal, .

 

function LoadBmpTexture(xSize,ySize: GLInt;Name: string): pointer;

type

TRGB = record

r,g,b: GLUByte;

end;

PBits = ^TBits;

TBits = Array [0..0] of GLUbyte;

var

i, j: Integer;

bitmap: TBitmap;

Size: GLInt;

Bits: PBits;

begin

bitmap:= TBitmap.Create;

bitmap.LoadFromFile(Name); //

Size:= xSize*ySize*SizeOf(TRGB);

GetMem(Bits,Size);

 

//

For i:= 0 to xSize-1 do

For j:= 0 to ySize-1 do

begin

bits[(i*xSize+j)*3+0]:= GetRValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

bits[(i*xSize+j)*3+1]:= GetGValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

bits[(i*xSize+j)*3+2]:= GetBValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

end;

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,

xSize, ySize,//

0, GL_RGB, GL_UNSIGNED_BYTE, bits);

Result:=bits;

//FreeMem(bits);

bitmap.Free;

end;//function LoadBmpTexture

 

, LoadBmpTexture glTexImage2D. , R-G-B, DIB, B-G-R, , . LoadBmpTexture , TBitmap DDB DIB, RGB, :

 

For i:= 0 to xSize-1 do

For j:= 0 to ySize-1 do

begin

bits[(i*xSize+j)*3+0]:= GetRValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

bits[(i*xSize+j)*3+1]:= GetGValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

bits[(i*xSize+j)*3+2]:= GetBValue(bitmap.Canvas.Pixels[j,xSize-1-i]);

end;

 

glTexImage2D, .

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,

xSize, ySize, 0, GL_RGB,

GL_UNSIGNED_BYTE, bits

);

GL_TEXTURE_2D. . Mipmap. 0. , 1 4. . 2n+2 x Border, Border = 0 1, , , . , : GL_COLOR_INDEX, GL_RED, GL_GREEN, GL_BLUE, GL_ALPHA, GL_RGB, GL_RGBA, GL_LUMINANCE, GL_LUMINANCE_ALPHA. , : GL_UNSIGNED_BYTE, GL_BYTE, GL_BITMAP, GL_UNSIGNED_SHORT, GL_SHORT, GL_UNSIGNED_INT, GL_INT, GL_FLOAT. . bits, . ,

 

TBits = Array [0..0] of GLUbyte;

 

, . , . {$R-}. bits , Object Pascal . , .

, . . , . . s, , t, . s t 0 1.

Ship.bmp 6464 . OpenGL, OpenGL . OpenGL , , , OpenGL. .

 

 

Const

Quad: GLInt=1;//

Ship: pointer;

...

glNewList(Quad,GL_COMPILE);//

Ship:= LoadBmpTexture(64,64,'Ship.bmp');// //

glBegin (GL_QUADS);// -

glTexCoord2d (0.0, 0.0);//

glVertex3f (-8.0, -8.0, 15.0);

glTexCoord2d (1.0, 0.0); //

glVertex3f (8.0, -8.0, 22.0);

glTexCoord2d (1.0,0.8);// //

glVertex3f (8.0, 0.0, 15.0);

glTexCoord2d (0.0, 1.0);//

glVertex3f (-8.0, 8.0, 15.0);

glEnd;

glEndList;//

 

glCallList(Quad).

Quadric .

 

//

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,

64, 64, //

0, GL_RGB, GL_UNSIGNED_BYTE, Ship);

 

glEnable(GL_TEXTURE_2D);//

gluQuadricTexture(Sphere,GL_TRUE);// // Sphere

 

gluQuadricDrawStyle (Sphere, GLU_FILL);//

gluSphere(Sphere, 15.0, 24, 24);// //

 

, . .





:


: 2016-10-30; !; : 1115 |


:

:

, .
==> ...

1513 - | 1282 -


© 2015-2024 lektsii.org - -

: 0.016 .