What am I doing wrong? (trying to texture mesh/entity)

Advanced game related topics
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

What am I doing wrong? (trying to texture mesh/entity)

Post by GBeebe »

Ok, here's what I've got so far:

Code: Select all

Structure s_Vertex
  px.f
  py.f
  pz.f
  u.f
  v.f
EndStructure

Structure s_Face
  face.w[3]
EndStructure 


InitEngine3D()
InitSprite()
;InitSprite3D()
InitKeyboard()
InitMouse()

    ScreenW = 800
    ScreenH = 600
    BitDepth = 32  ;This should be changed in settings
    ProgramName.s = "test"
    

;Allows us to use PNG files!
UsePNGImageDecoder()

OpenScreen(ScreenW, ScreenH, BitDepth, ProgramName.s) 

  


Add3DArchive("Data\", #PB_3DArchive_FileSystem)  
  Tid = LoadTexture(#PB_Any, "ship.png")
  Mid = CreateMaterial(#PB_Any, TextureID(Tid))
  MaterialBlendingMode   (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
  MaterialFilteringMode(Mid, #PB_Material_None)

  DisableMaterialLighting(Mid, 1)
  
Ret_Mesh = CreateMesh(#PB_Any, 5)
  
  Dim Vertices.s_Vertex(3)
  Dim Triangles.s_Face(1) 
  
  Vertices(0)\px = 0
  Vertices(0)\py = 0
  Vertices(0)\pz = 10
  Vertices(0)\u = 0
  Vertices(0)\v = 1
  
  Vertices(1)\px = 64
  Vertices(1)\py = 0
  Vertices(1)\pz = 10
  Vertices(1)\u = 0
  Vertices(1)\v = 1
  
  Vertices(2)\px = 64
  Vertices(2)\py = 64
  Vertices(2)\pz = 10
  Vertices(2)\u = 0
  Vertices(2)\v = 1
  
  Vertices(3)\px = 0
  Vertices(3)\py = 64
  Vertices(3)\pz = 10
  Vertices(3)\u = 0
  Vertices(3)\v = 1
  
  Triangles(0)\face[0] = 0
  Triangles(0)\face[1] = 1
  Triangles(0)\face[2] = 3
  
  Triangles(1)\face[0] = 1
  Triangles(1)\face[1] = 2
  Triangles(1)\face[2] = 3

  SetMeshData(Ret_Mesh, #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate , Vertices(), 4)
  SetMeshData(Ret_Mesh, #PB_Mesh_Face, Triangles(), 2)
  
 

  Ret_Ent = CreateEntity(#PB_Any, MeshID(Ret_Mesh), MaterialID(Mid))





  

#Camera = 0
CreateCamera(#Camera, 0, 0, 100, 100) ; Créate caméra
CameraBackColor(#Camera, $FF0000) ; Back color is blue
CameraLocate(#Camera,0,0,500) ; Position the caméra
CameraLookAt(#Camera, EntityX(Ret_Ent), EntityY(Ret_Ent), EntityZ(Ret_Ent)) ; Point/orient the caméra towards the entity
   
Repeat

  ;ClearScreen(0)
  
;{  Input           
  If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -1
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = 1
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -1
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = 1
        Else
          KeyY = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_PageUp)
          RollZ = 3
        Else
          If KeyboardPushed(#PB_Key_PageDown)
            RollZ = -3
          Else
            RollZ = 0
          EndIf  
        EndIf
        
        
        If KeyboardPushed(#PB_Key_Add)
          Frame.f+0.005
        EndIf
  EndIf
  
  If ExamineMouse()
        MouseX = -MouseDeltaX()/2 
        MouseY = -MouseDeltaY()/2
  EndIf
;}
  
  RotateCamera(#Camera, MouseX, MouseY, RollZ*2)
  MoveCamera  (#Camera, KeyX*2, 0, KeyY*2)
  
  RenderWorld() ; Display the 3D world
  
  
 
  FlipBuffers()
       ;Delay(10)
       
OnErrorResume()       
Until KeyboardPushed(#PB_Key_Escape)
Debug ret_ent
End
But it's just a blue screen. and I don't see my PNG image.
When i remove this line:

Code: Select all

MaterialBlendingMode   (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
Then I see a white square where the image should be, but the image isn't on it.

Is there something that I'm missing to Texture an Entity?
GBeebe
Enthusiast
Enthusiast
Posts: 263
Joined: Sat Oct 09, 2004 6:52 pm
Location: Franklin, PA - USA
Contact:

I got it

Post by GBeebe »

Ok, first - I didn't realize that when going down in Y value (in 3d space) it becomes a negative number (unlike positive Y is lower than negative Y on the screen).

And Until i read this post, I didn't know what UV was.
Post Reply