Jump to content
  • Advertisement
Sign in to follow this  
firlefanz

Upgrading from DX8 to DX9 - one problem left

This topic is 4809 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I am using the Omega Headers based on Clooties DX headers. The Omega headers are now being updated to use DX9 (DX8 before). So I am translating my project (space shooter) to DX9. I am nearly finished, I only have one problem left: My skybox is not working anymore! Declaration - Is Skyvertext still correct?
const
      D3DFVF_SKYVERTEX = D3DFVF_POSITION_MASK or D3DFVF_TEX1;
...
  Skybox_Textures: Array[0..0] of IDirect3dTexture9;//0..5 vorher
...
  TD3DSkyVertex=record
     p: TD3DXVector3;
     tu,tv: single
  end;
...
  Skybox_VB: IDirect3DVertexBuffer9;
...
  SkyBox_Vertices: Array[0..23] of TD3DSkyvertex;
  Skybox_Textures: Array[0..0] of IDirect3dTexture9;//0..5 vorher
Init
  for i:=0 to 0 do //to 5 vorher
    if (skybox_textures<> NIL) then skybox_textures:=NIL;
  skybox_vb:=nil;
Methods
procedure TCommandoForm.FillSkymap;
var factor: single;
    i: integer;
    matpos:TD3DXMatrix;
    ptr: pbyte;
    stexname: string;
begin
  factor:=590;     //540
  //Vorne
  skybox_Vertices[0]:= FillskyVertex(D3DXVector3(-factor,-factor, factor),0,1);
  skybox_Vertices[1]:= FillskyVertex(D3DXVector3(-factor, factor, factor),0,0);
  skybox_Vertices[2]:= FillskyVertex(D3DXVector3( factor,-factor, factor),1,1);
  skybox_Vertices[3]:= FillskyVertex(D3DXVector3( factor, factor, factor),1,0);
  //Rechts
  skybox_Vertices[4]:= FillskyVertex(D3DXVector3( factor,-factor, factor),0,1);
  skybox_Vertices[5]:= FillskyVertex(D3DXVector3( factor, factor, factor),0,0);
  skybox_Vertices[6]:= FillskyVertex(D3DXVector3( factor,-factor,-factor),1,1);
  skybox_Vertices[7]:= FillskyVertex(D3DXVector3( factor, factor,-factor),1,0);
  //Hinten
  skybox_Vertices[8]:= FillskyVertex(D3DXVector3( factor,-factor,-factor),0,1);
  skybox_Vertices[9]:= FillskyVertex(D3DXVector3( factor, factor,-factor),0,0);
  skybox_Vertices[10]:=FillskyVertex(D3DXVector3(-factor,-factor,-factor),1,1);
  skybox_Vertices[11]:=FillskyVertex(D3DXVector3(-factor, factor,-factor),1,0);
  //Links
  skybox_Vertices[12]:=FillskyVertex(D3DXVector3(-factor,-factor,-factor),0,1);
  skybox_Vertices[13]:=FillskyVertex(D3DXVector3(-factor, factor,-factor),0,0);
  skybox_Vertices[14]:=FillskyVertex(D3DXVector3(-factor,-factor, factor),1,1);
  skybox_Vertices[15]:=FillskyVertex(D3DXVector3(-factor, factor, factor),1,0);
  //Oben
  skybox_Vertices[16]:=FillskyVertex(D3DXVector3(-factor, factor, factor),0,1);
  skybox_Vertices[17]:=FillskyVertex(D3DXVector3(-factor, factor,-factor),0,0);
  skybox_Vertices[18]:=FillskyVertex(D3DXVector3( factor, factor, factor),1,1);
  skybox_Vertices[19]:=FillskyVertex(D3DXVector3( factor, factor,-factor),1,0);
  //Unten
  skybox_Vertices[20]:=FillskyVertex(D3DXVector3(-factor,-factor,-factor),0,1);
  skybox_Vertices[21]:=FillskyVertex(D3DXVector3(-factor,-factor, factor),0,0);
  skybox_Vertices[22]:=FillskyVertex(D3DXVector3( factor,-factor,-factor),1,1);
  skybox_Vertices[23]:=FillskyVertex(D3DXVector3( factor,-factor, factor),1,0);
  //Vertex erstellen + Texturen laden
  skybox_VB:=nil;
  if failed(xenScreen.device.CreateVertexBuffer(sizeof(Skybox_Vertices),D3DUsage_Writeonly,D3DFVF_Skyvertex,
            D3dPool_Default,SkyBox_VB,nil)) then exit;
  if failed(Skybox_vb.Lock(0,23*sizeof(Skybox_Vertices[0]),pointer(ptr),0)) then exit;
  move(Skybox_vertices,ptr^,sizeof(Skybox_Vertices));
  skybox_vb.Unlock;
  for i:=0 to 0 do begin //to 5 vorher
    if boollowres then stexname:='spacebacksmall.jpg' else stexname:='spaceback.jpg';
    if d3dxcreatetexturefromfilea(xenScreen.device,PChar(stexname),skybox_textures)<>s_ok
    then exception(stexname);
  end;
end;

procedure TCommandoForm.Draw_Skymap;
var i: integer;
    matpos: td3dmatrix;
begin
  xenscreen.Device.setrenderstate(d3drs_fogenable,0);
  //texturen schneiden
//dx8  xenscreen.device.SetTextureStageState(0, D3DTSS_ADDRESSU,D3DTADDRESS_CLAMP);
//xenscreen.device.SetSamplerState(0, D3DSAMP_ADDRESSU,D3DTADDRESS_CLAMP);
//xenscreen.device.SetSamplerState(0, D3DSAMP_ADDRESSV,D3DTADDRESS_CLAMP);
//dx8  xenscreen.device.SetTextureStageState(0, D3DTSS_ADDRESSV,D3DTADDRESS_CLAMP);
  //z buffer aus
  xenscreen.device.setrenderstate(d3drs_zenable,dword(false));
  xenscreen.device.setrenderstate(d3drs_zwriteenable,dword(false));
  //beleuchtung aus
  xenscreen.device.setrenderstate(d3drs_lighting,dword(false));
  xenscreen.Device.LightEnable(0, false);
  //skybox mit kamera bewegen
  d3dxmatrixtranslation(matpos,0,0,0);//hier ggf kamera koordianeten einsetzen
  xenscreen.device.settransform(d3dts_world,matpos);
  //skybox rendern
  xenscreen.device.SetFVF(d3dfvf_skyvertex);
  xenscreen.device.SetStreamSource(0,skybox_vb,sizeof(td3dskyvertex),sizeof(td3dskyvertex));
  for i:=0 to 5 do begin
    xenscreen.device.SetTexture(0,skybox_textures[0]);//i vorher
    xenscreen.device.DrawPrimitive(d3dpt_trianglestrip,i*4,2);
  end;
  //werte texturaddressierung rücksetzen
//dx8  xenscreen.device.SetTextureStageState(0, D3DTSS_ADDRESSU,D3DTADDRESS_wrap);
//dx8  xenscreen.device.SetTextureStageState(0, D3DTSS_ADDRESSV,D3DTADDRESS_wrap);
//xenscreen.device.SetSamplerState(0, D3DSAMP_ADDRESSU,D3DTADDRESS_wrap);
//xenscreen.device.SetSamplerState(0, D3DSAMP_ADDRESSV,D3DTADDRESS_wrap);
  //schalten zbuffer ein
  xenscreen.device.setrenderstate(d3drs_zenable,dword(true));
  xenscreen.device.setrenderstate(d3drs_zwriteenable,dword(true));
  //schalten licht ein
  xenscreen.device.setrenderstate(d3drs_lighting,dword(true));
  xenscreen.Device.LightEnable(0, true);
end;

function TCommandoForm.FillSkyVertex(p: TD3DXVector3; tu,tv: single): TD3dSkyvertex;
begin
  result.p:=p;
  result.tu:=tu;
  result.tv:=tv;
end;
FillSkyMap being called on time in form create, draw_Skymap in each frame. It worked perfect for DX8, no it is not working anymore. Fillskymap seems to work, no Exit or something. If I clear my screen with red, it stays red, so there is no skybox rendered. I am right now using 1 texture instead of 6 to save memory, but it was okay before the translation to dx9. I also inserted xenscreen.device.setTextureStageState(0, D3DTSS_COLOROP, D3DTOP_selectarg1); xenscreen.device.setTextureStageState(0, D3DTSS_COLOROP, D3DTSA_texture); xenscreen.device.setTextureStageState(1, D3DTSS_COLOROP, D3DTOP_disable); before drawprimitive, the same problem. Perhaps something is wrong with SetStreamsource or the vertext? Any ideas please? Thanks! Firle

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!