Grand Nagus Posted January 7, 2004 Posted January 7, 2004 Oh boy! An active DirectX forum! :D Hello, all. I'm a seriously newbie DirectX coder (using Visual C++ .net), and I'm probably going to ask some ridiculously simple questions every now and then (ya can pick on me, but please don't bash me for not knowing anything). Here's my dilemma: First off, I don't know much of anything about DirectX programming. So far, I can kickstart DirectX in windowed and fullscreen at a set resolution and color mode (oooooh, impressive). I've played around with Microsoft's tutorials to see how to do the basics, and it seemed easy enough. But I've spent a couple of days trying to modify this tutorial to get it to render a 'quad' (square) instead of a 'triangle'. Here's what I've done to it, but it doesn't work: I changed this: // Initialize three vertices for rendering a triangle CUSTOMVERTEX vertices[] = { { 150.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, }, { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, }, }; to this (added an extra vertex, arranged coords to reflect a square instead of a triangle): // Initialize three vertices for rendering a triangle CUSTOMVERTEX vertices[] = { { 50.0f, 50.0f, 0.5f, 1.0f, 0xffff0000, }, // x, y, z, rhw, color { 50.0f, 250.0f, 0.5f, 1.0f, 0xff00ff00, }, { 250.0f, 50.0f, 0.5f, 1.0f, 0xff00ffff, }, { 250.0f, 250.0f, 0.5f, 1.0f, 0xff00ffff, }, }; Then, I changed this: if( FAILED( g_pd3dDevice->CreateVertexBuffer( 3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) to this (increased buffer size to take into account the extra vertex): if( FAILED( g_pd3dDevice->CreateVertexBuffer( 2*3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) Finally, I changed this: g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLELIST, 0, 1 ); to this (make a triangle strip instead of a triangle list, and make two polys): g_pd3dDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 ); That shoulda defined 4 vertices, put 'em into the vertex buffer, and then rendered 'em as a 'triangle strip' instead of a 'triangle list'. But when the program's run, it only shows a blue screen (the initialized DirectX screen's background color). When I look at the code it looks like it should work, so I can't figure out where the problem's at... I'm sure it's something really simple, but what am I doing wrong or omitting that's keeping this code from rendering a quad? :confused: Thanks in advance for the help! Quote
Administrators PlausiblyDamp Posted January 7, 2004 Administrators Posted January 7, 2004 shouldn't if( FAILED( g_pd3dDevice->CreateVertexBuffer( 2*3*sizeof(CUSTOMVERTEX), 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) be if( FAILED( g_pd3dDevice->CreateVertexBuffer( 4*sizeof(CUSTOMVERTEX), // change on this line 0, D3DFVF_CUSTOMVERTEX, D3DPOOL_DEFAULT, &g_pVB, NULL ) ) ) as you are only adding one extra vertex to define a triangle strip. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Grand Nagus Posted January 7, 2004 Author Posted January 7, 2004 Thanks for the response, PlausiblyDamp. I gave your idea a shot and it compiled fine, but I still only get a blue Direct3d screen (no quad). Gads, I wish I could figure this thing out. It's frustratin'! Here's a link to the code (zipped 91k), if you want to d/l it and see why it's doing what it is (or isn't). It's the Vertices tut that Microsoft provides with the DirectX sdk, and it already has my edits in it. Just download it and extract it into its own folder, then startup 'Vertices.vcproj' in VisualC++.net: Quad don't work Thanks again! Quote
Grand Nagus Posted January 7, 2004 Author Posted January 7, 2004 Yippee, I got it to work! It had to do with the order of which I had the vertices... Direct3D is picky, picky, picky. Thanks for the help! Maybe I'll have a slightly more challenging question another time. ;) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.