Jump to content

  • Log In with Google      Sign In   
  • Create Account


BEGINNER: Issues rendering a textured quad primitive and textured meshes at the same time (DirectX)


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 shadowbreaker   Members   -  Reputation: 102

Like
0Likes
Like

Posted 04 May 2013 - 12:55 PM

Hi,

 

I'm a total newbie to DirectX.  I am programming a simple 3D game as of the moment.  When I was trying to implement a backdrop for my scene, I encountered a problem.  I can't display a textured quad, which serves as my "skybox" and my textured meshes at the same time.

 

The game is like a tail gunner.  The camera is fixed looking at 0,0,1 (x,y,z left-hand coords).  Enemies come toward the player from the positive z axis.  The player just shoots the enemies that come toward him/her.  It's game over when a number of enemies fly past the player.

 

I am almost done with the game.  I am just implementing a skybox.  I am quite aware of another method of creating a skybox for a game from one of my tutorial books, though I did not do it here because I was doing what I thought was a quick fix (by putting a plane facing the camera that is textured to serve as a background, mainly because the camera doesn't move and because I love experimenting).

 

The problem I am having is that I can't run the render code for the enemies (textured mesh) and the backdrop (quad made from primitives and then textured) at the same time.  If I comment out one, I can view the other on screen.  I am just getting a black screen if both are trying to render in one frame step.

 

More than just getting a decent backdrop, I guess I am interested in knowing why I can't render a textured mesh and a textured square made from primitives at the same time. Is it because of the SetFVF() call?  So far, I can't think of any other possible reason.  I tried experimenting with the lighting and z-buffer but I was unsuccessful in solving the mystery.

 

I have included the code I have for the lighting and the rendering of the problematic areas.  I haven't read much material on DirectX and 3D programming in general yet and I think this could be a typical newbie pitfall but I hope you would be patient with me. :)  

 

Thanks a lot in advance! :)

 

 

Here's a snippet of my problematic code:

 

 
#define CUSTOMFVF (D3DFVF_XYZ | D3DFVF_NORMAL | D3DFVF_TEX1)
 

class Enemy
{
.
.
.
void render(void)
{
D3DXMATRIX matRotZ_Propeller, matTranY_Propeller1, matTranY_Propeller2, matTran_All;
 
rotValPropeller += 75.0f;
 
D3DXMatrixRotationZ(&matRotZ_Propeller, D3DXToRadian(rotValPropeller));
D3DXMatrixTranslation(&matTranY_Propeller1, 0.0f, -0.50125f, 0.0f);
D3DXMatrixTranslation(&matTranY_Propeller2, 0.0f, 0.50125f, 0.0f);
D3DXMatrixTranslation(&matTran_All, x, y, z);
 
   for(DWORD i = 0; i < enemyMesh.dwNumMats; i++)   
{
d3ddev->SetMaterial(&enemyMesh.ptrMaterial[i]);   
if(enemyMesh.ptrTexture[i] != NULL)  
d3ddev->SetTexture(0, enemyMesh.ptrTexture[i]);   
 
if(i==5)
d3ddev->SetTransform(D3DTS_WORLD, &(matTranY_Propeller1*matRotZ_Propeller*matTranY_Propeller2*matTran_All));
else
d3ddev->SetTransform(D3DTS_WORLD, &(matTran_All));
 
enemyMesh.D3DXMesh->DrawSubset(i);  
}
}
 
void render_Skybox(void)
{
   // d3ddev->SetRenderState(D3DRS_ZENABLE, FALSE);
 
d3ddev->SetFVF(CUSTOMFVF);
 
D3DXMATRIX matRotateY;
D3DXMatrixRotationY(&matRotateY, D3DXToRadian(180.0f));
d3ddev->SetTransform(D3DTS_WORLD, &matRotateY);
    d3ddev->SetStreamSource(0, skybox.v_buffer, 0, sizeof(CUSTOMVERTEX)); 
    d3ddev->SetIndices(skybox.i_buffer);
d3ddev->SetTexture(0, skybox.skyboxTexture);
 
 
    d3ddev->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4, 0, 2);
}
} //end of class Enemy
 
void render_frame(void)
{
    d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
    d3ddev->Clear(0, NULL, D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
 
    d3ddev->BeginScene();
 
D3DXMATRIX matView;   
    D3DXMatrixLookAtLH(&matView,
  &D3DXVECTOR3 (0.0f, 0.0f, -1.0f),    // the camera position
  &D3DXVECTOR3 (0.0f, 0.0f, 0.0f),    // the look-at position
  &D3DXVECTOR3 (0.0f, 1.0f, 0.0f));    // the up direction
d3ddev->SetTransform(D3DTS_VIEW, &matView);    // set the view transform to matView 
 
    D3DXMATRIX matProjection;    // the projection transform matrix
    D3DXMatrixPerspectiveFovLH(&matProjection,
                               D3DXToRadian(45),    // the horizontal field of view
                               SCREEN_WIDTH / SCREEN_HEIGHT,    // the aspect ratio
                               1.0f,    // the near view-plane
                               2000.0f);    // the far view-plane
    d3ddev->SetTransform(D3DTS_PROJECTION, &matProjection);    // set the projection
 
render_Skybox();
render_Enemies();//render enemies
 
    d3ddev->EndScene(); 
 
 
    d3ddev->Present(NULL, NULL, NULL, NULL);
 
    return;
}
 
void render_Enemies(void)
{
for(int i=0;i<NUM_ENEMIES;i++)
arr_Enemy[i].render();
}
 
// this is the function that sets up the lights and materials
void init_light(void)
{
    D3DLIGHT9 light;    // create the light struct
D3DMATERIAL9 material;    // create the material struct
 
    ZeroMemory(&light, sizeof(light));    // clear out the struct for use
    light.Type = D3DLIGHT_DIRECTIONAL;    // make the light type 'directional light'
    light.Diffuse.r = 0.5f;    // .5 red
    light.Diffuse.g = 0.5f;    // .5 green
    light.Diffuse.b = 0.5f;    // .5 blue
    light.Diffuse.a = 1.0f;    // full alpha (we'll get to that soon)
 
    D3DVECTOR vecDirection = {-1.0f, -0.3f, 1.0f};    // the direction of the light
    light.Direction = vecDirection;    // set the direction
 
    d3ddev->SetLight(0, &light);    // send the light struct properties to light #0
    d3ddev->LightEnable(0, TRUE); 
 
  ZeroMemory(&material, sizeof(D3DMATERIAL9));    // clear out the struct for use
    material.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set diffuse color to white
    material.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);    // set ambient color to white
 
d3ddev->SetMaterial(&material);// turn on light #0
 
    return;
}
 
***by the way, I borrowed the codes from DirectXTutorial.com***
 


Sponsor:

#2 Juliean   GDNet+   -  Reputation: 2364

Like
0Likes
Like

Posted 04 May 2013 - 02:16 PM

Activate the directx debug runtime in DirectX control panel.exe . Its on the "Direct3D 9" tab, simply set "use debug runtime" , slide to "more" debug output, and check maximum validation. Now while running, the IDE should tell you if there is anything obviously broken. Some suspicious output?



#3 Racoonacoon   Members   -  Reputation: 443

Like
1Likes
Like

Posted 04 May 2013 - 03:43 PM

Hiya shadowbreaker,

 

I'm not all that familiar with the fixed-function pipeline of DirectX 9, so I can't offer much assistance on the issue you are having. What I would like to ask though, is why you are beginning your foray into DirectX with DirectX9, and futhermore, why you chose to use the fixed-function pipeline. The fixed-function pipeline is going the way of the dinosaur (one may argue that it is there already) so it likely not the best investment of your time to learn it. Furthermore  there are a great number of differences between DirectX9 and 10/11, so you will have to do a good deal of relearning if you want to move to the newest stuff.

 

Perhaps your goal is to learn the fixed-function pipeline for experience sake and then move on, and if so, then have fun! But you also said you are just beginning, which makes me wonder if you are accidentally starting down a potentially wrong path that will sap you of the time you could be spending learning the better way of doing things.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS