LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   ddraw DDSURFACEDESC2 gcc conversion (https://www.linuxquestions.org/questions/programming-9/ddraw-ddsurfacedesc2-gcc-conversion-239394/)

BenRichards 10-06-2004 09:48 AM

ddraw DDSURFACEDESC2 gcc conversion
 
Hello All,

It seems that to open DDS texture files everyones tutorials use the typedef DDSURFACEDESC2 from the ddraw.h file. I assume that DWORD is just an int but what about the rest? Has anyone already converted this structure previously so it could be used in linux without using a program such as wine? Any help you could give would be greatly appreciated.

typedef struct _DDSURFACEDESC2
{
DWORD dwSize; // size of the DDSURFACEDESC structure
DWORD dwFlags; // determines what fields are valid
DWORD dwHeight; // height of surface to be created
DWORD dwWidth; // width of input surface
union
{
LONG lPitch; // distance to start of next line (return value only)
DWORD dwLinearSize; // Formless late-allocated optimized surface size
} DUMMYUNIONNAMEN(1);
union
{
DWORD dwBackBufferCount; // number of back buffers requested
DWORD dwDepth; // the depth if this is a volume texture
} DUMMYUNIONNAMEN(5);
union
{
DWORD dwMipMapCount; // number of mip-map levels requestde
// dwZBufferBitDepth removed, use ddpfPixelFormat one instead
DWORD dwRefreshRate; // refresh rate (used when display mode is described)
DWORD dwSrcVBHandle; // The source used in VB::Optimize
} DUMMYUNIONNAMEN(2);
DWORD dwAlphaBitDepth; // depth of alpha buffer requested
DWORD dwReserved; // reserved
LPVOID lpSurface; // pointer to the associated surface memory
union
{
DDCOLORKEY ddckCKDestOverlay; // color key for destination overlay use
DWORD dwEmptyFaceColor; // Physical color for empty cubemap faces
} DUMMYUNIONNAMEN(3);
DDCOLORKEY ddckCKDestBlt; // color key for destination blt use
DDCOLORKEY ddckCKSrcOverlay; // color key for source overlay use
DDCOLORKEY ddckCKSrcBlt; // color key for source blt use
union
{
DDPIXELFORMAT ddpfPixelFormat; // pixel format description of the surface
DWORD dwFVF; // vertex format description of vertex buffers
} DUMMYUNIONNAMEN(4);
DDSCAPS2 ddsCaps; // direct draw surface capabilities
DWORD dwTextureStage; // stage in multitexture cascade
} DDSURFACEDESC2;

Mara 10-06-2004 01:44 PM

I don't know what does that structure do, but from the comments it looks it won't be that easy. If you'd like to port it to Linux, you need to find similar structures in OpenGL and use them. There will be similarities, of course, but I don't thing it's an automatic process.

Marius2 10-07-2004 09:39 AM

It's not all that complicated. What you basically need is lpSurface (ptr to
first byte of the surface), lPitch (number of bytes in a line), dwWidth
and dwHeight (vertical and horizontal extensions), and the pixel format.
BTW DWORD is an unsigned long. SDL and Xlib use a similar thing, here
you have some code which reads such data from each DDraw, SDL or
Xlib and writes it into member variables, so that

dptr=(unsigned long)this->S_SurfaceBaseAdr+dpy*this->S_Pitch+dpx*this->S_RGBByteCnt;
if(this->S_RGBByteCnt==2){pix_rgb565=this->convert_RGB32_to_RGB565(dmycolor);
*(unsigned short*)dptr=pix_rgb565;
return 0;}

if(this->S_RGBByteCnt==4){*(unsigned long*)dptr=dmycolor;
return 0;}

(sorry for the format, just straight out of MSVC editor) will set you a
single pixel in any of the libs. BTW to get a fully filled in DDSURFACEDESC2,
you need to lock/unlock the surface. From CreateSurface you will not get
the base pointer, only pixel format.


The code: (please note that the DDSURFACEDESC and similar structs in
SDL/Xlib are member variables set in other methods, so you shouldn't
wonder why I don't pass them as arguments)


void C_osi_graph_surface::get_Surface_data(){
printf("C_osi_graph_surface::get_Surface_data()\n");
int hRet=0;
unsigned short S_NumRBits,S_NumGBits,S_NumBBits;

#ifdef WINDOWS_APP
ZeroMemory(&ddsd2,sizeof(ddsd2));
ddsd2.dwSize=sizeof(ddsd2);
hRet=surface->Lock(NULL,&ddsd2,DDLOCK_NOSYSLOCK,NULL);
S_NumRBits=8-GetNumberOfBits(ddsd2.ddpfPixelFormat.dwRBitMask);
S_NumGBits=8-GetNumberOfBits(ddsd2.ddpfPixelFormat.dwGBitMask);
S_NumBBits=8-GetNumberOfBits(ddsd2.ddpfPixelFormat.dwBBitMask);

S_Pitch = ddsd2.lPitch;
S_RGBByteCnt = ddsd2.ddpfPixelFormat.dwRGBBitCount>>3;
S_SurfaceBaseAdr = (unsigned long)ddsd2.lpSurface;
hRet=surface->Unlock(NULL);

this->xres_phys=ddsd2.dwWidth;
this->yres_phys=ddsd2.dwHeight;

this->s_rbitpos=GetMaskPos(ddsd2.ddpfPixelFormat.dwRBitMask);
this->s_gbitpos=GetMaskPos(ddsd2.ddpfPixelFormat.dwGBitMask);
this->s_bbitpos=GetMaskPos(ddsd2.ddpfPixelFormat.dwBBitMask);

this->s_rbitmask=ddsd2.ddpfPixelFormat.dwRBitMask;
this->s_gbitmask=ddsd2.ddpfPixelFormat.dwGBitMask;
this->s_bbitmask=ddsd2.ddpfPixelFormat.dwBBitMask;
#endif

#ifdef LINUX_APP
#ifdef LINUX_USE_SDL
SDL_PixelFormat *pixelformat=surface->format;
this->S_SurfaceBaseAdr=(unsigned long)surface->pixels;
this->S_RGBByteCnt=(unsigned long)pixelformat->BytesPerPixel;
this->S_Pitch=(unsigned long)surface->pitch;

this->s_rbitpos=pixelformat->Rshift;
this->s_gbitpos=pixelformat->Gshift;
this->s_bbitpos=pixelformat->Bshift;

this->s_rbitmask=pixelformat->Rmask;
this->s_gbitmask=pixelformat->Gmask;
this->s_bbitmask=pixelformat->Bmask;

S_NumRBits=8-GetNumberOfBits(this->s_rbitmask);
S_NumGBits=8-GetNumberOfBits(this->s_gbitmask);
S_NumBBits=8-GetNumberOfBits(this->s_bbitmask);

this->xres_phys=surface->w;
this->yres_phys=surface->h;
#endif
#ifdef LINUX_USE_XLIB
printf("Xlib - ");
XImage *Imagedata=this->X_Windowdata.X_image;
this->S_SurfaceBaseAdr=(unsigned long)Imagedata->data;
this->S_RGBByteCnt=Imagedata->depth>>3;
this->S_Pitch=Imagedata->bytes_per_line;

this->s_rbitpos=GetMaskPos(Imagedata->red_mask);
this->s_gbitpos=GetMaskPos(Imagedata->green_mask);
this->s_bbitpos=GetMaskPos(Imagedata->blue_mask);

this->s_rbitmask=Imagedata->red_mask;
this->s_gbitmask=Imagedata->green_mask;
this->s_bbitmask=Imagedata->blue_mask;

S_NumRBits=8-GetNumberOfBits(this->s_rbitmask);
S_NumGBits=8-GetNumberOfBits(this->s_gbitmask);
S_NumBBits=8-GetNumberOfBits(this->s_bbitmask);

this->xres_phys=Imagedata->width;
this->yres_phys=Imagedata->height;
#endif
#endif

//00000000bbbbbbbbggggggggrrrrrrrr
// 0bbbbbgggggrrrrr
if(this->s_bbitpos>this->s_rbitpos){this->is_bgr_surface=true;}

if(this->is_bgr_surface==false){this->s_rbitshft=S_NumBBits+S_NumGBits+S_NumRBits;
this->s_gbitshft=S_NumBBits+S_NumGBits;
this->s_bbitshft=S_NumBBits;}

if(this->is_bgr_surface==true){ this->s_rbitshft=S_NumRBits;
this->s_gbitshft=S_NumRBits+S_NumGBits;
this->s_bbitshft=S_NumRBits+S_NumGBits+S_NumBBits;}

this->pixelformat->p_bbitshift=this->s_bbitshft;
this->pixelformat->p_bbitmask=this->s_bbitmask;
this->pixelformat->p_gbitshift=this->s_gbitshft;
this->pixelformat->p_gbitmask=this->s_gbitmask;
this->pixelformat->p_rbitshift=this->s_rbitshft;
this->pixelformat->p_rbitmask=this->s_rbitmask;

this->xres_phys_eq_des=false;
this->yres_phys_eq_des=false;
if(this->xres_phys==this->xres_desired)this->xres_phys_eq_des=true;
if(this->yres_phys==this->yres_desired)this->yres_phys_eq_des=true;
printf("BaseAdr:%d,RGBByteCnt:%d,Pitch:%d\n",S_SurfaceBaseAdr,S_RGBByteCnt,S_Pitch);
printf("s_rbitpos/gbitpos/bbitpos:%d,%d,%d\n",this->s_rbitpos,this->s_gbitpos,this->s_bbitpos);
printf("s_rbitshft=%d,s_gbitshft=%d,s_bbitshft=%d\n",s_rbitshft,s_gbitshft,s_bbitshft);


}



HTH


All times are GMT -5. The time now is 09:07 PM.