Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Telastyn

Newbie problems; rendering simple triangle [answered!]

This topic is 5222 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

I have finally gotten the motivation to work on [and continue working on] a nice simple game. 2d, turn based, nothing fancy. I have written up the server side [network setup, class infrastructure, map generation]. Now though I kind of need some sort of GUI [beyond little ASCII maps] to help manage actually visualizing the maps and unit locations the server spits out. Unfortunately windows programming, and directx in particular is a spot where I've little experience. I've done a little in DX7; a little in GDI. I know enough to setup a window and enough to know the cenceptual design of WndProc and the such. I know "book" 3d concepts. So I hit msdn, and started working on walking through the DX9 c++ tutorials [since that's what documentation is available]. Reading through and slowly adapting the tutorial details to my own game to make sure I understand the concepts. I've run across a problem though... [as you could've guessed]. I am working through Tutorial #2 [rendering vertices] and when I move the code into my own app it doesn't display the triangle. Or at least it doesn't display the triangle in an area where I can see it. I have gone through the program in vc++'s debugger and all of the DX calls return success. The created vertex buffer contains the 3 vertices. ->Clear() the screen sets the color properly. DrawPrimitive just doesn't seem to actually render the triangle anywhere I can see, despite it doing the same thing in the boxed tutorial with the same coordinates... On to code. from WinMain:
//snip...
ShowWindow(winobj,cmdshow);
UpdateWindow(winobj);

guiroot=new ro_root;
guiroot->init(winobj);
bzero(winmsg,sizeof(MSG));
while (winmsg->message!=WM_QUIT){
        if (PeekMessage (winmsg,0,0,0,PM_REMOVE)){
                TranslateMessage(winmsg);
                DispatchMessage(winmsg);
        }else{
                guiroot->render();
                guiroot->display();
        }

}
//snip...
    
ro_root is a class for abstracting the rendering so that various methods can be used. I'm leaving out the initialization code, as it's the same as in the tutorial, except it's in ro_root::init rather than InitD3D.
void    ro_root::display(vine *a, vine *b){
//
// Render Object Root -> Display ()
//
// Swap the back buffer to the foreground.
//

d3ddev->Present(0,0,0,0);
}


void    ro_root::render(){
//
// Set the rendering stuff.
//
HRESULT foo;
foo=d3ddev->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,255),1,0);
foo=d3ddev->BeginScene();
rendertree(this->ro);
foo=d3ddev->EndScene();

}
    
rendertree() is a function to call the render() functions of all of the child render objects. In ro_root::init() a child render object is created of the class ro_color_box [excuse the poor coding technique]... and vertices is cut/pasted from the tutorial [and the CUSTOMVERTEX struct renamed ro_d3d_tut_vertex]:
class   ro_color_box{
private:
public:
        ro_color_box(){
                ro=0;
                mt=0;
                kb=0;
                };
        ~ro_color_box(){};

        IDirect3DVertexBuffer9  *vb;

        vine    *ro;
        void    render();
        vine    *parent;
        vine    *mt;
        vine    *kb;

        void    init(ro_d3d_tut_vertex  *vertrect){
                void    *videoverts;
                guiroot->d3ddev->CreateVertexBuffer(3*sizeof(ro_d3d_tut_vertex),0,D3DFVF_XYZRHW|D3DFVF_DIFFUSE,D3DPOOL_DEFAULT
,&vb,0);
                vb->Lock(0,sizeof(vertices),&videoverts,0);
                memcpy(videoverts,vertices,sizeof(vertices));
                vb->Unlock();
        }

};

void    ro_color_box::render(){
//
//
//
HRESULT foo;
//foo=guiroot->d3ddev->SetStreamSource(0,vb,0,sizeof(ro_d3d_tut_vertex));
foo=guiroot->d3ddev->SetFVF(D3DFVF_XYZ|D3DFVF_DIFFUSE);
//foo=guiroot->d3ddev->DrawPrimitive(D3DPT_TRIANGLELIST,0,1);
guiroot->d3ddev->DrawPrimitiveUP(D3DPT_TRIANGLELIST,1,vertices,sizeof(ro_d3d_tut_vertex));
}
    
and it doesn't work either way... I've watched the debugger walk through the child render objects. I've watched the memory get copied over. The code seems to be doing everything it's supposed to. And everything it's doing looks to be exactly what the tutorial code does, only it works, and my code doesn't. Frustration abounds. So what stupid little detail have I missed? [edited by - Telastyn on June 5, 2004 4:50:08 PM] [edited by - Telastyn on June 5, 2004 4:50:29 PM] [edited by - Telastyn on June 5, 2004 5:21:16 PM]

Share this post


Link to post
Share on other sites
Advertisement
Ah hah. Found it.

The problem was:

In ro_color_box::render() the call to SetFVF had the incorrect flag [D3DFVF_XYZ rather than D3DFVF_XYZRHW]

Share this post


Link to post
Share on other sites

  • 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!