LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-06-2004, 09:48 AM   #1
BenRichards
LQ Newbie
 
Registered: May 2004
Posts: 17

Rep: Reputation: 0
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;
 
Old 10-06-2004, 01:44 PM   #2
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,571

Rep: Reputation: 180Reputation: 180
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.
 
Old 10-07-2004, 09:39 AM   #3
Marius2
Member
 
Registered: Jan 2004
Location: Munich
Distribution: SuSE 9.2, 10.2, 10.3, knoppix
Posts: 276

Rep: Reputation: 31
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
gcc floating point to normal conversion morph_ind Programming 6 09-20-2005 10:46 AM
gcc wont install, 'failed dependencies: glibc-devel is needed by gcc-3.3.3-41' TdlSnare SUSE / openSUSE 3 11-29-2004 02:13 PM
Kernel compiling: gcc-3.3 is 586, should be gcc-3.3 386 Erik Plaggenmar Linux - Software 0 10-01-2004 11:38 AM
running software built with gcc 3.0.2 on Redhat 8 - gcc 3.2 dst1989 Linux - Software 3 03-08-2004 10:23 PM
export CC=/usr/bin/gcc-3.2 - switch gcc version? ferreter Linux - Software 1 08-20-2003 12:07 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:52 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration