Jump to content
  • Advertisement
Sign in to follow this  
WaterCrane

OpenGL Delphi, PNG and OpenGL

This topic is 3654 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

In your opinion, using Delphi, what would be the best method of parsing PNG image files with the intention of creating OpenGL textures out of them? I would prefer that the result didn't involve convoluted code or an external DLL, since I was planning on putting the parsing code into a utility library anyway. I'm struggling to import libPNG into Delphi because I lack the means to compile the C code into OBJ files that Delphi can read, since I cannot import a LIB file through any obvious means; the ones that Microsoft Visual C++ create are of the wrong format, and I'm having problems telling Borland's C-Builder where all the source files are located.

Share this post


Link to post
Share on other sites
Advertisement
I did find this in the past, but I disregarded it quite quickly because the licence, the Mozilla Public Licence, is incompatible with the GNU Lesser General Public Licence (which is what I was planning to release my utility library under), any advice on this front? Saying that though, the licence alone shouldn't be a reason to disregard source code, so I'll take a look.

P.S. Sorry for posting this thread under the wrong board; I've reported to a moderator to move it to a more appropriate board.

ADDENDUM: Just spotted something that I overlooked... Section 13 of the Mozilla Public Licence does allow portions of code to be linked into the GNU GPL, but I'm not certain about the GNU LGPL.

[Edited by - WaterCrane on June 15, 2008 5:14:29 PM]

Share this post


Link to post
Share on other sites
Much appreciated!

I'll start exploring GraphicEx; if I do use the code, I will give credit to the author, but exactly how much code can I use under the GNU Lesser Public Licence over the Mozilla Public Licence? Section 13 is a little vague. I will be very grateful if anyone is able to clarify for me.

Share this post


Link to post
Share on other sites
While I find out about the legal details surrounding GraphicEx, I'm wondering if it's possible to use SDL to load PNG files for OpenGL texture use. I haven't properly explored it yet, so I should probably do that before asking this question, but is it possible to use SDL for that, or is it too closely tied with DirectX (at least on Windows) for that to be practical?

ADDENDUM: I'm sorry if I appear to be a bit anti-DirectX.

Share this post


Link to post
Share on other sites
You can use the OLE IPicture to load jpg/png/bmp/gif/tga.


#include "olectl.h"
static char* LoadTexture_JPG(const char* fName,int &wid,int &hei,int &BytesPP){
//----[ read data ]-------------------------------------[
FILE* f1 = fopen(fName,"rb"); if(!f1)return 0;
fseek(f1,0,SEEK_END);
int DataSize = ftell(f1); fseek(f1,0,SEEK_SET);

HGLOBAL hGlobal = GlobalAlloc(GMEM_MOVEABLE,DataSize);
fread(GlobalLock(hGlobal),1,DataSize,f1);
GlobalUnlock(hGlobal);
fclose(f1);
//------------------------------------------------------/

LPSTREAM pstm;
CreateStreamOnHGlobal(hGlobal,1,&pstm);

IPicture* PictuBaka;
HBITMAP hBmp;
if(OleLoadPicture( pstm, DataSize,0,IID_IPicture,(LPVOID*)&PictuBaka)){
pstm->Release();
GlobalFree(hGlobal);
return 0;
}
if(PictuBaka->get_Handle((OLE_HANDLE*)&hBmp)){
PictuBaka->Release();
pstm->Release();
GlobalFree(hGlobal);
return 0;
}

BITMAP bi;
GetObject(hBmp,sizeof(BITMAP),&bi);

wid = bi.bmWidth;
hei = bi.bmHeight;
BytesPP=3;

char* data = (char*)xmalloc(wid*hei*3);


BITMAPINFOHEADER hdr1;
memset(&hdr1,0,sizeof(hdr1));

hdr1.biSize=sizeof(BITMAPINFOHEADER);
hdr1.biWidth=wid;
hdr1.biHeight=hei;
hdr1.biPlanes=1;
hdr1.biBitCount=24;
hdr1.biCompression=BI_RGB;
hdr1.biSizeImage=wid*hei*3;

HDC dc = CreateCompatibleDC(GetDC(0));
GetDIBits(dc,hBmp,0,hei,data,(LPBITMAPINFO)&hdr1,DIB_RGB_COLORS);

DeleteObject(hBmp);
DeleteObject(dc);

PictuBaka->Release();
pstm->Release();
GlobalFree(hGlobal);

//-----[ make BGR to RGB ]------------[
{
char* esi = data;
int i = wid*hei;
if(BytesPP==3){
while(i--){
char c1 = esi[0];
char c2 = esi[2];
esi[0] = c2;
esi[2] = c1;
esi+=3;
}
}
}
//------------------------------------/

return data;
}



I'm not sure how to get the alpha-channel, though.

Share this post


Link to post
Share on other sites
Uff, scratch that - the above code only loads JPG. IPicture can't handle png or even tga. GDI+ can.

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!