

![]() |
![]() |
|
|||||||
![]() |
![]() |
| Code Snippets and Tutorials The place for open source releases, great information, and tutorials written by other members. |
![]() |
|
|
LinkBack | Thread Tools |
![]() |
![]() |
|
|
#1 (permalink) |
|
rol 3905h, 8
Senior Member
Administrator ![]() ![]() Saint Join Date: Jul 2004
Location: Canada
Posts: 5,414
![]() |
You may have heard me mention this topic if you've watched my video demonstrating some of the interface innovations I've been making with StarCraft. The idea behind it is simple.
You can draw any font you like to the game screen, provided you are willing to take the time to define your font. Making a monospace font is easier, so that each letter takes up the same amount of pixels. I originally wrote this code as a proof of concept to counteract some anti-maphack implementations that could read text from client-side buffers to detect hacks. The functions listed below are what're used to draw the text. There is a front-end function, which I will demonstrate, that will convert a string you pass to it into the bitmap font. Font Drawing Functions Code:
Font_DrawCharacter proc cbuffer:DWORD,x:DWORD,y:DWORD,clr:BYTE
;//Draws the individual character maps.
pushad
mov cl, 88
mov ch, 0
xor edi, edi
mov esi, y
.while (cl != ch)
mov ebx, cbuffer
inc ebx
xor edx, edx
mov dl, ch
add ebx, edx
mov al, byte ptr [ebx]
.if (al != 0)
mov edx, x
add edx, edi
pushad
.if (al == 1)
invoke DrawBox, edx, esi, 1, 1, clr
.elseif (al == 2)
invoke DrawBox, edx, esi, 1, 1, 0
.endif
popad
.endif
inc edi
.if (edi == 8)
xor edi, edi
add esi, 1
.endif
add ch, 1
.endw
popad
ret
Font_DrawCharacter endp
Font_ConvertString proc strchar:BYTE,x:DWORD,y:DWORD,clr:BYTE
;//Converts a text byte to the appropriate font map.
mov al, strchar
mov ebx, offset char_Space
check:
mov cl, byte ptr [ebx]
.if (al == cl)
invoke Font_DrawCharacter, ebx, x, y, clr
.else
.if (cl != 0)
add ebx, 89
jmp check
.else
invoke Font_DrawCharacter, addr char_ERROR, x, y, clr
.endif
.endif
ret
Font_ConvertString endp
Font_TextOut proc tbuffer:DWORD,x:DWORD,y:DWORD,clr:BYTE
;//Organizes the character maps into lines.
LOCAL colorb:BYTE
pushad
mov eax, tbuffer
mov cl, clr
mov colorb, cl
mov ecx, x
mov edi, y
xor ebx, ebx
.while (byte ptr [eax] != 0)
.if (byte ptr [eax] > 19)
mov bl, byte ptr [eax]
pushad
invoke Font_ConvertString, bl, ecx, edi, colorb
popad
add ecx, 8
.else
.if (byte ptr [eax] == 1) || (byte ptr [eax] == 2)
mov colorb, 83
.elseif (byte ptr [eax] == 3)
mov colorb, 51
.elseif (byte ptr [eax] == 4)
mov colorb, 255
.elseif (byte ptr [eax] == 5)
mov colorb, 85
.elseif (byte ptr [eax] == 6)
mov colorb, 111
.elseif (byte ptr [eax] == 7)
mov colorb, 117
.elseif (byte ptr [eax] == 14)
mov colorb, 53
.elseif (byte ptr [eax] == 15)
mov colorb, 158
.elseif (byte ptr [eax] == 16)
mov colorb, 163
.elseif (byte ptr [eax] == 17)
mov colorb, 31
.elseif (byte ptr [eax] == 18) || (byte ptr [eax] == 19)
mov colorb, 83
.endif
.endif
inc eax
.endw
popad
ret
Font_TextOut endp
Code:
invoke Font_TextOut, CTEXT("I'm some text!"), x-coordinate, y-coordinate, color
Defining Your Font The tricky part about using bitmap fonts is that you need a way for the computer to know what shape the characters are. Since the idea is to not use any text characters to represent this, I used a series of numbers. Code:
0 - Transparent 1 - Solid color (the current font color) 2 - Black shadow Code:
char_LA db "a"
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
db 0,1,1,1,1,0,0,0
db 1,2,2,2,2,1,2,0
db 0,1,1,1,1,1,2,0
db 1,2,2,2,2,1,2,0
db 1,2,0,0,1,1,2,0
db 2,1,1,1,2,1,1,0
db 0,0,2,2,0,2,2,2
db 0,0,0,0,0,0,0,0
db 0,0,0,0,0,0,0,0
You will require my DrawBox function to use this code. |
|
|
|
![]() |
![]() |
|
Advertisement
|
|
![]() |
![]() |
|
|
#2 (permalink) |
![]() ![]() ![]() ![]() Disciple |
starcraft uses directdraw, why just hook the DD Surfaces, then u can draw anything to the screen at anytime. But them again, in masm it will take sometime . . . to programming the createDI bitmap and etc . . . but anyway good job doing it old school + drawing use front pixel by pixel is alot quick . . i remember i had to do that for D3D8/9
|
|
|
|
![]() |
![]() |
![]() |
![]() |
|
|
#3 (permalink) |
|
rol 3905h, 8
Senior Member
Administrator ![]() ![]() Saint Join Date: Jul 2004
Location: Canada
Posts: 5,414
![]() |
I prefer to reinvent the wheel and create my own drawing functions, not to rely on the DirectX libraries to do all of the heavy lifting for me. And, like you mentioned, DirectX programming is quite messy in Masm.
|
|
|
|
![]() |
![]() |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| [StarCraft] Transparent Pane Drawing (v1.15.2) | Perma | Code Snippets and Tutorials | 39 | 07-02-2008 03:47 PM |
| All times are GMT. The time now is 02:26 AM. |

