Oldschool Lib Drawing On Image

Discuss the development of new homebrew software, tools and libraries.

Moderators: cheriff, TyRaNiD

Post Reply
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Oldschool Lib Drawing On Image

Post by Giuliano »

I have just started to work with OSLIB and I am unable to draw to an image. I understand that the image that is drawn to must be in VRAM. Therefore I made two functions that will copy the image to VRAM, draw, and copy it back. But they don't work, I get an ugly image back with lots of lines and messed up colors. Has anyone gotten this to work ?

Here is my code

Code: Select all

void ImageFillRect(OSL_IMAGE *img,int x1,int y1,int x2,int y2,unsigned long color) {
	OSL_IMAGE *tmp;
	tmp=tmp=oslCreateImageCopy(img,OSL_IN_VRAM);
	oslSetDrawBuffer(tmp);
	oslDrawFillRect(x1,y1,x2,y2,color);
	oslCopyImage(img,tmp);	
	oslSetDrawBuffer(OSL_DEFAULT_BUFFER);	
	oslDeleteImage(tmp);
}

void DrawImageOnImage(OSL_IMAGE *srcimg, int srcX, int srcY, int width, int height, OSL_IMAGE *destimg, int destX, int destY) {
	OSL_IMAGE *tmp;
	tmp=oslCreateImageCopy(destimg,OSL_IN_VRAM);
	oslSetDrawBuffer(tmp);
	oslSetImageTileSize(srcimg,srcX,srcY,width,height);
	oslDrawImageXY(srcimg,destX,destY);
	oslCopyImage(destimg,tmp);
	oslSetDrawBuffer(OSL_DEFAULT_BUFFER);
	oslDeleteImage(tmp);
}
Edit: I am trying this on a newly created image btw. I noticed that if you clear the image (oslClearImage) first then it works. But the problem is that I want the image to be transparent everywhere besides where I draw (this will be a layer of a map) and clearing it with oslClearImage(image,RGBA(0,0,0,0)); just makes the image completely blank even after I draw on it.
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

Yes, that's a problem, drawing to an image is very limited as the alpha component is never written by the GPU.
I'm desperately trying to find a solution but nobody can help me (like in this drowning topic)
This would be so useful... :-(
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

well I kind of want the alpha component to be skipped .. but if the image is created empty and then drawn to , it's messed up .. if it is cleared first, it is okay
Brunni
Posts: 186
Joined: Sat Oct 08, 2005 10:27 pm

Post by Brunni »

When you do oslCreateImage, the resulting image is not empty, it contains random data (what was at this VRAM area before).
That includes alpha, which might be set to anything. So, if it's 0 (and it's most likely 0) this means transparent, so the pixel will not be drawn, whatever its color is. You might also have some semi-transparent pixels and so on, resulting in a messed up image. It's why you need to clear it before ;)
But maybe I misunderstood your problem?
Sorry for my bad english
Image Oldschool library for PSP - PC version released
Giuliano
Posts: 78
Joined: Tue Sep 13, 2005 10:26 am

Post by Giuliano »

That's correct .. it's just that I don't want to draw any transparent pixels anyways (using OSL_FX_FLAT) so I thought that I wouldnt be affected by that problem you posted in the other thread since the pixel should be drawn at all. I don't draw any semi-transparent pixels, it's either transparent or opaque.
Post Reply