2D graphics / KOS tutorials

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Fri Apr 02, 2004 9:36 am

are those functions and variables (vid_empty, vid_mode->fb_base, vid_mode->fb_count) in KOS 1.1.6, 1.1.7 or 1.1.8 or higher?
All based off 1.2.0, but they're in earlier versions as well.
b) are they in the manuals or programming examples (cuz i don't remember seeing them)?
Manuals? They're really out of date, and weren't particularly good anyway.
ok..... better yet, why is fb_size multiplied by 2 or 4 (besides the fact that it refers to two different video modes)? is fb_size in bytes, bits, or something that would make mulitplying by 2 or 4 necessary?
fb_size is in bytes. In RGB565 and RGB555 modes, each pixel takes two bytes. In RGB888 mode, each pixel takes four bytes. width * height * bytes per pixel = bytes per framebuffer.
chrishill61
DCEmu Newbie
DCEmu Newbie
Posts: 1
Joined: Fri Oct 15, 2004 11:26 am

KOS

Post by chrishill61 » Fri Oct 15, 2004 11:30 am

can someone please give me a dummies guide on how to download KOS, and how to start off.

thanks
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY

Re: KOS

Post by OneThirty8 » Fri Oct 15, 2004 5:38 pm

chrishill61 wrote:can someone please give me a dummies guide on how to download KOS, and how to start off.

thanks
I'd use a build script.
If you're using a Linux system, you should probably have what you need for the build script to work.

If you are running Windows, then you will need a Unix environment. I use cygwin. Download their installer and run it. Select a mirror, and then you'll be presented with a list of packages. Make sure you grab the base system, all of the development tools, and wget.

Then, whether on Linux or Windows, you should be able to use a build script. (if on Windows, you'll have to start up cygwin. There should be a shortcut on your desktop.) I've used BlackAura's build script.

http://files.frashii.com/~sp00nz/Doom/f ... c_build.sh

There is also DCFreeDev. I've not used it myself, but it's another option for those on Windows. You can find it at http://www.dchomebrew.org/dcfreedev.shtml
bender
Mental DCEmu
Mental DCEmu
Posts: 399
Joined: Sun May 12, 2002 4:18 pm

Post by bender » Fri Oct 15, 2004 5:59 pm

If you want to build latest KOS SVN versions, you'll need Jim's Makefile for linux. Will do the build for you and patch it for posix like threading.
Read ATani's posts. Worked perfectly for me ;)
http://www.dcemulation.org/phpBB/viewtopic.php?t=56352
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY

Post by OneThirty8 » Fri Oct 15, 2004 6:13 pm

bender wrote:If you want to build latest KOS SVN versions, you'll need Jim's Makefile for linux. Will do the build for you and patch it for posix like threading.
Read ATani's posts. Worked perfectly for me ;)
http://www.dcemulation.org/phpBB/viewtopic.php?t=56352
OK... use that build script. You'll still need to make sure you've got the developer tools and wget in order for it to work, though.

<me needs to build new toolchain.>

*edit* err... does that build script download everything, or just compile it for you? I linked to BA's script because it'll download GCC, binutils, newlib, and KOS 1.2.0 for you and then compile everything.
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Contact:

Post by GPF » Fri Oct 15, 2004 8:58 pm

no you have to download everything yourself, I used Jim script to build gcc 3.4.2 with posix threads under cygwin.
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Contact:

Post by GPF » Sat Jan 01, 2005 9:44 pm

Hey I was using your example5 and trying to edit the video.c file so it would double the graphic size

Code: Select all

void image_draw_key_dbl(kos_img_t *image, int x, int y, uint16 key)
{
	uint16 *src, *src_start;
	uint16 *dst, *dst_start;
	int drawW, drawH;
	int startX, endX;
	int startY, endY;

	if(!image)
		return;

	/* Find the starting coordinates, and abort if off screen */
	startX = MAX(x, 0);
	if(startX >= vid_mode->width)
		return;

	startY = MAX(y, 0);
	if(startY >= vid_mode->height)
		return;

	/* Find the ending coordinates */
	endX = MIN(x + image->w, vid_mode->width);
	if(endX <= 0)
		return;

	endY = MIN(y + image->h, vid_mode->height);
	if(endY <= 0)
		return;

	/* Width, height */
	drawW = (endX - startX);
	drawH = (endY - startY)-1;

	/* Starting location for the source and destination */
	src_start = (uint16 *)image->data;
	dst_start = backbuffer_s + startX + (startY * vid_mode->width);

	/* If we're off the screen, adjust the start position */
	if(x < 0)
		src_start += -x;
	if(y < 0)
		src_start += (-y * image->w);

	/* Draw the image */
	while(drawH--)
	{
		int dw = drawW;

		/* Copy the current image source, and nudge it down one line */
		src = src_start;
		dst = dst_start;
		
		src_start += image->w;
		dst_start += vid_mode->width;

		/* Draw the line */
		while(dw--)
		{
			/* Skip transparent pixels */
			if(*src == key)
			{
				*dst++;
				*dst++;
				*src++;
			}
			else
			{
				*dst++ = *src;
				*dst++ = *src++;
			}
		}
		dw = drawW;

		/* Copy the current image source, and nudge it down one line */
		src = src_start;
		dst_start += vid_mode->width;
		dst = dst_start;

		/* Draw the line */
		while(dw--)
		{
			/* Skip transparent pixels */
			if(*src == key)
			{
				*dst++;
				*dst++;
				*src++;
			}
			else
			{
				*dst++ = *src;
				*dst++ = *src++;
			}
		}
	}
}
This is what I used, it mostly works but some graphics look like they are interlaced when it draws them, am I missing something or is this a limitation of doubling a graphic this way.

Thanks,
Troy
User avatar
mankrip
DCEmu Ex-Mod
DCEmu Ex-Mod
Posts: 3696
Joined: Sun Nov 04, 2001 5:12 pm
Contact:

Post by mankrip » Sun Jan 02, 2005 1:11 am

OneThirty8 wrote:you should be able to use a build script. (...) I've used BlackAura's build script.

http://files.frashii.com/~sp00nz/Doom/f ... c_build.sh
OneThirty8 wrote:
bender wrote:If you want to build latest KOS SVN versions, you'll need Jim's Makefile for linux. Will do the build for you and patch it for posix like threading.
Read ATani's posts. Worked perfectly for me ;)
http://www.dcemulation.org/phpBB/viewtopic.php?t=56352
OK... use that build script. You'll still need to make sure you've got the developer tools and wget in order for it to work, though.

*edit* err... does that build script download everything, or just compile it for you? I linked to BA's script because it'll download GCC, binutils, newlib, and KOS 1.2.0 for you and then compile everything.
GPF wrote:no you have to download everything yourself, I used Jim script to build gcc 3.4.2 with posix threads under cygwin.
How can I check which versions of GCC, binutils and newlib are installed in my Linux machine, and in which directories they are? By the way, which versions of GCC, binutils and newlib are the "best" to use with KOS? And... is there anything else needed? G++ is mentioned here, but IIRC it is installed along with GCC.

I'm also a bit confused about what the word "snapshot" means. Are the downloads available at http://gamedev.allusion.net/svn/snapshots/ full versions of KOS, or are they patches/updates? And is subversion really needed?

Thanks :) .
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
Image
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Sun Jan 02, 2005 8:54 am

GPF - You're only drawing to every other scanline.

Look at the top of the loop. Specifically, this bit:

Code: Select all

                /* Copy the current image source, and nudge it down one line */
                src = src_start;
                dst = dst_start;
                src_start += image->w;
                dst_start += vid_mode->width;
That changes the pointers src_start and dst_start, to make them point at the start of the next line. You probably don't want to do that just yet, so it should be something like:

Code: Select all

                src = src_start;
                dst = dst_start;
                src_start += image->w;
Then, and the start of the next iteration:

Code: Select all

                src = src_start;
                dst = dst_start;
                src_start += image->w;
                dst_start += vid_mode->width;
The code you've got it slightly the wrong way around. You want to write the same destination line to two different source lines. The horizontal stretching appears correct though.

One other problem - you've broken the clipping code. The code is clipping the image to the edge of the screen, and then you're doubling the size of the image. You need to change the clipping code so it clips to twice the width/height. That gets a little trickier though.

Fragger - Easiest questions first...

A snapshot is a copy of KOS that's been generated from the SVN repository at a moment in time. Kinda like a photograph, hence the term "snapshot". Yes, it is a bit of a silly name, but there you go. You can just use one of those snapshots, and you won't need Subversion (unless you want the absolute latest up-to-the-minute version, or want to contribute to KOS itself).

G++ (the C++ compiler from GCC) is included with GCC. Any recent-ish DC toolchain has it.

As for where they are... That depends. Assuming you run some kind of script file (like environ.sh or something) to compile DC stuff, the path to the compilers should be in there somewhere.

Once you've found them, you can get the version of GCC and binutils like this:

Code: Select all

/path/to/sh-elf-gcc --version
/path/to/sh-elf-as --version
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Contact:

Post by GPF » Sun Jan 02, 2005 11:13 pm

Code: Select all

void image_draw_key_dbl(kos_img_t *image, int x, int y, uint16 key)
{
	uint16 *src, *src_start;
	uint16 *dst, *dst_start;
	int drawW, drawH;
	int startX, endX;
	int startY, endY;

	if(!image)
		return;

	/* Find the starting coordinates, and abort if off screen */
	startX = MAX(x, 0);
	if(startX >= vid_mode->width)
		return;

	startY = MAX(y, 0);
	if(startY >= vid_mode->height)
		return;

	/* Find the ending coordinates */
	endX = MIN(x + image->w, vid_mode->width);
	if(2*endX <= 0)
		return;

	endY = MIN(y + image->h, vid_mode->height);
	if(2*endY <= 0)
		return;

	/* Width, height */
	drawW = (endX - startX);
	drawH = (endY - startY)-1;

	/* Starting location for the source and destination */
	src_start = (uint16 *)image->data;
	dst_start = backbuffer_s + startX + (startY * vid_mode->width);

	/* If we're off the screen, adjust the start position */
	if(x < 0)
		src_start += -x;
	if(y < 0)
		src_start += (-y * image->w);

	/* Draw the image */
	while(drawH--)
	{
		int dw = drawW;

		/* Copy the current image source, and nudge it down one line */
		src = src_start;
		dst = dst_start;
		
		src_start += image->w;
		dst_start += vid_mode->width;

		/* Draw the line */
		while(dw--)
		{
			/* Skip transparent pixels */
			if(*src == key)
			{
				*dst++;
				*dst++;
				*src++;
			}
			else
			{
				*dst++ = *src;
				*dst++ = *src++;
			}
		}
		dw = drawW;

		/* Copy the current image source, and nudge it down one line */
		src = src_start;
		dst = dst_start;
		dst_start += vid_mode->width;

		/* Draw the line */
		while(dw--)
		{
			/* Skip transparent pixels */
			if(*src == key)
			{
				*dst++;
				*dst++;
				*src++;
			}
			else
			{
				*dst++ = *src;
				*dst++ = *src++;
			}
		}
	}
}
Thanks BA, here is the above version that worked for what I needed. So i didn't realy test the bounding code.

Only question I have now unrelated to the above is.

If I load one image, how can I blit only part of that image? like for fonts or sprite tiles?

Thanks,
Troy
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Mon Jan 03, 2005 6:58 am

If I load one image, how can I blit only part of that image? like for fonts or sprite tiles?
Err... That starts getting kinda complex.

Basically, you need to have a look at the clipping code. See how it can already draw only a part of the image? You need to do pretty much the same thing - change the start point, and the number of pixels / scanlines to copy.

Think of it this way - instead of clipping to the edge of the window, you're clipping to the coordinates you want to draw.

Just don't ask how to flip images. That's pretty hard, mostly because the clipping code becomes nightmarishly complex.
ATani
DCGen Creator
DCGen Creator
Posts: 66
Joined: Sat Jan 19, 2002 12:54 am
Location: Near Yosemite, CA
Contact:

Post by ATani » Mon Jan 03, 2005 10:39 am

BlackAura wrote:Just don't ask how to flip images. That's pretty hard, mostly because the clipping code becomes nightmarishly complex.
How is flipping complex? You basically modify the logic for moving between lines (depending on flip orientation) and the starting point for source/dest.

Its rather simple actually..

Mike
q_006
Mental DCEmu
Mental DCEmu
Posts: 415
Joined: Thu Oct 10, 2002 7:18 pm
Contact:

Post by q_006 » Mon Jan 03, 2005 12:45 pm

a litte explanation please? :mrgreen:
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Contact:

Post by GPF » Mon Jan 03, 2005 5:20 pm

Basically, you need to have a look at the clipping code. See how it can already draw only a part of the image? You need to do pretty much the same thing - change the start point, and the number of pixels / scanlines to copy.

Think of it this way - instead of clipping to the edge of the window, you're clipping to the coordinates you want to draw.
Thanks that was just what I needed to figure this out .

Troy
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Tue Jan 04, 2005 4:01 am

How is flipping complex? You basically modify the logic for moving between lines (depending on flip orientation) and the starting point for source/dest.
Simply because the code for clipping the image to the edge of the screen becomes... somewhat difficult to explain. It's not actually difficult, but you end up with a bit of code about three times the length of the non-clipping variety, or even longer if you have the partial-drawing code in there as well, with a huge number of almost incomprehensible if's and calculations. Basically, it's just me being too lazy to explain exactly how to do it. And I couldn't get it to work properly...

Actually drawing a flipped image is a piece of cake, of course.

GPF - One other thing... Why do you want to draw part of an image? There's very little point in storing all your images inside one larger image, unless you have some kind of limitation on the image sizes (say, you're using 3D hardware an can only use power-of-two textures) and your images can be packed into a large image more efficiently. In this case, simply storing separate images wouldn't use much (if any) more memory.
User avatar
toastman
Iron Fist of Justice
Iron Fist of Justice
Posts: 4933
Joined: Sat Nov 10, 2001 3:08 am
Location: New Orleans
Contact:

Post by toastman » Tue Jan 04, 2005 8:27 am

How about you draw the screen normally to an intermediate texture, then draw that one flipped.
No signature.
GPF
DC Developer
DC Developer
Posts: 529
Joined: Wed Oct 17, 2001 7:44 pm
Location: Texas
Contact:

Post by GPF » Wed Jan 05, 2005 3:58 pm

GPF - One other thing... Why do you want to draw part of an image? There's very little point in storing all your images inside one larger image, unless you have some kind of limitation on the image sizes (say, you're using 3D hardware an can only use power-of-two textures) and your images can be packed into a large image more efficiently. In this case, simply storing separate images wouldn't use much (if any) more memory.
Cool, didn't realize that. I working on moving away from SDL because of its horrendous memory leaks, so im just accustomed to using tiled graphics. I found a cool little utility to split graphics up so im just loading them all in an array then I use your video code to draw everything as needed.

Troy
User avatar
mankrip
DCEmu Ex-Mod
DCEmu Ex-Mod
Posts: 3696
Joined: Sun Nov 04, 2001 5:12 pm
Contact:

Post by mankrip » Sat Jan 08, 2005 3:14 am

I have downloaded Jim Ursetto's dc-chain-0.1, gcc-3.4.1, newlib-1.12.0, binutils-2.15, and kos-snapshot-20050101. Then I removed the KOS patches (which are unnecessary in the last versions of KOS), and typed "make" without parameters in the KDE's root console (I figured it could be necessary to do this since normal users can't write files in the /usr/local dir). Everything went fine, and now I have the dirs /usr/local/dc/arm-elf and /usr/local/dc/sh-elf with some files and subdirs inside.

Now it seems that I have to edit the environ.sh file and compile KOS. Apparently what the environ.sh file does is to set the environment variables (paths, and maybe other stuff). My problem is, I got stuck in a line containing a reference to "/usr/local/dc/bin", because I don't have this directory; I only have /usr/local/dc/arm-elf and /usr/local/dc/sh-elf. Will this dir be created when I compile KOS, or should I do something else before?

I probably have no clue about what I'm doing...

BlackAura wrote:As for where they are... That depends. Assuming you run some kind of script file (like environ.sh or something) to compile DC stuff, the path to the compilers should be in there somewhere.

Once you've found them, you can get the version of GCC and binutils like this:

Code: Select all

/path/to/sh-elf-gcc --version
/path/to/sh-elf-as --version
There's something weird happening here. I open the console, go to /usr/local/dc/sh-elf/bin, and when I enter "sh-elf-gcc --version" or just "sh-elf-gcc" I get a message saying that it doesn't exist. However, the file is there. The "dir" command shows it, as well as the Konqueror's file manager. And I've tried it as a normal user, as well as a root user.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
Image
BlackAura
DC Developer
DC Developer
Posts: 9951
Joined: Sun Dec 30, 2001 9:02 am

Post by BlackAura » Sat Jan 08, 2005 3:51 am

There's something weird happening here. I open the console, go to /usr/local/dc/sh-elf/bin, and when I enter "sh-elf-gcc --version" or just "sh-elf-gcc" I get a message saying that it doesn't exist.
That's an easy one - Linux is not DOS.

In DOS, when you type the name of a command, the command interpreter checks if you've given it a full path (like C:\Stuff\OtherStuff\File.exe), and if you have it tries to run that. If it's not a full path, it will first search in the current directory, and then search all the directories in the PATH environment variable until it finds a match. It does this mostly because DOS was originally intended to run off floppy disks, so the path was mostly meaningless...

In Linux (and other Unix-like systems), when you type the name of a command, the shell checks if you've given it a full path (like /usr/local/dc/sh-elf/bin/sh-elf-gcc) and if you have it tries to run that. If it's not a full path, it searches all the directories in the PATH environment variable until it finds a match.

Notice the difference - Linux shells do not run programs from the current directory. That's mostly a security measure, to prevent a user from accidentally running a program that's in the current directory. For example, you could put a fake version of the "ls" command in your home directory, and as soon as someone tries to list the contents of your home drive (most likely the root user, since nobody else can even get into your home directory), your program could do massive damage. Like wipe out the entire system.

So, if you want to run a program from inside the current directory, do this:

Code: Select all

./programname
The ./ tells the shell that the program is in the current directory. Alternatively, just give the whole path to the program.
My problem is, I got stuck in a line containing a reference to "/usr/local/dc/bin", because I don't have this directory; I only have /usr/local/dc/arm-elf and /usr/local/dc/sh-elf. Will this dir be created when I compile KOS, or should I do something else before?
What kind of line is it? If it's something like:

Code: Select all

PATH=$PATH:/usr/local/dc/bin
then you should change it to something like this:

Code: Select all

PATH=$PATH:/usr/local/dc/sh-elf/bin:/usr/local/dc/arm-elf/bin
.

For almost anything else (like KOS_CC_BASE, or something), they you need to change it to either sh-elf/bin or arm-elf/bin, depending on which compiler it's referencing.
User avatar
mankrip
DCEmu Ex-Mod
DCEmu Ex-Mod
Posts: 3696
Joined: Sun Nov 04, 2001 5:12 pm
Contact:

Post by mankrip » Sat Jan 08, 2005 9:00 pm

BlackAura wrote:That's an easy one - Linux is not DOS.
:lol:
BlackAura wrote:What kind of line is it? If it's something like:

Code: Select all

PATH=$PATH:/usr/local/dc/bin
then you should change it to something like this:

Code: Select all

PATH=$PATH:/usr/local/dc/sh-elf/bin:/usr/local/dc/arm-elf/bin
For almost anything else (like KOS_CC_BASE, or something), they you need to change it to either sh-elf/bin or arm-elf/bin, depending on which compiler it's referencing.
It's this line:

Code: Select all

# Expand PATH (comment out if you don't want this done here)
export PATH="${PATH}:${KOS_CC_BASE}/bin:/usr/local/dc/bin"
I changed it to:

Code: Select all

# Expand PATH (comment out if you don't want this done here)
export PATH="${PATH}:${KOS_CC_BASE}/bin:${DC_ARM_BASE}/bin"
#/usr/local/dc/bin"
I got it working now, thank you very much BA :D.
Ph'nglui mglw'nafh mankrip Hell's end wgah'nagl fhtagn.
==-=-=-=-=-=-=-=-=-=-==
Dev blog / Twitter / YouTube
Image
Post Reply