Is there a way to render texture + wirframe?

Everything related to 3D programming
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Is there a way to render texture + wirframe?

Post by Mijikai »

Is there a way to render texture + wirframe (overlaying the texture)?
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Is there a way to render texture + wirframe?

Post by miso »

Quick and dirty, but the idea is there.

PS: I'm still struggling with my quads. If anyone tests this and sees pink/purple border around the screen viewport, please tell me what is your desktop resolution and dpi settings.

Code: Select all

EnableExplicit
#MASK_GENERALPICKMASK=1<<1

#MASK_MAINCAMERA=1<<1
#MASK_WIREFRAMECAMERA=1<<2
#MASK_RENDERCAMERA=1<<31

#RENDERWIDTH  = 1366/2
#RENDERHEIGHT = 768/2

Global maincamera.i,rendercamera.i,wireframecamera.i,texture.i,wrendertexture.i,rendertexture.i,rendermaterial.i,quadmesh.i,mainquadobj.i,spheremesh.i, planemesh.i,mylight.i, myobj.i, myplane.i, myevent.i
Global texture_A.i,material_A.i

Procedure start()
  InitEngine3D():InitSprite():InitKeyboard()
  AntialiasingMode(#PB_AntialiasingMode_x2)
  ExamineDesktops()
  ;PROPER SCREEN OPEN
  ;OpenWindow(0, 0,0, DesktopUnscaledX(DesktopWidth(0)),DesktopUnscaledY(DesktopHeight(0)), "RenderQuad Resize",#PB_Window_ScreenCentered|#PB_Window_SizeGadget)
  OpenWindow(0, 0,0,#RENDERWIDTH, #RENDERHEIGHT, "RenderQuad Resize",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0), 0, 0, #RENDERWIDTH, #RENDERHEIGHT, 1, 0, 0)
  ResizeWindow(0,0,0,DesktopWidth(0),DesktopHeight(0))
EndProcedure

Procedure CreateCameras()
  maincamera=CreateCamera(-1,0,0,100,100,#MASK_MAINCAMERA)
  CameraBackColor(maincamera,(RGB(0,0,0)))
  CameraRenderMode(maincamera,#PB_Camera_Textured)
  
  wireframecamera=CreateCamera(-1,0,0,100,100,#MASK_WIREFRAMECAMERA)
  CameraBackColor(wireframecamera,(RGB(0,0,0)))
  CameraRenderMode(wireframecamera,#PB_Camera_Wireframe)
  
  
  rendercamera=CreateCamera(-1,0,0,100,100,#MASK_RENDERCAMERA)
  CameraBackColor(rendercamera,(RGB(255,0,255)))
  CameraProjectionMode(rendercamera,#PB_Camera_Orthographic)
EndProcedure

Procedure createrenderquad()
  quadmesh=CreatePlane(-1,CameraViewWidth(rendercamera)*DesktopWidth(0)/ScreenWidth(),CameraViewHeight(rendercamera)*DesktopHeight(0)/ScreenHeight(),1,1,1,1)
  rendertexture = CreateRenderTexture(-1,CameraID(maincamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  wrendertexture = CreateRenderTexture(-1,CameraID(wireframecamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  rendermaterial =CreateMaterial(-1,TextureID(rendertexture))
  AddMaterialLayer(rendermaterial,TextureID(wrendertexture),#PB_Material_Add)
  mainquadobj=CreateEntity(-1,MeshID(quadmesh),MaterialID(rendermaterial),0,0,-100000,#MASK_GENERALPICKMASK,#MASK_RENDERCAMERA)
  
  RotateEntity(mainquadobj,90,180,0,#PB_Absolute)
  MoveCamera(rendercamera,0,0,-500,#PB_Absolute|#PB_World)
EndProcedure

Procedure createworld()
  Protected x.i
  texture_A=CreateTexture(#PB_Any,256,256)
  StartDrawing(TextureOutput(texture_A))
  Box(0,0,256,256,RGB(10,128,10))
  For x = 1 To 4096*2
    Plot(Random(255),Random(255),RGB(Random(255),255,255))
  Next x
  StopDrawing()
  material_A.i = CreateMaterial(#PB_Any,TextureID(texture_A))
  ScaleMaterial(material_A,0.25,0.25)
  
  spheremesh=CreateSphere(-1,100)
  planemesh=CreatePlane(-1,WindowWidth(0)*1.2,WindowHeight(0)*1.2,1,1,1,1)
  
  mylight= CreateLight(-1,RGB(255,255,255),200,200,200)
  DisableMaterialLighting(rendermaterial,#True)
  MaterialFilteringMode(rendermaterial,#PB_Material_None)
  AmbientColor(RGB(150,150,150))
  
  myobj = CreateEntity(-1,MeshID(spheremesh),MaterialID(material_A),0,0,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  myplane=CreateEntity(-1,MeshID(planemesh),MaterialID(material_A),0,-100,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  
  MoveCamera(maincamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveCamera(wireframecamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveEntity(myobj,0,0,0,#PB_Absolute|#PB_World)
  CameraLookAt(maincamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
  CameraLookAt(wireframecamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
EndProcedure

start()
createcameras()
createrenderquad()
createworld()


Repeat
  Repeat
    myevent = WindowEvent()
  Until myevent = 0
  
	ExamineKeyboard()
	
	If KeyboardPushed(#PB_Key_Left) : RotateCamera(maincamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(maincamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(maincamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(maincamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
  If KeyboardPushed(#PB_Key_Left) : RotateCamera(wireframecamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(wireframecamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(wireframecamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(wireframecamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
	RotateEntity(myobj,0,0.1,0,#PB_Relative)
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape)
  
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Is there a way to render texture + wirframe?

Post by miso »

I gave up. If anyone knows how to resize a quadplane to fit an ortho camera for borderless fullscreen window in any desktop resolution and dpi, I'm full of ears...
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Is there a way to render texture + wirframe?

Post by Mijikai »

Thanks for the example.
I did not see a pink/purple border, so not sure what might be wrong.
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Is there a way to render texture + wirframe?

Post by miso »

Your welcome. Change the resolution, and you will see.
This one is better, but still not perfect:

Code: Select all

EnableExplicit
#MASK_GENERALPICKMASK=1<<1

#MASK_MAINCAMERA=1<<1
#MASK_WIREFRAMECAMERA=1<<2
#MASK_RENDERCAMERA=1<<31

#RENDERWIDTH  = 1366/2
#RENDERHEIGHT = 768/2

Global maincamera.i,rendercamera.i,wireframecamera.i,texture.i,wrendertexture.i,rendertexture.i,rendermaterial.i,quadmesh.i,mainquadobj.i,spheremesh.i, planemesh.i,mylight.i, myobj.i, myplane.i, myevent.i
Global texture_A.i,material_A.i

Procedure start()
  InitEngine3D():InitSprite():InitKeyboard()
  AntialiasingMode(#PB_AntialiasingMode_x2)
  ExamineDesktops()
  ;PROPER SCREEN OPEN
  OpenWindow(0, 0,0, DesktopUnscaledX(DesktopWidth(0)),DesktopUnscaledY(DesktopHeight(0)), "RenderQuad Resize",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
  ;OpenWindow(0, 0,0,#RENDERWIDTH, #RENDERHEIGHT, "RenderQuad Resize",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 1, 0, 0)
  ;ResizeWindow(0,0,0,DesktopWidth(0),DesktopHeight(0))
EndProcedure

Procedure CreateCameras()
  maincamera=CreateCamera(-1,0,0,100,100,#MASK_MAINCAMERA)
  CameraBackColor(maincamera,(RGB(0,0,0)))
  CameraRenderMode(maincamera,#PB_Camera_Textured)
  
  wireframecamera=CreateCamera(-1,0,0,100,100,#MASK_WIREFRAMECAMERA)
  CameraBackColor(wireframecamera,(RGB(0,0,0)))
  CameraRenderMode(wireframecamera,#PB_Camera_Wireframe)
  
  
  rendercamera=CreateCamera(-1,0,0,100,100,#MASK_RENDERCAMERA)
  CameraBackColor(rendercamera,(RGB(255,0,255)))
  CameraProjectionMode(rendercamera,#PB_Camera_Orthographic)
EndProcedure

Procedure createrenderquad()
  quadmesh=CreatePlane(-1,CameraViewWidth(rendercamera)*ScreenWidth()/ScreenHeight(),CameraViewHeight(rendercamera)*ScreenWidth()/ScreenHeight(),1,1,1,1)
  rendertexture = CreateRenderTexture(-1,CameraID(maincamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  wrendertexture = CreateRenderTexture(-1,CameraID(wireframecamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  rendermaterial =CreateMaterial(-1,TextureID(rendertexture))
  AddMaterialLayer(rendermaterial,TextureID(wrendertexture),#PB_Material_Add)
  mainquadobj=CreateEntity(-1,MeshID(quadmesh),MaterialID(rendermaterial),0,0,-100000,#MASK_GENERALPICKMASK,#MASK_RENDERCAMERA)
  
  RotateEntity(mainquadobj,90,180,0,#PB_Absolute)
  MoveCamera(rendercamera,0,0,-500,#PB_Absolute|#PB_World)
EndProcedure

Procedure createworld()
  Protected x.i
  texture_A=CreateTexture(#PB_Any,256,256)
  StartDrawing(TextureOutput(texture_A))
  Box(0,0,256,256,RGB(10,128,10))
  For x = 1 To 4096*2
    Plot(Random(255),Random(255),RGB(Random(255),255,255))
  Next x
  StopDrawing()
  material_A.i = CreateMaterial(#PB_Any,TextureID(texture_A))
  ScaleMaterial(material_A,0.25,0.25)
  
  spheremesh=CreateSphere(-1,100)
  planemesh=CreatePlane(-1,WindowWidth(0)*1.2,WindowHeight(0)*1.2,1,1,1,1)
  
  mylight= CreateLight(-1,RGB(255,255,255),200,200,200)
  DisableMaterialLighting(rendermaterial,#True)
  MaterialFilteringMode(rendermaterial,#PB_Material_None)
  AmbientColor(RGB(150,150,150))
  
  myobj = CreateEntity(-1,MeshID(spheremesh),MaterialID(material_A),0,0,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  myplane=CreateEntity(-1,MeshID(planemesh),MaterialID(material_A),0,-100,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  
  MoveCamera(maincamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveCamera(wireframecamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveEntity(myobj,0,0,0,#PB_Absolute|#PB_World)
  CameraLookAt(maincamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
  CameraLookAt(wireframecamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
EndProcedure

start()
createcameras()
createrenderquad()
createworld()


Repeat
  Repeat
    myevent = WindowEvent()
  Until myevent = 0
  
	ExamineKeyboard()
	
	If KeyboardPushed(#PB_Key_Left) : RotateCamera(maincamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(maincamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(maincamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(maincamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
  If KeyboardPushed(#PB_Key_Left) : RotateCamera(wireframecamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(wireframecamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(wireframecamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(wireframecamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
	RotateEntity(myobj,0,0.1,0,#PB_Relative)
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape)
  
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Is there a way to render texture + wirframe?

Post by Mijikai »

I see, this is bad theres no info on how to do i.
How to get the viewport?
How to fit a render texture?

Gonna play around a bit more but it looks like its not possible.
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Is there a way to render texture + wirframe?

Post by miso »

I'm sure its possible, I just don't know how to do it. The only thing that is needed is to size the quadobject to fit correctly.
It would be much more helpful, if autostretching in 3d would work the same way like in 2d. Really stretching, and not increasing the viewport...
miso
Enthusiast
Enthusiast
Posts: 466
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: Is there a way to render texture + wirframe?

Post by miso »

Just for the record. I don't know the why's, but figured out the correct quad size algo to use in PB

Code: Select all

quadmesh = CreatePlane(#PB_Any,(ScreenWidth()/ScreenHeight())*1000,1000,1,1,1,1) 
(I belive here in PB 1000 means 1.0 and 0 means -1.0, and the full range is the ortho camera height.)

Quad entity should be moved into any negative Z to be visible, it will always fit your screen perfectly at xy 0,0. (normal pb plane centered around local origo.)

Now my new problem is, that entitites in an ortho camera seems to always rendered after sprites. Sprites also can't be ordered with renderqueue.
(Edit:already got help from pjay for a good solution with sprites)


Edit: And heres the now corrected example:

Code: Select all

EnableExplicit
#MASK_GENERALPICKMASK=1<<1

#MASK_MAINCAMERA=1<<1
#MASK_WIREFRAMECAMERA=1<<2
#MASK_RENDERCAMERA=1<<31

#RENDERWIDTH  = 1366
#RENDERHEIGHT = 768

Global maincamera.i,rendercamera.i,wireframecamera.i,texture.i,wrendertexture.i,rendertexture.i,rendermaterial.i,quadmesh.i,mainquadobj.i,spheremesh.i, planemesh.i,mylight.i, myobj.i, myplane.i, myevent.i
Global image_A.i,texture_A.i,material_A.i

Procedure start()
  InitEngine3D():InitSprite():InitKeyboard()
  AntialiasingMode(#PB_AntialiasingMode_x2)
  ExamineDesktops()
  OpenWindow(0, 0,0, DesktopUnscaledX(DesktopWidth(0)),DesktopUnscaledY(DesktopHeight(0)), "RenderQuad Resize",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
  OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0), DesktopHeight(0), 1, 0, 0)
EndProcedure

Procedure CreateCameras()
  maincamera=CreateCamera(-1,0,0,100,100,#MASK_MAINCAMERA)
  CameraBackColor(maincamera,(RGB(0,0,0)))
  CameraRenderMode(maincamera,#PB_Camera_Textured)
  
  wireframecamera=CreateCamera(-1,0,0,100,100,#MASK_WIREFRAMECAMERA)
  CameraBackColor(wireframecamera,(RGB(0,0,0)))
  CameraRenderMode(wireframecamera,#PB_Camera_Wireframe)
  
  rendercamera=CreateCamera(-1,0,0,100,100,#MASK_RENDERCAMERA)
  CameraBackColor(rendercamera,(RGB(255,0,255)))
  CameraProjectionMode(rendercamera,#PB_Camera_Orthographic)
EndProcedure

Procedure createrenderquad()
  quadmesh=CreatePlane(-1,ScreenWidth()/ScreenHeight()*1000,1000,1,1,1,1)
  rendertexture = CreateRenderTexture(-1,CameraID(maincamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  wrendertexture = CreateRenderTexture(-1,CameraID(wireframecamera),#RENDERWIDTH,#RENDERHEIGHT,#PB_Texture_AutomaticUpdate)
  rendermaterial =CreateMaterial(-1,TextureID(rendertexture))
  AddMaterialLayer(rendermaterial,TextureID(wrendertexture),#PB_Material_Add)
  mainquadobj=CreateEntity(-1,MeshID(quadmesh),MaterialID(rendermaterial),0,0,-100000,#MASK_GENERALPICKMASK,#MASK_RENDERCAMERA)
  
  RotateEntity(mainquadobj,90,180,0,#PB_Absolute)
  MoveCamera(rendercamera,0,0,-500,#PB_Absolute|#PB_World)
EndProcedure

Procedure createworld()
  Protected x.i
  image_A=CreateImage(#PB_Any,256,256)
  texture_A=CreateTexture(#PB_Any,256,256)
  StartDrawing(ImageOutput(image_A))
  Box(0,0,256,256,RGB(10,128,10))
  For x = 1 To 4096*2
    Plot(Random(255),Random(255),RGB(Random(255),255,255))
  Next x
  StopDrawing()
  StartDrawing(TextureOutput(texture_A))
    DrawImage(ImageID(image_A),0,0)
  StopDrawing()
  FreeImage(image_A)
  
  material_A.i = CreateMaterial(#PB_Any,TextureID(texture_A))
  ScaleMaterial(material_A,0.25,0.25)
  
  spheremesh=CreateSphere(-1,100)
  planemesh=CreatePlane(-1,WindowWidth(0)*1.2,WindowHeight(0)*1.2,1,1,1,1)
  
  mylight= CreateLight(-1,RGB(255,255,255),200,200,200)
  DisableMaterialLighting(rendermaterial,#True)
  MaterialFilteringMode(rendermaterial,#PB_Material_None)
  AmbientColor(RGB(150,150,150))
  
  myobj = CreateEntity(-1,MeshID(spheremesh),MaterialID(material_A),0,0,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  myplane=CreateEntity(-1,MeshID(planemesh),MaterialID(material_A),0,-100,0,#MASK_GENERALPICKMASK,#MASK_MAINCAMERA|#MASK_WIREFRAMECAMERA)
  
  MoveCamera(maincamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveCamera(wireframecamera,0,0,-500,#PB_Absolute|#PB_World)
  MoveEntity(myobj,0,0,0,#PB_Absolute|#PB_World)
  CameraLookAt(maincamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
  CameraLookAt(wireframecamera,EntityX(myobj),EntityY(myobj),EntityZ(myobj))
EndProcedure

start()
createcameras()
createrenderquad()
createworld()


Repeat
  Repeat
    myevent = WindowEvent()
  Until myevent = 0
  
	ExamineKeyboard()
	
	If KeyboardPushed(#PB_Key_Left) : RotateCamera(maincamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(maincamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(maincamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(maincamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
  If KeyboardPushed(#PB_Key_Left) : RotateCamera(wireframecamera,0,1,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Right) : RotateCamera(wireframecamera,0,-1.0,0,#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Up) : MoveCamera(wireframecamera,0,0,-10,#PB_Local|#PB_Relative): EndIf
	If KeyboardPushed(#PB_Key_Down) : MoveCamera(wireframecamera,0,0,10,#PB_Local|#PB_Relative): EndIf
	
	RotateEntity(myobj,0,0.1,0,#PB_Relative)
	RenderWorld()
	FlipBuffers()    
Until KeyboardReleased(#PB_Key_Escape)
  
Last edited by miso on Sun Mar 16, 2025 3:24 pm, edited 1 time in total.
User avatar
Mijikai
Addict
Addict
Posts: 1520
Joined: Sun Sep 11, 2016 2:17 pm

Re: Is there a way to render texture + wirframe?

Post by Mijikai »

Thank you for the solution, it works great :)
Now im more confident to continue with my project.
I saw the bug report, i hope there will be a solution or clarification soon.
Post Reply