Page 1 of 1

3d Engine Textured Plain.

Posted: Thu Nov 12, 2009 2:08 pm
by AndyMK
I have never used the 3d engine commands before. Is it easy to create textured plains from just a loaded image?

Ignore this, i managed to do it.. i have one more question.. can i draw text directly to a texture?

Re: 3d Engine Textured Plain.

Posted: Fri Nov 13, 2009 12:54 am
by citystate
not directly...
you can draw text to an image, save the image and then load it from disk as a texture...

Re: 3d Engine Textured Plain.

Posted: Fri Nov 13, 2009 3:22 pm
by AndyMK
Does anyone have some basic code to create a simple plain ready for texturing, i thought i had it but it didn't work. Im getting confused with the meshdata stuff.

Re: 3d Engine Textured Plain.

Posted: Fri Nov 13, 2009 4:51 pm
by AndyMK
Ok, i managed to make a plain with some code i found but i cant get the texture to appear.

Code: Select all

InitEngine3D()
InitSprite()
UsePNGImageDecoder()
Add3DArchive("d:\work\digitalselecta\media", #PB_3DArchive_FileSystem)

ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2, "")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2, 0, 0, 0)

LoadTexture(0, "knob.png")
CreateMaterial(0, TextureID(0))

CreateMesh(0, 100)

SetMeshData(0, #PB_Mesh_Vertex, ?Ecken, 4)
SetMeshData(0, #PB_Mesh_Face, ?Viereck_1, 2)
SetMeshData(0, #PB_Mesh_UVCoordinate, ?TexturKoordinaten, 4)

CreateEntity(0, MeshID(0), MaterialID(0))

CreateCamera(0, 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2)
CameraBackColor(0, $FF0000)
CameraLocate(0, 0, 0, 10)
CameraLookAt(0, EntityX(0), EntityY(0), EntityZ(0))

Repeat
  ClearScreen(0)
  RenderWorld()
  FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow

DataSection
  
  Ecken:
  Data.f-1, -1, 0 ; Ecke 0             3-----2
  Data.f 1, -1, 0 ; Ecke 1             |     |
  Data.f 1, 1, 0  ; Ecke 2             |     |
  Data.f-1, 1, 0  ; Ecke 3             0-----1
  
  Viereck_1:
  Data.w 0, 1, 2
  Data.w 2, 3, 0
  
  TexturKoordinaten:
  Data.f 0.0, 0.0 ; Vertex 0
  Data.f 1.0, 0.0 ; Vertex 1
  Data.f 1.0, 1.0 ; Vertex 2
  Data.f 0.0, 1.0 ; Vertex 3
    
EndDataSection

Re: 3d Engine Textured Plain.

Posted: Sun Nov 29, 2009 1:53 am
by Rook Zimbabwe
A link to the knob.png pic you used would be nice :D

Re: 3d Engine Textured Plain.

Posted: Thu Dec 03, 2009 12:10 pm
by AndyMK
you can replace "knob.png" with any square png or bmp image

Re: 3d Engine Textured Plain.

Posted: Thu Dec 03, 2009 8:08 pm
by Comtois
I changed few lines, it work like this

Code: Select all

InitEngine3D()
InitSprite()
UsePNGImageEncoder()
Add3DArchive("d:\", #PB_3DArchive_FileSystem)

ExamineDesktops()
OpenWindow(0, 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2, "")
OpenWindowedScreen(WindowID(0), 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2, 0, 0, 0)

CreateImage(0, 256,256)
StartDrawing(ImageOutput(0))
  Box(0,0,256,256, #Red)
  Circle(128,128,80, #Blue)
StopDrawing()
SaveImage(0, "d:\knob.png",#PB_ImagePlugin_PNG)

LoadTexture(0, "knob.png")


CreateMaterial(0, TextureID(0))

CreateMesh(0, 100)

SetMeshData(0, #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate, ?Ecken, 4)
SetMeshData(0, #PB_Mesh_Face, ?Viereck_1, 2)

CreateEntity(0, MeshID(0), MaterialID(0))

CreateCamera(0, 0, 0, DesktopWidth(0)/2, DesktopHeight(0)/2)
CameraBackColor(0, $FFFF00)
CameraLocate(0, 0, 0, 10)
CameraLookAt(0, EntityX(0), EntityY(0), EntityZ(0))

Repeat
  ClearScreen(0)
  RenderWorld()
  FlipBuffers()
Until WindowEvent() = #PB_Event_CloseWindow

DataSection
 
  Ecken:
  Data.f-1, -1, 0 ; Ecke 0            
  Data.f 0.0, 0.0 ; Vertex 0
  Data.f 1, -1, 0 ; Ecke 1  
  Data.f 1.0, 0.0 ; Vertex 1            
  Data.f 1, 1, 0  ; Ecke 2  
  Data.f 1.0, 1.0 ; Vertex 2            
  Data.f-1, 1, 0  ; Ecke 3           
  Data.f 0.0, 1.0 ; Vertex 3

  Viereck_1:
  Data.w 0, 1, 2
  Data.w 2, 3, 0
  
EndDataSection