When you got time, could you try this? I got curious, and I wonder if this (2D) works in your system.Caronte3D wrote: Mon May 12, 2025 2:43 pm On the example 2D, the circle is not perfect on my system (flattened by the poles).
Thanks in advance, and sorry for bugging you.
Code: Select all
;VER PB 6.21 Beta 9
EnableExplicit
;-==============================================================
;- MODULE START
;-==============================================================
DeclareModule sys
#MAIN_DESKTOP = 0
#MAIN_WINDOW = 0
#APPNAME = "Application"
#SCREEN_FRAMERATE = 60
#MAINLOOP_DELAY = 0
#COMPILER_MINIMUM_VERSION = 621
#MAIN_CAMERA = 1<<0
#RENDER_CAMERA = 1<<1
#PICK = 1<<0
#DONTPICK = 1<<1
#RENDERWIDTH_DEFAULT = 1366
#RENDERHEIGHT_DEFAULT = 768
Global desktopcount.i, renderwidth.i=#RENDERWIDTH_DEFAULT, renderheight.i=#RENDERHEIGHT_DEFAULT
Declare open2d(renderwidth.i=#RENDERWIDTH_DEFAULT,renderheight.i=#RENDERHEIGHT_DEFAULT)
Declare open3d(renderwidth.i=#RENDERWIDTH_DEFAULT, renderheight.i=#RENDERHEIGHT_DEFAULT)
Declare SetOrthoCamera()
Declare SetPerspectiveCamera()
Declare.i entitycreate(mesh.i,material.i,x=0,y=0,z=0,pickmask.i=#PICK)
Declare SweepEvents()
Declare.i escape()
EndDeclareModule
Module sys
Structure quadobject
mesh.i
entity.i
texture.i
material.i
EndStructure
Global quad.quadobject
Declare checks()
Declare Load3DScripts()
;==============================================================
; Initializes before opening 2D Screen
; You may correct it to your needs
;==============================================================
Procedure init2d()
sys::desktopcount = ExamineDesktops()
UsePNGImageDecoder()
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
EndProcedure
;==============================================================
; Initializes before opening 3D Screen
; You may correct it to your needs
;==============================================================
Procedure init3d()
sys::desktopcount = ExamineDesktops()
UsePNGImageDecoder()
InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()
InitSound()
EndProcedure
;==============================================================
; Parse 3d resources
; You have to add your correct routes
;==============================================================
Procedure Load3DScripts()
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Main",#PB_3DArchive_FileSystem)
Parse3DScripts()
EndProcedure
;==============================================================
; Opens a fullscreen windowed 3d screen
; Render resolution can be specified,
; result will be stretched according to desktop aspect ratio
;==============================================================
Procedure open2d(renderwidth.i=#RENDERWIDTH_DEFAULT,renderheight.i=#RENDERHEIGHT_DEFAULT)
init2d()
OpenWindow(#MAIN_WINDOW,0,0,renderwidth,renderheight,#APPNAME,#PB_Window_BorderLess|#PB_Window_Invisible)
OpenWindowedScreen(WindowID(#MAIN_WINDOW),0,0,renderwidth,renderheight,1,0,0,#PB_Screen_WaitSynchronization)
ResizeWindow(#MAIN_WINDOW,0,0,DesktopUnscaledX(DesktopWidth(#MAIN_DESKTOP)),DesktopUnscaledY(DesktopHeight(#MAIN_DESKTOP)))
HideWindow(#MAIN_WINDOW,#False)
EndProcedure
;==============================================================
; Opens a fullscreen windowed 3d screen
; Render resolution can be specified,
; result won't be stretched
; Sets the main camera with (ID=1)
; You don't have to bother with the final render camera (ID=2)
;==============================================================
Procedure open3d(renderwidth.i=#RENDERWIDTH_DEFAULT, renderheight.i=#RENDERHEIGHT_DEFAULT)
init3d()
If renderwidth>DesktopUnscaledX(DesktopWidth(#MAIN_DESKTOP)) : renderwidth = DesktopUnscaledX(DesktopWidth(#MAIN_DESKTOP)) : EndIf
If renderheight>DesktopUnscaledY(DesktopHeight(#MAIN_DESKTOP)) : renderheight = DesktopUnscaledY(DesktopHeight(#MAIN_DESKTOP)) : EndIf
OpenWindow(#MAIN_WINDOW,0,0,DesktopUnscaledX(DesktopWidth(#MAIN_DESKTOP)),DesktopUnscaledY(DesktopHeight(#MAIN_DESKTOP)),#APPNAME, #PB_Window_BorderLess)
OpenWindowedScreen(WindowID(#MAIN_WINDOW),0,0,WindowWidth(#MAIN_WINDOW),WindowHeight(#MAIN_WINDOW),1,0,0,#PB_Screen_SmartSynchronization)
Load3DScripts() : SetFrameRate(#SCREEN_FRAMERATE)
CreateCamera(#RENDER_CAMERA,0,0,100,100,#RENDER_CAMERA)
CreateCamera(#MAIN_CAMERA,0,0,100,100,#MAIN_CAMERA)
quad\texture = CreateRenderTexture(#PB_Any,CameraID(#MAIN_CAMERA),renderwidth,renderheight,#PB_Texture_AutomaticUpdate)
quad\material = CreateMaterial(#PB_Any,TextureID(quad\texture))
DisableMaterialLighting(quad\material,#True)
MaterialFilteringMode(quad\material,#PB_Material_Bilinear)
quad\mesh = CreatePlane(#PB_Any,(ScreenWidth()/ScreenHeight())*1000,1000,1,1,1,1)
quad\entity = CreateEntity(#PB_Any,MeshID(quad\mesh),MaterialID(quad\material),0,0,-1200,#DONTPICK,#RENDER_CAMERA)
RotateEntity(quad\entity,90,180,0,#PB_Absolute)
EndProcedure
;=====================================================
; Sets the main world camera to orthographic
;=====================================================
Procedure SetOrthoCamera()
If IsCamera(#MAIN_CAMERA)
CameraProjectionMode(#MAIN_CAMERA,#PB_Camera_Orthographic)
EndIf
EndProcedure
;=====================================================
; Sets the main world camera to perspective
;=====================================================
Procedure SetPerspectiveCamera()
If IsCamera(#MAIN_CAMERA)
CameraProjectionMode(#MAIN_CAMERA,#PB_Camera_Perspective)
EndIf
EndProcedure
;=====================================================
; Shortened entity creation, it uses raw PB ID-s
;=====================================================
Procedure.i entitycreate(mesh.i,material.i,x.i=0,y.i=0,z.i=0,pickmask.i=#PICK)
Protected.i returnvalue=-1
If IsMesh(mesh)
If IsMaterial(material)
returnvalue = CreateEntity(#PB_Any,MeshID(mesh),MaterialID(material),x,y,z,#PICK,#MAIN_CAMERA)
Else
returnvalue = CreateEntity(#PB_Any,MeshID(mesh),#PB_Material_None,x,y,z,pickmask,#MAIN_CAMERA)
EndIf
EndIf
ProcedureReturn returnvalue
EndProcedure
;=====================================================
; Check for compiler version and debugger
; Adjust it to your needs
;=====================================================
Procedure Checks()
If #PB_Compiler_Version<#COMPILER_MINIMUM_VERSION
Debug "Minimum Compiler version is "+ Str(#COMPILER_MINIMUM_VERSION) + "."
End
EndIf
If #PB_Compiler_Debugger
Debug "Please run without debugger"
End
EndIf
EndProcedure
;=====================================================
; Processes windows events
; Delays(0), and examines the keyboard and mouse
;=====================================================
Procedure SweepEvents()
Protected w_event.i
Delay(#MAINLOOP_DELAY)
Repeat
w_event = WindowEvent() : If w_event = #PB_Event_CloseWindow : End : EndIf
Until Not w_event
ExamineKeyboard():ExamineMouse()
EndProcedure
;=====================================================
;Short check if Escape is pressed
;=====================================================
Procedure.i Escape()
If KeyboardPushed(#PB_Key_Escape)
ProcedureReturn #True
EndIf
ProcedureReturn #False
EndProcedure
EndModule
;-=====================================================
;-MODULE END
;-=====================================================
;=====================================================
;- EXAMPLES
;=====================================================
Procedure create_example_sprite()
CreateSprite(1,100,100,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(1))
DrawingMode(#PB_2DDrawing_AllChannels)
Box(0,0,OutputWidth(),OutputHeight(),RGBA(0,0,0,0))
Circle(OutputWidth()/2,OutputHeight()/2,Round(OutputWidth()/2-1,#PB_Round_Down),RGBA(255,0,0,255))
StopDrawing()
EndProcedure
;=====================================================
; A 2d example
;=====================================================
Procedure example_2d()
ExamineDesktops()
Sys::open2d(DesktopWidth(0),DesktopHeight(0))
create_example_sprite()
ZoomSprite(1,ScreenHeight()/2,ScreenHeight()/2)
Repeat
sys::SweepEvents()
ClearScreen(RGB(20,60,90))
RotateSprite(1,1,#PB_Relative)
DisplayTransparentSprite(1,ScreenWidth()/2-SpriteWidth(1)/2,ScreenHeight()/2-SpriteHeight(1)/2)
FlipBuffers()
Until sys::Escape()
EndProcedure
;=====================================================
; A 3d example
;=====================================================
Procedure example_3d()
Protected.i cubeobj
Sys::open3d(1366,768)
;sys::SetOrthoCamera() :;uncomment this line to switch the camera to orthographic
create_example_sprite()
CreateLight(1,RGB(255,255,255),0,0,0,#PB_Light_Directional) : LightDirection(1,1,-1,1)
CreateCube(1,100)
cubeobj = sys::entitycreate(1,0,0,0,-500)
Repeat
sys::SweepEvents()
RotateEntity(cubeobj,0,1,0,#PB_Relative)
RenderWorld()
RotateSprite(1,1,#PB_Relative)
DisplayTransparentSprite(1,25,25)
FlipBuffers()
Until sys::Escape()
EndProcedure
;-==============================================================
;-RUN THE EXAMPLES HERE
;-==============================================================
example_2d()
;example_3d()