Start point with terrains for noobs (as me hehe)

Everything related to 3D programming
User avatar
minimy
Enthusiast
Enthusiast
Posts: 619
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Start point with terrains for noobs (as me hehe)

Post by minimy »

If you have a lot of problems with terrains as me...
This is a start point to try understand how work this madness hehe. :mrgreen:

1) To work you need use DirectX9 subsystem (add 'DirectX9' in compiler options in the field subsystem lib)
2) create folder called 'Data'
3) create folders into 'Data' called 'Textures' and put images:
to use as texture "suelo_tierraA.jpg"
to use as normalmap "suelo_tierraA.jpg". Can use the some texture if you want for both, texture and normalmap.
to use as elevation map "sueloC1.png"
or use your own images.

I hope this can help all Ogre noobs as me. :lol:

Code: Select all

Define.f KeyX, KeyY, MouseX, MouseY, Speed = 1
  
  Procedure   iniDX(title.s="titulin", width=800,height=600, shadowmode= #PB_Shadow_Modulative, shadowres=4096, param=#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
    InitEngine3D()
      InitSprite()
      InitKeyboard()
      InitMouse()
      AntialiasingMode(#PB_AntialiasingMode_x6)
      
      OpenWindow(0, 0, 0, width, height, title, param)
        SetWindowColor(0,$444444)
;         creaGadgets(width,height)
      
      OpenWindowedScreen(WindowID(0), 0, 0, (width * DesktopResolutionX()), (height * DesktopResolutionY()))
        KeyboardMode(#PB_Keyboard_International)
        Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
        Add3DArchive("Data/Model", #PB_3DArchive_FileSystem)
        Add3DArchive( "Data/cyborgGirl", #PB_3DArchive_FileSystem)
        Parse3DScripts()

        Protected.b s= 100
        If shadowmode= #PB_Shadow_TextureAdditive Or shadowmode= #PB_Shadow_TextureModulative
          WorldShadows(shadowmode, -1, RGB(s,s,s), shadowres)
        Else  
          WorldShadows(shadowmode, -1, RGB(s,s,s))
        EndIf
;         KeyboardMode(#PB_Keyboard_International)
  EndProcedure
  Procedure   eventosWindows()
    Repeat
      event= WindowEvent()
      Select event
        Case #PB_Event_Gadget
          EventGadget=  EventGadget()
          EventType=    EventType()
          
        Case #PB_Event_CloseWindow
          sal= 1
      EndSelect
    Until event= 0
  EndProcedure

  iniDX("Terreno F1=Wire, F2=Textures - Cursor move, +Shift fast",960,540)
                
;{
    c= CreateCube(#PB_Any,1)
    m= CreateMaterial(#PB_Any,#Null,$0000ff)
    muro= CreateEntity(#PB_Any,MeshID(c),MaterialID(m) )
    ScaleEntity(muro,1,2,1,#PB_Absolute)
    MoveEntity(muro,0,1,2,#PB_Absolute)
    
    CreateCamera(0, 0, 0, 100, 100)
    MoveCamera(0, 12, 24, 12, #PB_Absolute)
    CameraLookAt(0, 0,0,0)

    CreateLight(0, RGB(255, 255, 255), -40, 100, 80)
    AmbientColor(RGB(80, 80, 80))
;}
    
    terr_ancho= 100 ; width (X and Z) of terrain
    terr_altura= 2  ; height of map in example 'sueloC1.png"
    terr_textura_ancho= 2 ; width (X and Z) of texture and bump map in example "suelo_tierraA.jpg", "suelo_tierraAnormal.jpg"
    
    SetupTerrains(LightID(0), 5000, #PB_Terrain_NormalMapping)
    CreateTerrain(0,65, terr_ancho, terr_altura, 1,"suelo","terreno")
    AddTerrainTexture(0,  0, terr_textura_ancho, "suelo_tierraA.jpg", "suelo_tierraAnormal.jpg")
    DefineTerrainTile(0,0,0, "sueloC1.png", 0,0 )  
    BuildTerrain(0)
  
  
    Repeat
      eventosWindows()
      
      If ExamineMouse()
        MouseX = -MouseDeltaX()/10
        MouseY = -MouseDeltaY()/10
      EndIf
          
      If ExamineKeyboard()
        If KeyboardReleased(#PB_Key_F1)
          CameraRenderMode(0, #PB_Camera_Wireframe)
        EndIf
        If KeyboardReleased(#PB_Key_F2)
          CameraRenderMode(0, #PB_Camera_Textured)
        EndIf
      
        ;{
        If KeyboardPushed(#PB_Key_LeftShift) Or KeyboardPushed(#PB_Key_RightShift)
          If KeyboardPushed(#PB_Key_Up)
            KeyY = -1
          ElseIf KeyboardPushed(#PB_Key_Down)
            KeyY = 1
          Else
            KeyY = 0
          EndIf
          If KeyboardPushed(#PB_Key_Left)
            KeyX = -1
          ElseIf KeyboardPushed(#PB_Key_Right)
            KeyX = 1
          Else
            KeyX = 0
          EndIf
        Else
          If KeyboardPushed(#PB_Key_Up)
            KeyY = -0.1
          ElseIf KeyboardPushed(#PB_Key_Down)
            KeyY = 0.1
          Else
            KeyY = 0
          EndIf
          If KeyboardPushed(#PB_Key_Left)
            KeyX = -0.1
          ElseIf KeyboardPushed(#PB_Key_Right)
            KeyX = 0.1
          Else
            KeyX = 0
          EndIf
        EndIf
        ;}     
      EndIf

      RotateCamera(0, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (0, KeyX, 0, KeyY)
      
      TimeSinceLastFrame = RenderWorld()

      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    

If translation=Error: reply="Sorry, Im Spanish": Endif