Advertisement Jump to content
Sign in to follow this  


This topic is 3417 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey all, i did some research of how to load png files into an GL engine. and so far i found the GraphicEx that helps me with that, i was able to load the png file to the memory, convert it into the bmp image and only then load it. all goes good except the transparency part of the png file.. by converting the png to bmp, i was unable to use the transparency of the image, does i missing something? im loading pngs via TPicture class.(delphi) is there any other way to get the png into the OpenGL engine without using the bmp converting? my LoadPngTexture code: function CreateTexture(Width, Height, Format : Word; pData : Pointer) : GlUint; var Texture : GLuint; begin glGenTextures(1, Texture); glBindTexture(GL_TEXTURE_2D, Texture); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); if Format = GL_RGBA then gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Width, Height, GL_RGBA, GL_UNSIGNED_BYTE, pData) else gluBuild2DMipmaps(GL_TEXTURE_2D, 3, Width, Height, GL_RGB, GL_UNSIGNED_BYTE, pData); result :=Texture; end; function LoadPNGTexture(Filename: String; var Texture: GLuint; LoadFromResource : Boolean): Boolean; var Png:TPicture; Data : Array of LongWord; W : Integer; H : Integer; BMP : TBitmap; C : LongWord; Line : ^LongWord; begin try png := TPicture.Create; png.LoadFromFile(FileName); BMP:=TBitmap.Create; BMP.pixelformat:=pf32bit; BMP.width:=png.width; BMP.height:=png.height; BMP.canvas.draw(0,0,Png.Bitmap); SetLength(Data, Png.Width*Png.Height); BMP.AlphaFormat := afPremultiplied; BMP.Transparent := True; BMP.TransparentColor := RGB(0,0,0); BMP.TransparentMode := tmAuto; For H:=0 to Png.Height-1 do Begin Line :=BMP.scanline[Png.Height-H-1]; For W:=0 to Png.Width-1 do Begin c:=Line^ and $FFFFFF; Data[W+(H*Png.Width)] :=(((c and $FF) shl 16)+(c shr 16)+(c and $FF00)) or $FF000000; inc(Line); End; End; ImgWidth := Png.Width; ImgHeight := Png.Height; Texture := CreateTexture(Png.Width,Png.Height,GL_RGBA,Addr(Data[0]) ); Finally if bmp <> nil then FreeAndnIl(Bmp); if Png <> nil then FreeAndNil(Png); Result := True; end; end;

Share this post

Link to post
Share on other sites
oh, and.. almost forgot, this is how i using the transparency code:

if A2Button[a].Transparency = True then begin
glDisable (GL_ALPHA_TEST);
glEnable (GL_BLEND);

width := A2Button[a].Img1.Width;
Height := A2Button[a].Img1.Height;

glTexCoord2f(0, 0); glVertex3f(-width, height, 0.0);
glTexCoord2f(1, 0); glVertex3f( width, height, 0.0);
glTexCoord2f(1, -1);glVertex3f( width,-height, 0.0);
glTexCoord2f(0, -1); glVertex3f(-width,-height, 0.0);

if A2Button[a].Transparency = True then begin

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!