faire ( texture de fond avec rendu de mesh par dessus)
Code : Tout sélectionner
; Include files 
IncludePath "includes"   :   IncludeFile "n3xtD_PB.pbi"
; Globales
Global	anglex.f, angley.f, flagXDown.w
Global	mox.f, omx.f, moy.l, omy.l
Global *app.l, Quit.l
;----------------------------------------------------------
; open n3xt-D screen
*app = iCreateGraphics3D(800,600)
; << OR >>
;*app = iCreateGraphics3D(800,600, 32, #False, #True, #EDT_DIRECT3D9)
If *app= #Null
  End
EndIf
 
 
  SetCurrentDirectory("media/") 
;-----------------------------------------
; set ambient light
 iAmbientLight( color.l=$ffaaaaaa)
;-----------------------------------------
; create a cube and set position
Global *cube.IMesh = iCreateCube(1.0)
iPositionNode(*cube, 0,0,0) 
; first method to texturing
  *material.IMaterial = iNodeMaterial(*cube)
; load texture
  *tex.ITexture = iLoadTexture( "glass.bmp") 
; set texture in material 
  iTextureMaterial(*material,  0, *tex) 
; create a target texture 
Global *textureTarget.ITexture = iCreateRenderTargetTexture(512, 512)
; load texture for copy inside the TextureRender
Global *bk.ITexture = iLoadTexture("bk.jpg")
; create Skybox
*sky.IMesh = iCreateSkybox( iLoadTexture("up.jpg"),iLoadTexture("dn.jpg"),iLoadTexture("lf.jpg"),iLoadTexture("rt.jpg"),iLoadTexture("ft.jpg"),*textureTarget)
;-----------------------------------------
; create first  camera
Global *cam.ICamera = iCreateCamera()
iPositionNode(*cam, 0,1,-10)
; create second  camera for render target
Global *cam2.ICamera = iCreateCamera()
iPositionNode(*cam2, 0,0,-8)
Procedure RenderSky()
     ; render traget texture with camera 2
     iActiveCamera(*cam2)
     iRenderTarget( *textureTarget , #True,  #True,  $ff222222)    
       iRenderNode(*cam2)
       iDrawImage2D(*bk ,0, 0)
       iRenderNode(*cube)
   iRenderTarget( #Null , #True,  #True,  0)
   iActiveCamera(*cam)
EndProcedure
; ---------------------------------------
;           main loop
; ---------------------------------------
Repeat
  
  iTurnNode(*cube, 0,1,0)
  
 	; move camera with dir key and mouse (left click)
  If iGetKeyDown(#KEY_ARROW_UP)
    iMoveNode(*cam, 0,0,0.5)
  EndIf
  If iGetKeyDown(#KEY_ARROW_DOWN)
    iMoveNode(*cam, 0,0,-0.5)
  EndIf
  If iGetMouseEvent(#MOUSE_BUTTON_LEFT)
  		If flagXDown=0
  			omx = iGetMouseX()
  			omy = iGetMouseY()
  			flagXDown=11
  		Else
  			moy = iGetMouseY()-omy
  			angley=(moy/10.0)
  			omy= iGetMouseY()
  			mox = iGetMouseX()-omx
  			anglex=(mox/10.0)
  			omx= iGetMouseX()
  			iTurnNode(*cam, angley, anglex,0)
  		EndIf
  Else
  	 		flagXDown=0
  EndIf
	; if Escape Key, exit	
  If iGetKeyDown(#KEY_ESCAPE)
    Quit=1
  EndIf
  	; ---------------
  	;      Render
  	; ---------------
  iBeginScene()
    
    RenderSky()
    iDrawScene()
  iEndScene()
Until Quit=1
; end
iFreeEngine()