After casting Bigby's compressing hands on my code, the result looks like a mess. The important part is just three small function though, setfontimport(), readsystemfontdata() and textout(). There are a couple of much better examples on the forum than mine. Works with or without the ogre engine. DirectX was not tested, I only use the default Opengl subsystem.
Code: Select all
EnableExplicit
DeclareModule sys
#Target_Width=1366 : #Target_Height=768 : #APP_NAME="COMMANDER 64 Print example"
#USED_CHARACTERS="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]};:',<.>/?"+Chr(34)
#ERROR_1="No valid desktop found.":#ERROR_2="Desktop resolution must be at least 1366*768."
#ERROR_3="Could not initialize the sound device.":#ERROR_4="Could not initialize the Sprite Environment."
#ERROR_5="Could not initialize the keyboard input device.":#ERROR_6="Could not initialize the mouse input device."
#ERROR_7="Could not open the graphic screen.":#ERROR_8="Could not set the 3D environment."
#c64_Color_Black=0:#c64_Color_White=1:#c64_Color_Red=2:#c64_Color_Cyan=3:#c64_Color_Violet=4:#C64_Color_Purple=4:#c64_Color_Green=5
#c64_Color_Blue=6:#c64_Color_Yellow=7:#c64_Color_Orange=8:#c64_Color_Brown=9:#c64_Color_LightRed=10:#c64_Color_DarkGrey=11
#c64_Color_Grey=12:#c64_Color_LightGreen=13:#c64_Color_LightBlue=14:#c64_Color_LightGray=15:#c64_Color_Cull=16
Structure colorstructure : r.i : g.i : b.i : a.i : EndStructure
Declare Init():Declare Update():Declare Critical_Error(message.s):Declare setfontimport():Declare readsystemfontdata()
Declare textout(x.i,y.i,text.s,color.i):Declare createC64Desktopsprite():Declare fillc64hardwarepal():Declare.i c64color(color.i)
Declare createc64mouse():Declare Predate()
Global DISPLAY_Count.i,maindisplay_h.i=0,mainwindow_h.i,c64_Cursorsprite.i,c64_desktopsprite.i,CONTROLLER_Count.i
Global c64_mousesprite.i,maincamera_h.i
Global Dim sysfont(370):Global Dim fontimport.i(370):Global Dim c64palette.colorstructure(16):Global Dim sprite2d(64,64):Global Dim spritemask2d(64,64)
EndDeclareModule
Module sys
Procedure fillc64Hardwarepal():Define j
Restore petskii_colors
For j= 0 To 16 : Read.a c64palette(j)\r : Read.a c64palette(j)\g : Read.a c64palette(j)\b : c64palette(j)\a=255 :Next j :c64palette(16)\a=0
EndProcedure
Procedure.i c64color(color.i)
If color<0 Or color>16 : ProcedureReturn RGB(0,0,0) : EndIf
ProcedureReturn RGB(c64palette(color)\r,c64palette(color)\g,c64palette(color)\b)
EndProcedure
Procedure.i c64colorAlpha(color.i)
If color<0 Or color>16 : ProcedureReturn RGBA(0,0,0,0) : EndIf
ProcedureReturn RGBA(c64palette(color)\r,c64palette(color)\g,c64palette(color)\b,255)
EndProcedure
Procedure Init()
DISPLAY_Count = ExamineDesktops(): If DISPLAY_Count<1 : Critical_Error(#ERROR_1) : EndIf
;If DesktopWidth(maindisplay_h)<#Target_Width Or DesktopHeight(maindisplay_h)<#Target_Height : Critical_Error(#ERROR_2) : EndIf
If Not InitSound(): Critical_Error(#ERROR_3):EndIf :If Not InitEngine3D() : Critical_Error(#ERROR_8):EndIf
If Not InitSprite(): Critical_Error(#ERROR_4):EndIf
If Not InitKeyboard(): Critical_Error(#ERROR_5):EndIf : If Not InitMouse(): Critical_Error(#ERROR_6):EndIf
CONTROLLER_Count=InitJoystick()
setfontimport():fillc64hardwarepal()
mainwindow_h = OpenWindow(#PB_Any,(DesktopWidth(0)-#Target_Width)*0.5,(DesktopHeight(0)-#Target_Height)*0.5,#Target_Width,#Target_Height,#APP_NAME)
If Not OpenWindowedScreen(WindowID(mainwindow_h),0,0,WindowWidth(mainwindow_h),WindowHeight(mainwindow_h),1,0,0,#PB_Screen_WaitSynchronization) : Critical_Error(#ERROR_7): EndIf
SetFrameRate(60):readsystemfontdata():createc64desktopsprite():createc64mouse()
EndProcedure
Procedure update()
DisplayTransparentSprite(c64_mousesprite,WindowMouseX(mainwindow_h),WindowMouseY(mainwindow_h))
EndProcedure
Procedure PreDate(): Define windoweventstatus.i,j.i
Repeat : windoweventstatus=WindowEvent()
If windoweventstatus=#PB_Event_CloseWindow:End:EndIf
Until windoweventstatus=0
ExamineKeyboard()
If KeyboardPushed(#PB_Key_Escape):End:EndIf
ReleaseMouse(#False)
ExamineMouse()
EndProcedure
Procedure Critical_Error(message.s) : MessageRequester("Critical Error!",message.s, #PB_MessageRequester_Error) : End : EndProcedure
Procedure setfontimport() :Define i.i : For i = 1 To Len(sys::#USED_CHARACTERS) :fontImport(Asc(Mid(sys::#USED_CHARACTERS,i,1)))=1 : Next i : EndProcedure
Procedure create_c64_cursor()
c64_cursorsprite=CreateSprite(-1,16,24,#PB_Sprite_AlphaBlending):StartDrawing(SpriteOutput(c64_cursorsprite)):Box(1,1,14,22,RGBA(255,255,255,255)):StopDrawing()
EndProcedure
Procedure readsystemfontdata() : Define sprline.a,x.i,i.i,j.i
Restore petskii_font
For x= 1 To 370
If fontimport(x)=1
sysfont(x)=CreateSprite(-1,8,12,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(sysfont(x)))
DrawingMode(#PB_2DDrawing_AllChannels)
;You can replace all these shennanigens with a single drawtext(0,0,chr(x),rgba(255,255,255,255),rgba(0,0,0,0)) using your favorite truetype font
;sprite and font sizes matter, this example has just this monospace font.
;-----------------------------------------------------------------------------------------------------------------------------------------------
For j=0 To 11
Read.a sprline
For i=0 To 7
If sprline&%1 :Plot(i,j,RGBA(255,255,255,255)): Else : Plot(i,j,RGBA(0,0,0,0)) : EndIf
sprline>>1
Next i
Next j
;-----------------------------------------------------------------------------------------------------------------------------------------------
StopDrawing()
ZoomSprite(sysfont(x),16,24)
EndIf
Next x
EndProcedure
Procedure textout(x,y,text.s,color.i) : Define.i textlength,i,character
textlength.i = Len(text.s)
For i = 1 To textlength
character.i = Asc(Mid(text.s,i,1))
If IsSprite(sysfont(character))
DisplayTransparentSprite(sysfont(character),(x+((i-1) * 16)),(y),255,color.i)
EndIf
Next i
EndProcedure
Procedure createc64desktopsprite()
c64_desktopsprite=CreateSprite(-1,#Target_Width,#Target_Height,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(c64_desktopsprite))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,#Target_Width,#Target_Height,RGBA(0,136,255,255))
Box(#Target_Height*0.1,#Target_Height*0.1,#Target_Width-(#Target_Height*0.2),#Target_Height*0.8,RGBA(0,0,0,0))
StopDrawing()
EndProcedure
Procedure createc64mouse()
c64_mousesprite=CreateSprite(-1,16,16,#PB_Sprite_AlphaBlending)
Restore mcursor_type_0:
For i=0 To 15
Read.u myunicodecharacter : Read.u myunicodecharacter2
For j =15 To 0 Step -1
sys::spritemask2d(i,j)=myunicodecharacter&%1 : sys::sprite2d(i,j)=myunicodecharacter2&%1
myunicodecharacter>>1 : myunicodecharacter2>>1
Next j
Next i
StartDrawing(SpriteOutput(c64_mousesprite))
DrawingMode(#PB_2DDrawing_AllChannels)
For i=0 To 15
For j =0 To 15
If spritemask2d(i,j)=1
Plot(i,j,c64colorAlpha(sprite2d(i,j)))
spritemask2d(i,j)=0 : sprite2d(i,j)=0
EndIf
Next j
Next i
StopDrawing()
ZoomSprite(c64_mousesprite,64,64)
SpriteQuality(0)
EndProcedure
DataSection
petskii_font:
Data.a $00,$00,$38,$38,$38,$38,$38,$38,$00,$38,$00,$00,$00,$00,$EE,$EE,$EE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$FF,$EE,$FF,$EE,$EE,$00,$00,$00,$00,$38,$38,$FC,$0E,$7C,$E0,$7E,$38,$00,$00
Data.a $00,$00,$CE,$CE,$EE,$70,$38,$1C,$EE,$E6,$00,$00,$00,$00,$7C,$7C,$EE,$7C,$3C,$EE,$EE,$FC,$00,$00,$00,$00,$E0,$E0,$70,$38,$00,$00,$00,$00,$00,$00,$00,$00,$70,$70,$38,$1C,$1C,$1C,$38,$70,$00,$00
Data.a $00,$00,$1C,$1C,$38,$70,$70,$70,$38,$1C,$00,$00,$00,$00,$00,$00,$EE,$7C,$FF,$7C,$EE,$00,$00,$00,$00,$00,$00,$00,$38,$38,$FE,$38,$38,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$38,$38,$1C,$00
Data.a $00,$00,$00,$00,$00,$00,$FE,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$38,$38,$00,$00,$00,$00,$00,$00,$C0,$E0,$70,$38,$1C,$0E,$00,$00,$00,$00,$7C,$7C,$EE,$FE,$FE,$EE,$EE,$7C,$00,$00
Data.a $00,$00,$38,$38,$38,$3C,$38,$38,$38,$FE,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$70,$1C,$0E,$FE,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$78,$E0,$EE,$7C,$00,$00,$00,$00,$E0,$E0,$F0,$F8,$EE,$FE,$E0,$E0,$00,$00
Data.a $00,$00,$FE,$FE,$0E,$7E,$E0,$E0,$EE,$7C,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$7E,$EE,$EE,$7C,$00,$00,$00,$00,$FE,$FE,$EE,$70,$38,$38,$38,$38,$00,$00,$00,$00,$7C,$7C,$EE,$EE,$7C,$EE,$EE,$7C,$00,$00
Data.a $00,$00,$7C,$7C,$EE,$EE,$FC,$E0,$EE,$7C,$00,$00,$00,$00,$38,$38,$38,$00,$00,$00,$38,$38,$00,$00,$00,$00,$38,$38,$38,$00,$00,$00,$38,$38,$1C,$00,$00,$00,$F0,$F0,$38,$1C,$0E,$1C,$38,$F0,$00,$00
Data.a $00,$00,$00,$00,$00,$FE,$00,$FE,$00,$00,$00,$00,$00,$00,$1E,$1E,$38,$70,$E0,$70,$38,$1E,$00,$00,$00,$00,$7C,$7C,$EE,$E0,$70,$38,$00,$38,$00,$00,$00,$00,$7C,$7C,$EE,$FE,$FE,$0E,$CE,$7C,$00,$00
Data.a $00,$00,$38,$38,$7C,$EE,$FE,$EE,$EE,$EE,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$EE,$EE,$7E,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$0E,$0E,$EE,$7C,$00,$00,$00,$00,$3E,$3E,$7E,$EE,$EE,$EE,$7E,$3E,$00,$00
Data.a $00,$00,$FE,$FE,$0E,$0E,$3E,$0E,$0E,$FE,$00,$00,$00,$00,$FE,$FE,$0E,$0E,$3E,$0E,$0E,$0E,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$FE,$EE,$EE,$7C,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$FE,$EE,$EE,$EE,$00,$00
Data.a $00,$00,$7C,$7C,$38,$38,$38,$38,$38,$7C,$00,$00,$00,$00,$F8,$F8,$70,$70,$70,$70,$7E,$3C,$00,$00,$00,$00,$EE,$EE,$7E,$3E,$1E,$3E,$7E,$EE,$00,$00,$00,$00,$0E,$0E,$0E,$0E,$0E,$0E,$0E,$FE,$00,$00
Data.a $00,$00,$CE,$CE,$FE,$FE,$FE,$CE,$CE,$CE,$00,$00,$00,$00,$EE,$EE,$FE,$FE,$FE,$FE,$EE,$EE,$00,$00,$00,$00,$7C,$7C,$EE,$EE,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$0E,$0E,$0E,$00,$00
Data.a $00,$00,$7C,$7C,$EE,$EE,$EE,$EE,$7C,$F0,$00,$00,$00,$00,$7E,$7E,$EE,$EE,$7E,$3E,$7E,$EE,$00,$00,$00,$00,$7C,$7C,$EE,$0E,$7C,$E0,$EE,$7C,$00,$00,$00,$00,$FE,$FE,$38,$38,$38,$38,$38,$38,$00,$00
Data.a $00,$00,$EE,$EE,$EE,$EE,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$EE,$EE,$7C,$38,$00,$00,$00,$00,$CE,$CE,$CE,$CE,$FE,$FE,$FE,$CE,$00,$00,$00,$00,$EE,$EE,$EE,$7C,$38,$7C,$EE,$EE,$00,$00
Data.a $00,$00,$EE,$EE,$EE,$EE,$7C,$38,$38,$38,$00,$00,$00,$00,$FE,$FE,$E0,$70,$38,$1C,$0E,$FE,$00,$00,$00,$00,$7C,$7C,$1C,$1C,$1C,$1C,$1C,$7C,$00,$00,$00,$00,$7C,$7C,$70,$70,$70,$70,$70,$7C,$00,$00
Data.a $00,$00,$38,$38,$7C,$FE,$38,$38,$38,$38,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$FF,$00,$00,$00,$00,$00,$00,$00,$7C,$E0,$FC,$EE,$FC,$00,$00,$00,$00,$00,$00,$0E,$0E,$7E,$EE,$EE,$7E,$00,$00
Data.a $00,$00,$00,$00,$00,$7C,$0E,$0E,$0E,$7C,$00,$00,$00,$00,$00,$00,$E0,$E0,$FC,$EE,$EE,$FC,$00,$00,$00,$00,$00,$00,$00,$7C,$EE,$FE,$0E,$7C,$00,$00,$00,$00,$00,$00,$F0,$38,$FC,$38,$38,$38,$00,$00
Data.a $00,$00,$00,$00,$00,$FC,$EE,$EE,$FC,$E0,$7E,$00,$00,$00,$0E,$0E,$0E,$7E,$EE,$EE,$EE,$EE,$00,$00,$00,$00,$38,$38,$00,$3C,$38,$38,$38,$7C,$00,$00,$00,$00,$00,$00,$70,$00,$70,$70,$70,$70,$3C,$00
Data.a $00,$00,$0E,$0E,$0E,$0E,$7E,$3E,$7E,$EE,$00,$00,$00,$00,$3C,$3C,$38,$38,$38,$38,$38,$7C,$00,$00,$00,$00,$00,$00,$00,$EE,$FE,$FE,$FE,$CE,$00,$00,$00,$00,$00,$00,$00,$7E,$EE,$EE,$EE,$EE,$00,$00
Data.a $00,$00,$00,$00,$00,$7C,$EE,$EE,$EE,$7C,$00,$00,$00,$00,$00,$00,$00,$7E,$EE,$EE,$7E,$0E,$0E,$00,$00,$00,$00,$00,$00,$FC,$EE,$EE,$FC,$E0,$E0,$00,$00,$00,$00,$00,$00,$7E,$EE,$0E,$0E,$0E,$00,$00
Data.a $00,$00,$00,$00,$00,$FC,$0E,$7C,$E0,$7E,$00,$00,$00,$00,$00,$00,$38,$FE,$38,$38,$38,$F0,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$EE,$FC,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$7C,$38,$00,$00
Data.a $00,$00,$00,$00,$00,$CE,$FE,$FE,$FC,$FC,$00,$00,$00,$00,$00,$00,$00,$EE,$7C,$38,$7C,$EE,$00,$00,$00,$00,$00,$00,$00,$EE,$EE,$EE,$FC,$70,$3E,$00,$00,$00,$00,$00,$00,$FE,$70,$38,$1C,$FE,$00,$00
Data.a $00,$00,$F0,$F0,$38,$38,$1E,$38,$38,$F0,$00,$00,$00,$00,$1E,$1E,$38,$38,$F0,$38,$38,$1E,$00,$00
petskii_colors:
Data.a $01,$01,$01,$FF,$FF,$FF,$88,$00,$00,$AA,$FF,$EE,$CC,$44,$CC,$00,$CC,$55,$00,$00,$AA,$EE,$EE,$77,$DD,$88,$55,$66,$44,$00,$FF,$77,$77,$33,$33,$33,$77,$77,$77,$AA,$FF,$66,$00,$88,$FF,$BB,$BB,$BB
Data.a $00,$00,$00
mcursor_type_0:
Data.a $F8,$FF,$00,$00,$F8,$FF,$F0,$7F,$FF,$7F,$F0,$1F,$FF,$1F,$FE,$07,$FF,$07,$CE,$01,$CF,$01,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
Data.a $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
EndDataSection
EndModule
;_____________________________MAIN PROGRAM_________________________
sys::init()
sys::maincamera_h = CreateCamera(-1,0,0,100,100)
CameraBackColor(sys::maincamera_h,sys::c64color(sys::#c64_Color_Blue))
Define cubemesh_h.i,cubeentity_h.i
cubemesh_h = CreateCube(-1,100)
cubeentity_h = CreateEntity(-1,MeshID(cubemesh_h),#PB_Material_None,0,0,0)
MoveCamera(sys::maincamera_h,0,0,500)
Repeat
sys::preDate()
RotateEntity(cubeentity_h,0,0.5,0,#PB_Relative)
RenderWorld()
DisplayTransparentSprite(sys::c64_desktopsprite,0,0)
sys::textout(80,80,"Press Escape to quit.",sys::c64color(sys::#c64_Color_LightBlue))
sys::textout(80,100,"Ready.",sys::c64color(sys::#c64_Color_LightBlue))
sys::textout(80,660,FormatDate("%hh:%ii:%ss", Date()),sys::c64color(sys::#c64_Color_LightBlue))
sys::textout(780,660,"Mem " + Str(MemoryStatus(#PB_System_FreePhysical)/(1024*1024)) + " MByte / " + Str(MemoryStatus(#PB_System_TotalPhysical)/(1024*1024))+" MByte",sys::c64color(sys::#c64_Color_LightBlue))
sys::Update()
FlipBuffers()
Delay(1)
ForEver
;_________________________MAIN PROGRAM END__________________________