Problems With 3D Texture

Advanced game related topics
Vallan
User
User
Posts: 24
Joined: Thu Mar 09, 2006 1:25 pm

Problems With 3D Texture

Post by Vallan »

I'd wrote a code to create a 3D sphere with OGRE.
It works great, but There is a problem with the texture.

Does anybody know why? And how I could change that.

Code: Select all

 #PI = 3.14159265
















; (Halbe Kugel) +1  , da OBen und unten benötigt wird,um dort Ringe zu erzeugen.


#Punktepro360 = 72
#Radius       = 25


; 
;  P1------P4
;   |      /| 
;   |    /  | 
;   |  /    | 
;   |/      |
;  P2------P3
; 





InitEngine3D()
InitSprite() 
InitMouse()
InitKeyboard() 
   
Structure Pos
x.f
y.f
z.f
EndStructure

Punkt.Pos


OpenScreen( 800 , 600 , 32 , "Kugel" )


Add3DArchive("data\",#PB_3DArchive_FileSystem )
#TextureName_SkyDone = "clouds.jpg"

; 
;     SkyDome(#TextureName_SkyDone, 1)


Procedure Kugel_3T(MeshNo.l,Radius.f,PunktePro360.l)


;  SetMeshData(MeshNo, 0, addpoint    , ((PunktePro360) * ((PunktePro360/2 +1)))    )
;  SetMeshData(MeshNo, 1, addtriangle , ((PunktePro360) * (((PunktePro360)/2))) * 4)
;  SetMeshData(MeshNo, 2, addtexture  , ((PunktePro360) * ((PunktePro360/2)+1)))


addpoint    = AllocateMemory((PunktePro360)   * (PunktePro360/2 +1)  *3     * 4) 
addtriangle = AllocateMemory((PunktePro360)   * (PunktePro360/2)     *12    * 2)
addtexture  = AllocateMemory((PunktePro360-1) * ((PunktePro360+1)/2) *8     * 4)


Adresse = addpoint


For Posy = 0 To (PunktePro360/2)
  WinkelY.f = Posy*#PI*2/PunktePro360
  
  r2.f = Sin(WinkelY)*Radius 
  y.f  = Cos(WinkelY)*Radius
   
   For Pos = 0 To (PunktePro360-1)
    Winkel.f = Pos *#PI*2/PunktePro360
    
    Px.f = Cos(Winkel)*r2
    Py.f = y
    Pz.f = Sin(Winkel)*r2
    
    If Posy = (PunktePro360/2)
    Px = 0 
    Py = -1*Radius
    Pz = 0
    EndIf 
    
    PokeF(Adresse,Px) 
    Adresse+4
    PokeF(Adresse,Py) 
    Adresse+4
    PokeF(Adresse,Pz) 
    Adresse+4
    
   Next
Next



Adresse = addtriangle

For Posy = 0 To (PunktePro360/2)
  For Pos = 0 To PunktePro360-1
  
  
  If pos = PunktePro360 -1
  
  
   P1 = Pos+(Posy*PunktePro360)
   P2 = Pos+(Posy*PunktePro360)+PunktePro360
   P3 = (Posy*PunktePro360)+PunktePro360
   P4 = (Posy*PunktePro360)
     
  
  
         PokeW(adresse     , P4) : PokeW(adresse +  2, P1) : PokeW(adresse +  4, P2) 
         PokeW(adresse +  6, P2) : PokeW(adresse +  8, P3) : PokeW(adresse + 10, P4) 
            
         PokeW(adresse + 12, P2) : PokeW(adresse + 14, P1) : PokeW(adresse + 16, P4)  ; Außen  (Im Urzeigersinn !!!)
         PokeW(adresse + 18, P4) : PokeW(adresse + 20, P3) : PokeW(adresse + 22, P2)  ; Außen  (Im Urzeigersinn !!!)
                                         
; 
;  P1------P4
;   |      /| 
;   |    /  | 
;   |  /    | 
;   |/      |
;  P2------P3
;   
                    
    adresse + 24 
   Else



; 
;  P1------P4
;   |      /| 
;   |    /  | 
;   |  /    | 
;   |/      |
;  P2------P3
;   
  

   P1 = Pos+(Posy*PunktePro360)
   P2 = Pos+(Posy*PunktePro360)+PunktePro360
   P3 = Pos+(Posy*PunktePro360)+1+PunktePro360
   P4 = Pos+(Posy*PunktePro360)+1
     
    
         PokeW(adresse     , P4) : PokeW(adresse +  2, P1) : PokeW(adresse +  4, P2) 
         PokeW(adresse +  6, P2) : PokeW(adresse +  8, P3) : PokeW(adresse + 10, P4) 
            
         PokeW(adresse + 12, P2) : PokeW(adresse + 14, P1) : PokeW(adresse + 16, P4)  ; Außen  (Im Urzeigersinn !!!)
         PokeW(adresse + 18, P4) : PokeW(adresse + 20, P3) : PokeW(adresse + 22, P2)  ; Außen  (Im Urzeigersinn !!!)
                     
    adresse + 24 

   EndIf  
  Next
Next










   adresse=addtexture 
   
For Posy = 0 To (PunktePro360) Step 2
 For Pos = 0 To (PunktePro360-1) 

    
    
    PokeF(Adresse,Pos/(PunktePro360-1)) 
    Adresse+4
    PokeF(Adresse,Posy/(PunktePro360-1)) 
    Adresse+4

 
   Next 
Next












;-Mesh 
CreateMesh(MeshNo) 
 SetMeshData(MeshNo, 0, addpoint    , ((PunktePro360) * ((PunktePro360/2 +1)))    )
 SetMeshData(MeshNo, 1, addtriangle , ((PunktePro360) * (((PunktePro360)/2))) * 4)
 SetMeshData(MeshNo, 2, addtexture  , ((PunktePro360) * ((PunktePro360/2)+2)))

EndProcedure

Kugel_3T(0,50,64)

CreateTexture(0,512,512) 
StartDrawing(TextureOutput(0)) 

  DrawingMode(4) 


For xxx = 0 To 512 Step 8
For yyy = 0 To 512 Step 8
Box(xxx+2,yyy+2,4,4,RGB(Random(255),Random(255),Random(255) ))
Next
Next

Box(128,128,256,256,RGB(255,0,0))

StopDrawing() 








CreateMaterial(0,TextureID(0)) 
MaterialFilteringMode(0 , #PB_Material_Trilinear ) 
; MaterialDiffuseColor(0,RGB(255,255,255))



CreateEntity(0, MeshID(0), MaterialID(0)) 
;ScaleEntity(0,5,5,5)


CreateCamera(0, 0, 0, 100, 100) 
CameraLocate(0,0,0,100) 
CameraLookAt(0,0,0,0) 
CameraBackColor(0, RGB(255,255,255))

    
    
    CreateLight(0, RGB(0,0,255), 100.0, 0, 0)   ; Blue light
    CreateLight(1, RGB(255,0,0), -100.0, 0, 0)  ; Red light
    



Repeat 
    
   ClearScreen(0,0,0) 
   ExamineKeyboard()
   ExamineMouse()

   ;RotateEntity(0,0.5,0.5,0.5)
   
   
    If KeyboardReleased(#PB_Key_F1) 
     ClearScreen(0,0,0)
     CameraRenderMode(0, #PB_Camera_Wireframe) 
    EndIf 
    
    If KeyboardReleased(#PB_Key_F2)
     ClearScreen(0,0,0)
     CameraRenderMode(0, #PB_Camera_Textured)
    EndIf 
    
    If KeyboardReleased(#PB_Key_F3)
     ClearScreen(0,0,0)
     CameraRenderMode(0, #PB_Camera_Plot)
    EndIf 
    
    
    
   
    If KeyboardPushed(#PB_Key_Left)
     KeyX = -10
    ElseIf KeyboardPushed(#PB_Key_Right)
     KeyX = 10
    Else
     KeyX = 0
    EndIf
    If KeyboardPushed(#PB_Key_Up)
     KeyY = -10
    ElseIf KeyboardPushed(#PB_Key_Down)
     KeyY = 10
    Else
     KeyY = 0
    EndIf
    

     
      
RotateCamera(0,-1*MouseDeltaX(),-1*MouseDeltaY(),0)
MoveCamera(0, KeyX, 0, KeyY)
     PunktePro360 = 128
     
     b+2
     If b > PunktePro360
     a+1  
     b = 0 
     EndIf 

  

      
    
   RenderWorld() 



StartDrawing(ScreenOutput())
FrontColor(255,255,255)
BackColor(0,0,0)
DrawingMode(0)

Locate(10,10)
DrawText("Triangles: "+Str(CountRenderedTriangles()))
Locate(10,70)
DrawText("Framerate: "+Str(Engine3DFrameRate(#PB_Engine3D_Current)))
; Locate(10,70)



StopDrawing()


   FlipBuffers() 
    
Until KeyboardPushed(#PB_Key_Escape)
End 
Google 4ever!
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

Wich version of PB do you use ?
Please correct my english
http://purebasic.developpez.com/
Vallan
User
User
Posts: 24
Joined: Thu Mar 09, 2006 1:25 pm

Post by Vallan »

Sorry, I forgot it. It's PB 3.94. (I dont know how to update it to PB 4)
Google 4ever!
Nik
Addict
Addict
Posts: 1017
Joined: Fri May 13, 2005 11:45 pm
Location: Germany
Contact:

Post by Nik »

If you are a License owner you need to go to purebasic.com and login with the account information you got emailed you can then download the newest Betas
Vallan
User
User
Posts: 24
Joined: Thu Mar 09, 2006 1:25 pm

Post by Vallan »

No, I mean I don't know how I can use the Ogre comandos changed in PB 4.
Like the new Parameter with CreateMesh().
Google 4ever!
User avatar
Comtois
Addict
Addict
Posts: 1432
Joined: Tue Aug 19, 2003 11:36 am
Location: Doubs - France

Post by Comtois »

here is an example using PB4 beta 7

Sphere 3D
Please correct my english
http://purebasic.developpez.com/
Vallan
User
User
Posts: 24
Joined: Thu Mar 09, 2006 1:25 pm

Post by Vallan »

I did read it. But what's the mistake in my code? Why is there a stripe :?:
Google 4ever!
Post Reply