• Advertisement

Archived

This topic is now archived and is closed to further replies.

screwy graphics problem

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

ok, i finally got it to work but the screen is all screwy looking and im not sure whats goin on
  
	lpddsback->Lock(NULL,&ddsd, DDLOCK_SURFACEMEMORYPTR | DDLOCK_WAIT,NULL);
	// get video pointer to primary surfce

	DWORD *image_buffer = (DWORD *)ddsd.lpSurface;       

	if (ddsd.lPitch  == WWIDTH)
	{
		memset(image_buffer,0,WWIDTH*WHEIGHT);
	}
	else
	{
		DWORD *destptr = image_buffer;
		for (int y=0;y<WHEIGHT;y++)
		{
			memset(destptr,0,WWIDTH);
			destptr += ddsd.lPitch;
		}
	}
	if (FAILED(lpddsback->Unlock(NULL)))
	return 0;
		drawmap();

		lpddsprimary->Flip(NULL, DDFLIP_WAIT);
	return 1;
  

Share this post


Link to post
Share on other sites
Advertisement
1) instead of doing all that crap with filling the back buffer with 0''s, just do a black colorfill like so:
DDBLTFX ddbltfx;
memset(&ddbltfx, 0, sizeof(ddbltfx);
ddbltfx.dwSize = sizeof(ddbltfx);
ddbltfx.dwFillColor = 0;
lpddsback->Blt(0, 0, 0, DDBLT_COLORFILL|DDBLT_WAIT, &ddbltfx);

2) you''re problem is probably in the drawmap() function, so without that you won''t get much help

Share this post


Link to post
Share on other sites
well here is my drawmap function, also your code above doesnt correct the problem so im not sure. i got the program to work semi-correct just that the images im trying to display are all the same and they are distorted. i also included my bitmap function im not sure if that is causing the problem either.

      
void drawmap()
{
int x=0,y=0,cntr,sx=0,sy=0;

for (cntr=1;cntr<21;cntr++)
{
for (x=0;x<=7;x++)
{
for (y=0;y<=13;y++)
{
if (map.maplayer1[x][y]==cntr)
bltsprite(offsurface,sx,sy,x*16,y*16;
}
}
}
}
int bltsprite(LPDIRECTDRAWSURFACE7 lpddstemp, int sx, int sy,int dx, int dy)
{

RECT src_rect,dst_rect;

src_rect.top = (sy*16);
src_rect.left = (sx*16);
src_rect.right = (sx*16)+16;
src_rect.bottom = (sy*16)+16;


dst_rect.top = dy;
dst_rect.left = dx;
dst_rect.right = dx+16;
dst_rect.bottom = dy+16;


// blt to destination surface

if (FAILED(lpddsback->Blt(&dst_rect,lpddstemp,&src_rect,DDBLT_WAIT,NULL)))
return(0);
return 1;
}
int loadbitmap(BITMAPFILEPTR bitmap, char *filename)
{
// this function opens a bitmap file and loads the data into bitmap


int file_handle, // the file handle

index; // looping index


UCHAR *temp_buffer = NULL; // used to convert 24 bit images to 16 bit

OFSTRUCT file_data; // the file data information


// open the file if it exists

if ((file_handle = OpenFile(filename,&file_data,OF_READ))==-1)
return(0);

// now load the bitmap file header

_lread(file_handle, &bitmap->bitmapfileheader,sizeof(BITMAPFILEHEADER));

// test if this is a bitmap file

if (bitmap->bitmapfileheader.bfType!=BITMAP_ID)
{
// close the file

_lclose(file_handle);

// return error

return(0);
} // end if


// now we know this is a bitmap, so read in all the sections


// first the bitmap infoheader


// now load the bitmap file header

_lread(file_handle, &bitmap->bitmapinfoheader,sizeof(BITMAPINFOHEADER));


// finally the image data itself

_lseek(file_handle,-(int)(bitmap->bitmapinfoheader.biSizeImage),SEEK_END);

// now read in the image, if the image is 8 or 16 bit then simply read it

// but if its 24 bit then read it into a temporary area and then convert

// it to a 16 bit image


if (bitmap->bitmapinfoheader.biBitCount==8 || bitmap->bitmapinfoheader.biBitCount==16)
{
// delete the last image if there was one

if (bitmap->buffer)
free(bitmap->buffer);

// allocate the memory for the image

if (!(bitmap->buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file

_lclose(file_handle);

// return error

return(0);
} // end if


// now read it in

_lread(file_handle,bitmap->buffer,bitmap->bitmapinfoheader.biSizeImage);

} // end if

else
{
if (!(temp_buffer = (UCHAR *)malloc(bitmap->bitmapinfoheader.biSizeImage)))
{
// close the file

_lclose(file_handle);

// return error

return(0);
} // end if


// allocate final 16 bit storage buffer

if (!(bitmap->buffer=(UCHAR *)malloc(2*bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight)))
{
// close the file

_lclose(file_handle);

// release working buffer

free(temp_buffer);

// return error

return(0);
} // end if


// now read it in

_lread(file_handle,temp_buffer,bitmap->bitmapinfoheader.biSizeImage);

// now convert each 24 bit RGB value into a 16 bit value

for (index=0; index<bitmap->bitmapinfoheader.biWidth*bitmap->bitmapinfoheader.biHeight; index++)
{
// extract RGB components (in BGR order), note the scaling

UCHAR blue = (temp_buffer[index*3 + 0] >> 3),
green = (temp_buffer[index*3 + 1] >> 3),
red = (temp_buffer[index*3 + 2] >> 3);

// build up 16 bit color word

USHORT color = rgb16bit(red,green,blue);

// write color to buffer

((USHORT *)bitmap->buffer)[index] = color;

} // end for index


// finally write out the correct number of bits

bitmap->bitmapinfoheader.biBitCount=16;


} // end else


// close the file

_lclose(file_handle);

// flip the bitmap

flipbitmap(bitmap->buffer,
bitmap->bitmapinfoheader.biWidth*(bitmap->bitmapinfoheader.biBitCount/8),
bitmap->bitmapinfoheader.biHeight);

// return success

return(1);

} // end Load_Bitmap_File






Edited by - omegasyphon on February 13, 2001 1:44:43 PM

Edited by - omegasyphon on February 14, 2001 8:37:33 PM

Share this post


Link to post
Share on other sites

  • Advertisement