hi all!
I write opengl demo, save tga images, my demo save is 24bit no alpha tga images, i want to my demo render 32bit alpha tga images, who can help me,how!
thanks!
environment: ms vc + mfc + opengl
my demo a part source:
//////////////////////////////////
void CMainFrame::OnRendTga()
{
int nFrames=100; /帧数/
GLubyte FBuffer = NULL; / Memory for the framebuffer /
static GLubyte magic[12]= {0,0,2,0,0,0,0,0,0,0,0,0}; / Targa header /
GLubyte info[6]; / Width and Height Targa header info /
int WinW, WinH; / Width and Height of the current window */
FILE Outfile; / The file to be written to disk /
char FileName[13]; / Name of file: SCR#####.TGA /
static int FileNum = 1; / Number to fill in ##### in FileName above */
#if (!defined(GL_BGR)) /* For compatibility with both NT and Suns /
#define GL_BGR 0x80E0
#endif
GLView_Left_Up pView=(GLView_Left_Up *)GetActiveView();
int cx=0, cy=0;
CRect rect;
pView->GetClientRect(&rect);
CSize size(rect.Width(), rect.Height());
cx=(size.cx/2)2;
cy=(size.cy/2)2;
////////////////////////////////////////////////
// glReadBuffer(GL_FRONT); / Be sure to read from the displayed window /
glPixelStorei(GL_PACK_ALIGNMENT,1);
WinW =cx; // glutGet((GLenum)GLUT_WINDOW_WIDTH); / Get dimensions of window /
WinH =cy; //glutGet((GLenum)GLUT_WINDOW_HEIGHT);
/ Allocate space for the current window’s framebuffer /
if ((FBuffer = (GLubyte )malloc(WinW * WinH * 3)) != NULL)
{
glReadBuffer(GL_BACK); //读背景缓冲
for(int i=0;i<nFrames;i++)
{
pView->DrawGL();
/ Set the name for the file and open it for writing/
sprintf(FileName,“SCR%05d.TGA”,FileNum++);
if ((Outfile = fopen(FileName,“wb”)) == NULL)
{
fprintf(stderr,"Can’t save to the file %s!
",FileName);
fflush(stderr); / Make sure output shows up /
}
else
{
/ Read the image data from the framebuffer */
glReadPixels(0,0,WinW,WinH,(GLenum)GL_RGB,GL_UNSIGNED_BYTE,FBuffer);
/* Write the new BGR framebuffer data to the Targa file */
fwrite(magic,1,sizeof(magic),Outfile); /* Header */
info[0] = (GLubyte)(WinW % 256);
info[1] = (GLubyte)(WinW / 256);
info[2] = (GLubyte)(WinH % 256);
info[3] = (GLubyte)(WinH / 256);
info[4] = 24;
info[5] = 0;
fwrite(info,1,sizeof(info),Outfile); /* Width/Height header */
fwrite(FBuffer,1,WinW*WinH*3,Outfile); /* Data */
fclose(Outfile);
}
} //end nFrames
free(FBuffer);
}
////////////////end
E-MAIL:ying7970@hotmail.com