Original Post
It's been a long time since I've posted to GD.net, and I feel that I've developed a lot as a programmer... HOWEVER, I've been trying to extend my 2D engine to work with directdraw as well as openGL, and I'm running into some issues. Now, the problem is really just loading graphics onto a DDS... Before I had known about the lPitch variable, it seemed like I was able to load the full graphic onto the surface, except it would be tinted with the first color of the RGBA int, so everything would be tinted red for example. After reading up a bit more, I would get the right colors... but something horrible!! It only seemed to fill about 1/4 of the surface!!
as demonstrated here... It really baffles me, I don't understand why. So I was hoping someone with more DirectDraw experience could shed some light on this for me, I would be most grateful. PS Yes i have read the articles on loading images in DDraw and what not, I found them very informative, but rereading them again and again havn't been much help to me on this. Here is my "loading image into DDS" code, currently : In the above, the imgload struct is just a struct with the height and width of the image, the BPP and a pointer to the data, it gets filled by functions which are modified from imlib2, and work reliably in OpenGL, so I'm not convinced that the problem is in that area. Thanks in advance for helping.
as demonstrated here... It really baffles me, I don't understand why. So I was hoping someone with more DirectDraw experience could shed some light on this for me, I would be most grateful. PS Yes i have read the articles on loading images in DDraw and what not, I found them very informative, but rereading them again and again havn't been much help to me on this. Here is my "loading image into DDS" code, currently :
int img_to_dds ( struct s_imgload *load, struct s_image *img )
{
DDSURFACEDESC ddsd;
int i = 0;
int x, y, p;
int pixels, px;
//DATA8 *pixelptr;
//DATA32 *pixel;
DATA8 *pixel;
unsigned int *lpscreen;
memset( &ddsd, 0, sizeof(ddsd) );
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT |DDSD_WIDTH;
ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_VIDEOMEMORY;
ddsd.dwWidth = load->w;
ddsd.dwHeight = load->h;
if (IDirectDraw_CreateSurface( DDRAW, &ddsd, &img->surface, NULL) != DD_OK)
return FALSE;
IDirectDrawSurface_Lock( img->surface, NULL, &ddsd, NULL, NULL );
pixel = (DATA8 *)ddsd.lpSurface;
p = ddsd.lPitch ;
pixels = load->w * load->h;
for ( y=0;y<load->h;y++ )
for ( x=0;x<load->w;x++, i++ )
{
int c;
int r,g,b,a,cr,cb,cg,ca, rgb;
rgb = 255;
c = (DATA32)load->data;
READ_RGBA( &c, cr, cg, cb, ca );
//pixel = x+y * p;
r = ( cr * ( 1 << r_bits )) / 256;
g = ( cg * ( 1 << g_bits )) / 256;
b = ( cb * ( 1 << b_bits )) / 256;
a = ( ca * ( 1 << a_bits )) / 256;
// Convert the Values to the appropriate Location in the returned colour value
r <<= r_low;
g <<= g_low;
b <<= b_low;
a <<= a_low;
rgb = r | g | b | a;
//pixel[x + y] = rgb;
pixel[x+y*p] = rgb;
//pixel[x+y*p] = 255;
//memset ( pixel, rgb, 4 );
}
IDirectDrawSurface_Unlock ( img->surface, NULL );
return TRUE;
}