No black behind text

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
captain_squirrley

No black behind text

Post by captain_squirrley » Tue Aug 30, 2005 12:47 pm

I wan to get rid of the black behind the text while in screen 13 BUT I'm trying to not use libraries. I haven't been able to find a tutorial so could someone point me to one, or show me how to do it. Thanx for all the help!

User avatar
Michael Calkins
Veteran
Posts: 76
Joined: Tue Apr 05, 2005 8:40 pm
Location: Floresville, Texas
Contact:

Post by Michael Calkins » Tue Aug 30, 2005 1:00 pm

There is a simple option:

defint a-z
red=?
green=?
blue=?
PALETTE 0,red+green*&h100+blue*&h10000

which changes attribute 0 to whatever color you want. red, green, and blue should be values from &h0 to &h3f.

Alternately, you could write a font routine than used PUT to draw your text. Using silouettes, etc, you could even preserve the existing background, drawing your text over it.

Regards,
Michael
Bring on the Maulotaurs! oops...
I like to slay Disciples of D'Sparil...

User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened » Tue Aug 30, 2005 1:05 pm

Okay... well first you'll have to whip up your own font in a graphic editor. You'll probably want it to correspond to the ASCII character codes. Then you want to make a mask of each letter/character of your font. Then you put it on the screen, masked.

So as for actually making a PRINT routine for yourself, you'll want to set up a subroutine, something like PutText(text$). You'll also want two variables to keep track of where your x and y coordinates currently are, and if your x value gets above a certain value, it resets to 0, and y gets increased by 1.

And for getting characters out of the string that you send it, you'll have to check out some of QB's string functions like LEFT$, MID$, RIGHT$, LEN, etc.
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."

captain_squirrley

deeper explination

Post by captain_squirrley » Tue Aug 30, 2005 1:07 pm

What exactly do you mean, I'm writing my first QB RPG, and I'm working on the battle engine, I want to display the words "attack", "magic", "run", ect. Is there a way I could create a sub? and I don't want to have to redraw all the graphics just to GET and PUT text. Thanx for the help but could you explain it in a little more detail and maybe include an example subroutine.

User avatar
Michael Calkins
Veteran
Posts: 76
Joined: Tue Apr 05, 2005 8:40 pm
Location: Floresville, Texas
Contact:

Post by Michael Calkins » Tue Aug 30, 2005 1:58 pm

A demo:

Code: Select all

'Written by Michael Calkins
SCREEN 13
DEFINT A-Z 'We use INTEGERs around these parts...

DIM SHARED text(0 TO 33, 32 TO 127, 0 TO 1)

COLOR 15

'write and GET text:
FOR i = 32 TO 127
 PRINT CHR$(i);
 y = ((i - 32) \ 40) * 8
 x = ((i - 32) MOD 40) * 8
 GET (x, y)-(x + 7, y + 7), text(0, i, 0)
NEXT i

'create silouettes:
FOR x = 0 TO 319
 FOR y = 0 TO 23 'adjust this if you need more lines
  n = POINT(x, y)
  IF n = 0 THEN n = &HFF ELSE n = 0
  PSET (x, y + 100), n
 NEXT y
NEXT x

'GET silouettes:
FOR i = 32 TO 127
 y = ((i - 32) \ 40) * 8
 x = ((i - 32) MOD 40) * 8
 GET (x, y + 100)-(x + 7, y + 107), text(0, i, 1)
NEXT i

CLS     '"random" demo background:
FOR x = 0 TO 319
 FOR y = 0 TO 199
  PSET (x, y), INT(RND * 255)
 NEXT y
NEXT x


FOR i = 30 TO 129: t$ = t$ + CHR$(i): NEXT i

l = 5
c = 10
FOR i = 1 TO LEN(t$)
 n = ASC(MID$(t$, i, 1))
 IF n < 32 OR n > 127 THEN n = 32
 x = (c - 1) * 8
 y = (l - 1) * 8
 PUT (x, y), text(0, n, 1), AND
 PUT (x, y), text(0, n, 0), OR
 c = c + 1
 IF c = 41 THEN c = 1: l = l + 1
 IF l > 25 THEN l = 25
NEXT i
Regards,
Michael
Bring on the Maulotaurs! oops...
I like to slay Disciples of D'Sparil...

User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened » Tue Aug 30, 2005 7:22 pm

You won't have to redraw the graphics, just make up your own font, which isn't all that hard. If you really don't want to make your own, just make a program that prints every ASCII code in the standard QB font, and then GET each one, BSAVE it into one big file, and then you're ready to use it.

If you can't figure the PRINT stuff on your own (and yes, you've gotta make your own PRINT routine), then download PixelPlus256 and check out the usersubs.bas.
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."

User avatar
Zamaster
Veteran
Posts: 174
Joined: Wed Jun 15, 2005 1:51 pm
Contact:

Post by Zamaster » Tue Aug 30, 2005 9:39 pm

Arrggghhh! I can never get to these posts in time to actually type
anything usefull cause' everybody always beats me to em'! Oh yeah and
Calkins they're called "Masks" not "Silhouettes".
C:\DOS
C:\DOS\RUN
RUN\DOS\RUN

Seb McClouth

Post by Seb McClouth » Wed Aug 31, 2005 4:18 am

How can I make my own font?

I want it to use:

fontname.fnt > which contains the grpx stuff

SUB FPrint Text$, Font$, x%, y%, clr%


grtz
Seb

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Wed Aug 31, 2005 5:44 am

Well, I would reccomend bloading 1 file then putting it into a tileset, then just do some multiplycation to get the thing that you want to PUT. Also, it would be cool if you could re-load the fonts and have an ability to let the users make new fonts.
Image

Seb McClouth

Post by Seb McClouth » Wed Aug 31, 2005 8:35 am

How do I do that? Grpx not my league (yet)!

grtz
Seb

User avatar
The Awakened
Veteran
Posts: 144
Joined: Sun Aug 07, 2005 1:51 am

Post by The Awakened » Wed Aug 31, 2005 11:16 pm

Damn, looks like the site was corrupted... I HAD posted something here, but it's not here anymore.

So here I go.

Well first, you whip up a font in a graphic editor (anything that BSAVEs), I'd recommend PixelPlus 256. You're going to have all of your images saved into the same file, so in PP256, go Image...Add... 8x8 (or whatever size you want, I'd recommend 8x8), 95 more images. Then start doing your font in the order of the ASCII character codes, starting with character 32 (you don't need any of the ones before 32), so check out any ASCII lookup table.

So in your code, you set your screen mode. In this example, I'm going to use screen 13, mainly because it's the easiest to manipulate and do fast graphical stuff. It probably won't work in screen 12.

Then you make an array, called Font(however many bytes you want). Now, here's how a GETed or BSAVEd image works. The first four bytes are reserved for describing the width and the height (Andrew L. Ayers' tut on Pete's site tells ya), and then after that, comes the colour values of each pixel. Since there can be 256 different colours in the 13h palette, each colour is represented by one byte. So two pixels can be put into one QB integer. Now, if you're working with 8x8 characters, then let's do some math to see how many fonts you can put into one array (and save a helluva lot of time later):

8 bytes x 8 bytes + 4 bytes = 68 bytes per character.
68 bytes * 96 characters = 6582 bytes per font.
65536 bytes (one segment) \ 6528 bytes = just over 10. Which means we get a maximum of 10 fonts in one QB array. Of course, you probably don't need 10 8x8 fonts in a screen 13 setting, but I'm just demonstrating.

So let's think about how this is divided up. We have our large array, which is divided up into 10 fonts. Each font is divided up into 96 characters. So when we PUT it on the screen, we need to know what offset the character image is at when we PUT it. So it would look something like this:

offset = fontNumber * (68 bytes * (ASCII code - 32)

where font number is a number BETWEEN 0 AND 9! This is very important, it is NOT between 1 and 10, otherwise you'd be reading the wrong font, and if you inputted 10, you wouldn't be reading from the array anymore.

Also don't forget, that anytime I say bytes, you should divide that number by two to get the amount of QB standard integers.

So as for actually putting this into a routine... you'd have to look into QB's string manipulating functions, I can't remember most of them but I think you'll want to look into the ASC function, as well as some of the LEFT$, RIGHT$, and MID$ functions.

I'll write something tomorrow, I've gotta go to bed. :D
"Sorry for beating you up with a baseball bat Julian, but I DID think that you were a samsquanch."

User avatar
{Nathan}
Veteran
Posts: 1169
Joined: Thu Aug 19, 2004 6:08 pm
Location: The wetlands of central Ohio, USA
Contact:

Post by {Nathan} » Fri Sep 02, 2005 4:27 pm

If you want just red behind text (which I know you don't want, but it could help others) just look up COLOR in QB's online help.
Image

Post Reply