• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
shadowbreaker

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

2 posts in this topic

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***
 
0

Share this post


Link to post
Share on other sites

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?

0

Share this post


Link to post
Share on other sites

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.

1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0